From 22db363943c36bc3e131d1ebcffc785351f9ab63 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 15:30:32 +0000 Subject: [PATCH 01/10] build: move from deprecated gh action, invalidate cache --- .github/workflows/cabal.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml index 247a8a5..e53f9f3 100644 --- a/.github/workflows/cabal.yml +++ b/.github/workflows/cabal.yml @@ -14,11 +14,11 @@ jobs: matrix: ghc: ["8.6", "8.8", "8.10", "9.0", "9.2", "9.4"] cabal: ["3.6"] - cache-version: ["2022-10-25"] + cache-version: ["2025-01-01"] steps: - uses: actions/checkout@v2 - - uses: haskell/actions/setup@v2 + - uses: haskell-actions/setup@v2 with: ghc-version: ${{ matrix.ghc }} cabal-version: ${{ matrix.cabal }} From 5482df3845635c805ec02fa1ca26b8a1bb9e2b57 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 15:38:59 +0000 Subject: [PATCH 02/10] build: move to newer, more performant cabal --- .github/workflows/cabal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml index e53f9f3..1121d8a 100644 --- a/.github/workflows/cabal.yml +++ b/.github/workflows/cabal.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: ghc: ["8.6", "8.8", "8.10", "9.0", "9.2", "9.4"] - cabal: ["3.6"] + cabal: ["3.12"] cache-version: ["2025-01-01"] steps: From 6cb0307c72f70cbe22d939fb569f53effa49fb39 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 15:41:52 +0000 Subject: [PATCH 03/10] build: run gh-actions on ghc 9.12 --- .github/workflows/cabal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml index 1121d8a..38e548f 100644 --- a/.github/workflows/cabal.yml +++ b/.github/workflows/cabal.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - ghc: ["8.6", "8.8", "8.10", "9.0", "9.2", "9.4"] + ghc: ["8.6", "8.8", "8.10", "9.0", "9.2", "9.4", "9.12"] cabal: ["3.12"] cache-version: ["2025-01-01"] From 7819122a8f45e306790f8fa85891c2bd2aabd84c Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 15:58:28 +0000 Subject: [PATCH 04/10] build: add support for newer dependencies when testing --- haskell-stack-trace-plugin.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haskell-stack-trace-plugin.cabal b/haskell-stack-trace-plugin.cabal index 0e0e121..e80aa43 100644 --- a/haskell-stack-trace-plugin.cabal +++ b/haskell-stack-trace-plugin.cabal @@ -55,8 +55,8 @@ test-suite test hs-source-dirs: test type: exitcode-stdio-1.0 build-depends: - , bytestring >=0.10 && <0.12 - , hspec ^>=2.8 + , bytestring >=0.10 + , hspec ^>=2.8 || ^>=2.11 , typed-process ^>=0.2 build-tool-depends: hspec-discover:hspec-discover ^>=2.8 From 7cc8807ce7990ffd88b7f05a10721952ded48c46 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 17:46:01 +0000 Subject: [PATCH 05/10] fix: tests on ghc >= 9.4 --- haskell-stack-trace-plugin.cabal | 2 ++ test/StackTrace/PluginSpec.hs | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/haskell-stack-trace-plugin.cabal b/haskell-stack-trace-plugin.cabal index e80aa43..477e734 100644 --- a/haskell-stack-trace-plugin.cabal +++ b/haskell-stack-trace-plugin.cabal @@ -57,6 +57,8 @@ test-suite test build-depends: , bytestring >=0.10 , hspec ^>=2.8 || ^>=2.11 + , raw-strings-qq ^>=1.1 + , regex-tdfa ^>=1.3 , typed-process ^>=0.2 build-tool-depends: hspec-discover:hspec-discover ^>=2.8 diff --git a/test/StackTrace/PluginSpec.hs b/test/StackTrace/PluginSpec.hs index 2cc6417..7571a79 100644 --- a/test/StackTrace/PluginSpec.hs +++ b/test/StackTrace/PluginSpec.hs @@ -1,17 +1,35 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + module StackTrace.PluginSpec (spec) where import Data.ByteString.Lazy (ByteString) -import qualified Data.ByteString.Lazy as BL -import Test.Hspec +import qualified Data.ByteString.Lazy.Char8 as BS import System.Process.Typed +import Test.Hspec +import Text.RawString.QQ +import Text.Regex.TDFA ((=~)) + +-- | Extracts the function names of all functions that appear in a stack trace +extractStackTraceFunctions :: String -> [String] +extractStackTraceFunctions input = map extractFunctionName matches + where + regex = [r|[ ]*([A-Za-z0-9]+), called at example/Main.hs:[0-9]+:[0-9]+ in [^:]+:Main|] :: String + matches = (input =~ regex) :: [[String]] + extractFunctionName :: [String] -> String + extractFunctionName (_ : name : _) = name + extractFunctionName _ = error "Regex match failed" spec :: Spec spec = do output <- runIO exe - expected <- runIO $ BL.readFile "test/resource/ghc.output" - it "integration test" $ output `shouldBe` expected + let outputStr = BS.unpack output + let extractedFunctions = extractStackTraceFunctions outputStr + + -- each of these exceptions should appear in the stack trace + let expectedFunctions = ["error", "fError", "f10", "f9", "f8", "f7", "f6", "f5", "f4", "f3", "f2", "f1", "main"] :: [String] + it "integration test" $ extractedFunctions `shouldBe` expectedFunctions exe :: IO ByteString exe = do From ababc39a54ba972eaa24043f992978cebf577044 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 18:04:05 +0000 Subject: [PATCH 06/10] build: remove support for ghc ^>= 9.0 and 9.2 --- haskell-stack-trace-plugin.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haskell-stack-trace-plugin.cabal b/haskell-stack-trace-plugin.cabal index 477e734..594902d 100644 --- a/haskell-stack-trace-plugin.cabal +++ b/haskell-stack-trace-plugin.cabal @@ -20,7 +20,7 @@ extra-source-files: CHANGELOG.md Readme.md -tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.4 || ==9.4.8 || ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.1 +tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.4.8 || ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.1 source-repository head type: git @@ -38,7 +38,7 @@ common common-opts library import: common-opts hs-source-dirs: src - build-depends: ghc ^>=8.6 || ^>=8.8 || ^>=8.10 || ^>=9.0 || ^>=9.2 || ^>=9.4 || ^>=9.6 || ^>=9.8 || ^>=9.10 || ^>=9.12 + build-depends: ghc ^>=8.6 || ^>=8.8 || ^>=8.10 || ^>=9.4 || ^>=9.6 || ^>=9.8 || ^>=9.10 || ^>=9.12 exposed-modules: StackTrace.Plugin if flag(dev) From 62553f5973be6d3d7d2bb77c60d7dadf36cd6ea0 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 18:09:31 +0000 Subject: [PATCH 07/10] build: no longer test on unsupported ghc 9.0 and 9.2 --- .github/workflows/cabal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml index 38e548f..34f05f7 100644 --- a/.github/workflows/cabal.yml +++ b/.github/workflows/cabal.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - ghc: ["8.6", "8.8", "8.10", "9.0", "9.2", "9.4", "9.12"] + ghc: ["8.6", "8.8", "8.10", "9.4", "9.6", "9.8", "9.12"] cabal: ["3.12"] cache-version: ["2025-01-01"] From 88e1a6521a351e23d237fa758eb0ea3cb02816e7 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Wed, 1 Jan 2025 18:25:06 +0000 Subject: [PATCH 08/10] build: use recommended caching system --- .github/workflows/cabal.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml index 34f05f7..b5ea816 100644 --- a/.github/workflows/cabal.yml +++ b/.github/workflows/cabal.yml @@ -23,20 +23,34 @@ jobs: ghc-version: ${{ matrix.ghc }} cabal-version: ${{ matrix.cabal }} - - name: Cache ~/.cabal/store - uses: actions/cache@v3 + - name: Restore cached dependencies + uses: actions/cache/restore@v4 + id: cache + env: + key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }} with: - path: | - ~/.cabal/store - dist-newstyle - key: ${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.cache-version }}-cabal + path: ${{ steps.setup.outputs.cabal-store }} + key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }} + restore-keys: ${{ env.key }}- - name: Install dependencies + # If we had an exact cache hit, the dependencies will be up to date. + if: steps.cache.outputs.cache-hit != 'true' run: | cabal update cabal configure --disable-optimization --enable-tests --write-ghc-environment-files=always -j2 cabal build --only-dependencies + + # Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail. + - name: Save cached dependencies + uses: actions/cache/save@v4 + # If we had an exact cache hit, trying to save the cache would error because of key clash. + if: steps.cache.outputs.cache-hit != 'true' + with: + path: ${{ steps.setup.outputs.cabal-store }} + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Build & Test run: | cabal build --flag dev From bf6c855f3b8260d473f0300eec333c76ed738a8a Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Thu, 2 Jan 2025 06:11:19 +0000 Subject: [PATCH 09/10] build: use alternative caching mechanism --- .github/workflows/cabal.yml | 86 ++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml index b5ea816..395d6dd 100644 --- a/.github/workflows/cabal.yml +++ b/.github/workflows/cabal.yml @@ -1,57 +1,53 @@ name: cabal - on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ '*' ] - + branches: ['*'] jobs: build: runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: - ghc: ["8.6", "8.8", "8.10", "9.4", "9.6", "9.8", "9.12"] - cabal: ["3.12"] + ghc-version: ["8.6", "8.8", "8.10", "9.4", "9.6", "9.8", "9.12"] + cabal-version: ["3.12"] cache-version: ["2025-01-01"] - steps: - - uses: actions/checkout@v2 - - uses: haskell-actions/setup@v2 - with: - ghc-version: ${{ matrix.ghc }} - cabal-version: ${{ matrix.cabal }} - - - name: Restore cached dependencies - uses: actions/cache/restore@v4 - id: cache - env: - key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }} - with: - path: ${{ steps.setup.outputs.cabal-store }} - key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }} - restore-keys: ${{ env.key }}- - - - name: Install dependencies - # If we had an exact cache hit, the dependencies will be up to date. - if: steps.cache.outputs.cache-hit != 'true' - run: | - cabal update - cabal configure --disable-optimization --enable-tests --write-ghc-environment-files=always -j2 - cabal build --only-dependencies - - - # Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail. - - name: Save cached dependencies - uses: actions/cache/save@v4 - # If we had an exact cache hit, trying to save the cache would error because of key clash. - if: steps.cache.outputs.cache-hit != 'true' - with: - path: ${{ steps.setup.outputs.cabal-store }} - key: ${{ steps.cache.outputs.cache-primary-key }} - - - name: Build & Test - run: | - cabal build --flag dev - cabal test --flag dev + - uses: actions/checkout@v4 + - name: Set up GHC ${{ matrix.ghc-version }} + uses: haskell-actions/setup@v2 + id: setup + with: + ghc-version: ${{ matrix.ghc-version }} + cabal-version: ${{ matrix.cabal-version }} + cabal-update: true + - name: Configure the build + run: | + cabal configure --enable-tests --disable-documentation --disable-optimization --write-ghc-environment-files=always -j2 + cabal build all --dry-run + - name: Restore cached dependencies + uses: actions/cache/restore@v4 + id: cache + env: + key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}-${{ matrix.cache-version }} + with: + path: ${{ steps.setup.outputs.cabal-store }} + key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }} + restore-keys: ${{ env.key }}- + - name: Install dependencies + # If we had an exact cache hit, the dependencies will be up to date. + if: steps.cache.outputs.cache-hit != 'true' + run: cabal build all --only-dependencies + # Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail. + - name: Save cached dependencies + uses: actions/cache/save@v4 + # If we had an exact cache hit, trying to save the cache would error because of key clash. + if: steps.cache.outputs.cache-hit != 'true' + with: + path: ${{ steps.setup.outputs.cabal-store }} + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Build + run: cabal build all --flag dev + - name: Run tests + run: cabal test all --flag dev From f5e0b5880e269ef5338c6efffb4ec8d7a85df230 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Thu, 2 Jan 2025 06:20:01 +0000 Subject: [PATCH 10/10] chore: remove unused test comparison --- test/resource/ghc.output | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 test/resource/ghc.output diff --git a/test/resource/ghc.output b/test/resource/ghc.output deleted file mode 100644 index c3953a0..0000000 --- a/test/resource/ghc.output +++ /dev/null @@ -1,15 +0,0 @@ -example: fError -CallStack (from HasCallStack): - error, called at example/Main.hs:47:10 in main:Main - fError, called at example/Main.hs:43:11 in main:Main - f10, called at example/Main.hs:40:6 in main:Main - f9, called at example/Main.hs:37:11 in main:Main - f8, called at example/Main.hs:33:16 in main:Main - f7, called at example/Main.hs:29:11 in main:Main - f6, called at example/Main.hs:25:15 in main:Main - f5, called at example/Main.hs:21:8 in main:Main - f4, called at example/Main.hs:17:6 in main:Main - f3, called at example/Main.hs:13:6 in main:Main - f2, called at example/Main.hs:10:6 in main:Main - f1, called at example/Main.hs:7:14 in main:Main - main, called at example/Main.hs:7:1 in main:Main