From 70305a7ee6bd3924c1162e97be846657a89eb344 Mon Sep 17 00:00:00 2001 From: "Sam A. Horvath-Hunt" Date: Sat, 16 Dec 2023 15:50:10 +0000 Subject: [PATCH 1/6] Add restore keys to CI caches --- .github/workflows/check.yml | 6 ++++++ .github/workflows/publish.yml | 2 ++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ac1b3cc..a3e30d1 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -26,6 +26,8 @@ jobs: with: path: ~/.cabal/store key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} + restore-keys: | + cabal-${{ runner.os }} - run: nix develop -c cabal build test: name: Test @@ -39,6 +41,8 @@ jobs: with: path: ~/.cabal/store key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} + restore-keys: | + cabal-${{ runner.os }} - run: nix develop -c cabal test lint: name: Lint @@ -71,5 +75,7 @@ jobs: with: path: ~/.cache/yarn/v6 key: yarn-${{ runner.os }}-${{ hashFiles('.golden/ts/yarn.lock') }} + restore-keys: | + yarn-${{ runner.os }} - run: nix develop -c yarn install --frozen-lockfile - run: nix develop -c yarn typecheck diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 665f36b..12227fa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -29,6 +29,8 @@ jobs: with: path: ~/.cabal/store key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} + restore-keys: | + cabal-${{ runner.os }} - name: Build run: | # Unlike `cabal build`, `cabal install` appears to build in a From 4dcf2218246fe985c1f4956d4c796064facdc15a Mon Sep 17 00:00:00 2001 From: "Sam A. Horvath-Hunt" Date: Sat, 16 Dec 2023 15:57:46 +0000 Subject: [PATCH 2/6] Extract Cabal cache composite action --- .github/actions/cabal-cache/action.yml | 11 +++++++++++ .github/workflows/check.yml | 14 ++------------ .github/workflows/publish.yml | 7 +------ 3 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 .github/actions/cabal-cache/action.yml diff --git a/.github/actions/cabal-cache/action.yml b/.github/actions/cabal-cache/action.yml new file mode 100644 index 0000000..7a93129 --- /dev/null +++ b/.github/actions/cabal-cache/action.yml @@ -0,0 +1,11 @@ +name: Cabal dependency cache +runs: + using: composite + steps: + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ~/.cabal/store + key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} + restore-keys: | + cabal-${{ runner.os }} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a3e30d1..a4cd387 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -22,12 +22,7 @@ jobs: - uses: cachix/install-nix-action@v22 - run: nix develop -c cabal update - run: nix develop -c cabal freeze - - uses: actions/cache@v3 - with: - path: ~/.cabal/store - key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} - restore-keys: | - cabal-${{ runner.os }} + - uses: ./.github/actions/cabal-cache - run: nix develop -c cabal build test: name: Test @@ -37,12 +32,7 @@ jobs: - uses: cachix/install-nix-action@v22 - run: nix develop -c cabal update - run: nix develop -c cabal freeze - - uses: actions/cache@v3 - with: - path: ~/.cabal/store - key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} - restore-keys: | - cabal-${{ runner.os }} + - uses: ./.github/actions/cabal-cache - run: nix develop -c cabal test lint: name: Lint diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 12227fa..8e982a6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,12 +25,7 @@ jobs: with: ghc-version: 9.4.6 - run: cabal freeze - - uses: actions/cache@v3 - with: - path: ~/.cabal/store - key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} - restore-keys: | - cabal-${{ runner.os }} + - uses: ./.github/actions/cabal-cache - name: Build run: | # Unlike `cabal build`, `cabal install` appears to build in a From 911ee732e72a213036124ddf877a7aa7c6b9a5f1 Mon Sep 17 00:00:00 2001 From: "Sam A. Horvath-Hunt" Date: Sat, 16 Dec 2023 15:59:36 +0000 Subject: [PATCH 3/6] Add incremental build CI caching This should work as of GHC 9.4. This is largely based upon: https://harry.garrood.me/blog/easy-incremental-haskell-ci-builds-with-ghc-9.4/ I've omitted the GHC version for simplicity. --- .github/actions/cabal-cache/action.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/actions/cabal-cache/action.yml b/.github/actions/cabal-cache/action.yml index 7a93129..acafea7 100644 --- a/.github/actions/cabal-cache/action.yml +++ b/.github/actions/cabal-cache/action.yml @@ -1,4 +1,4 @@ -name: Cabal dependency cache +name: Cabal dependency and incremental build caches runs: using: composite steps: @@ -9,3 +9,10 @@ runs: key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} restore-keys: | cabal-${{ runner.os }} + - name: Cache incremental build + uses: actions/cache@v3 + with: + path: ./dist-newstyle/ + key: dist-${{ runner.os }}-${{ github.sha }} + restore-keys: | + dist-${{ runner.os }} From 168ea1e4597e5ff5ae664ecd15477486af8c95e0 Mon Sep 17 00:00:00 2001 From: "Sam A. Horvath-Hunt" Date: Sat, 16 Dec 2023 16:07:45 +0000 Subject: [PATCH 4/6] Force rebuild For CI testing. From 0e3e28f89831062ae5fd133ff3f4f8747c74daac Mon Sep 17 00:00:00 2001 From: "Sam A. Horvath-Hunt" Date: Sat, 16 Dec 2023 16:20:52 +0000 Subject: [PATCH 5/6] Fix Cabal store location in CI cache Newer versions of Cabal no longer use ~/.cabal/ unless it's already present (XDG). --- .github/actions/cabal-cache/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/cabal-cache/action.yml b/.github/actions/cabal-cache/action.yml index acafea7..207e049 100644 --- a/.github/actions/cabal-cache/action.yml +++ b/.github/actions/cabal-cache/action.yml @@ -5,7 +5,7 @@ runs: - name: Cache dependencies uses: actions/cache@v3 with: - path: ~/.cabal/store + path: ~/.local/state/cabal/store/ key: cabal-${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }} restore-keys: | cabal-${{ runner.os }} From d4d8fb963066fa4a73cae938998ec3b5c31d23ce Mon Sep 17 00:00:00 2001 From: "Sam A. Horvath-Hunt" Date: Sat, 16 Dec 2023 16:27:34 +0000 Subject: [PATCH 6/6] Split golden typecheck deps into their own dev shell --- .github/workflows/check.yml | 4 ++-- flake.nix | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a4cd387..ba4d662 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -67,5 +67,5 @@ jobs: key: yarn-${{ runner.os }}-${{ hashFiles('.golden/ts/yarn.lock') }} restore-keys: | yarn-${{ runner.os }} - - run: nix develop -c yarn install --frozen-lockfile - - run: nix develop -c yarn typecheck + - run: nix develop .#golden -c yarn install --frozen-lockfile + - run: nix develop .#golden -c yarn typecheck diff --git a/flake.nix b/flake.nix index 584000d..0cfd55f 100644 --- a/flake.nix +++ b/flake.nix @@ -15,19 +15,24 @@ haskPkgs = pkgs.haskell.packages."${ghcVer}"; in { - devShells.default = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ - cabal-install - haskell.compiler."${ghcVer}" - haskPkgs.haskell-language-server - hlint - haskPkgs.hspec-golden - stylish-haskell + devShells = { + default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + cabal-install + haskell.compiler."${ghcVer}" + haskPkgs.haskell-language-server + hlint + haskPkgs.hspec-golden + stylish-haskell + ]; + }; - # For typechecking golden output - nodejs - yarn - ]; + golden = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + nodejs + yarn + ]; + }; }; }); }