Skip to content

Commit 73957c4

Browse files
committed
Reuse cache GHA from cardano-api repository
1 parent fc43f72 commit 73957c4

File tree

1 file changed

+19
-56
lines changed

1 file changed

+19
-56
lines changed

.github/workflows/haskell.yml

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
ghc: ["9.6", "9.10", "9.12"]
24-
cabal: ["3.14"]
23+
ghc: [&ghc-stable "9.6", "9.10", &ghc-latest "9.12"]
24+
cabal: [&cabal-version "3.16"]
2525
sys:
26-
- { os: windows-latest, shell: 'C:/msys64/usr/bin/bash.exe -e {0}' }
2726
- { os: ubuntu-latest, shell: bash }
27+
include:
28+
# Using include, to make sure there will only be one macOS job, even if the matrix gets expanded later on.
29+
# We want a single job, because macOS runners are scarce.
30+
- ghc: *ghc-stable
31+
cabal: *cabal-version
32+
sys:
33+
os: macos-latest
34+
shell: bash
35+
- ghc: *ghc-latest
36+
cabal: *cabal-version
37+
sys:
38+
os: windows-latest
39+
shell: 'C:/msys64/usr/bin/bash.exe -e {0}'
2840

2941
defaults:
3042
run:
@@ -74,60 +86,11 @@ jobs:
7486

7587
- uses: actions/checkout@v4
7688

77-
- name: Cabal update
78-
run: cabal update
79-
80-
# A dry run `build all` operation does *NOT* download anything, it just looks at the package
81-
# indices to generate an install plan.
82-
- name: Build dry run
83-
run: cabal build all --enable-tests --dry-run --minimize-conflict-set
84-
85-
# From the install plan we generate a dependency list.
86-
- name: Record dependencies
87-
id: record-deps
88-
run: |
89-
cat dist-newstyle/cache/plan.json | jq -r '."install-plan"[] | select(.style != "local") | .id' | sort | uniq > dependencies.txt
90-
91-
# Use a fresh cache each month
92-
- name: Store month number and GHC version as environment variables used in cache version
93-
run: |
94-
cat <<EOF >> $GITHUB_ENV
95-
MONTHNUM=$(date -u '+%m')
96-
GHC=$(ghc --numeric-version)
97-
EOF
98-
99-
# From the dependency list we restore the cached dependencies.
100-
# We use the hash of `dependencies.txt` as part of the cache key because that will be stable
101-
# until the `index-state` values in the `cabal.project` file changes.
102-
- name: Restore cached dependencies
103-
uses: actions/cache/restore@v4
104-
id: cache
105-
with:
106-
path: |
107-
${{ steps.setup-haskell.outputs.cabal-store }}
108-
dist-newstyle
109-
key:
110-
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ env.GHC }}-${{ env.MONTHNUM }}-${{ hashFiles('dependencies.txt') }}
111-
# try to restore previous cache from this month if there's no cache for the dependencies set
112-
restore-keys: |
113-
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ env.GHC }}-${{ env.MONTHNUM }}-
114-
115-
# Now we install the dependencies. If the cache was found and restored in the previous step,
116-
# this should be a no-op, but if the cache key was not found we need to build stuff so we can
117-
# cache it for the next step.
118-
- name: Install dependencies
119-
run: cabal build all --enable-tests --only-dependencies
120-
121-
# Always store the cabal cache.
122-
# This can fail (benign failure) if there is already a hash at that key.
123-
- name: Cache Cabal store
124-
uses: actions/cache/save@v4
89+
- name: Cache and install Cabal dependencies
90+
uses: intersectmbo/cardano-api/.github/actions/cabal-cache@master
12591
with:
126-
path: |
127-
${{ steps.setup-haskell.outputs.cabal-store }}
128-
dist-newstyle
129-
key:
130-
${{ steps.cache.outputs.cache-primary-key }}
92+
cabal-store: ${{ steps.setup-haskell.outputs.cabal-store }}
93+
cache-version: ${{ env.CABAL_CACHE_VERSION }}
13194

13295
# Now we build.
13396
- name: Build all

0 commit comments

Comments
 (0)