Skip to content

Commit ae182ef

Browse files
committed
Make GHA cache restore any cache from current month if dependencies do not match.
1 parent 03de67a commit ae182ef

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

.github/workflows/haskell.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
99
branches:
1010
- main
11+
# GH caches are removed when not accessed within 7 days - this schedule runs the job every 6 days making
12+
# sure that we always have some caches on main
13+
schedule:
14+
- cron: '0 0 */6 * *'
1115

1216
jobs:
1317
build:
@@ -69,7 +73,7 @@ jobs:
6973
with:
7074
use-sodium-vrf: true # default is true
7175

72-
- uses: actions/checkout@v3
76+
- uses: actions/checkout@v4
7377

7478
- name: Cabal update
7579
run: cabal update
@@ -85,6 +89,10 @@ jobs:
8589
run: |
8690
cat dist-newstyle/cache/plan.json | jq -r '."install-plan"[] | select(.style != "local") | .id' | sort | uniq > dependencies.txt
8791
92+
# Use a fresh cache each month
93+
- name: Store month number as environment variable used in cache version
94+
run: echo "MONTHNUM=$(/usr/bin/date -u '+%m')" >> $GITHUB_ENV
95+
8896
# From the dependency list we restore the cached dependencies.
8997
# We use the hash of `dependencies.txt` as part of the cache key because that will be stable
9098
# until the `index-state` values in the `cabal.project` file changes.
@@ -95,7 +103,11 @@ jobs:
95103
path: |
96104
${{ steps.setup-haskell.outputs.cabal-store }}
97105
dist-newstyle
98-
key: cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}
106+
key:
107+
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.MONTHNUM }}-${{ hashFiles('dependencies.txt') }}
108+
# try to restore previous cache from this month if there's no cache for the dependencies set
109+
restore-keys: |
110+
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.MONTHNUM }}-
99111
100112
# Now we install the dependencies. If the cache was found and restored in the previous step,
101113
# this should be a no-op, but if the cache key was not found we need to build stuff so we can
@@ -110,7 +122,8 @@ jobs:
110122
path: |
111123
${{ steps.setup-haskell.outputs.cabal-store }}
112124
dist-newstyle
113-
key: cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}
125+
key:
126+
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.MONTHNUM }}-${{ hashFiles('dependencies.txt') }}
114127

115128
# Now we build.
116129
- name: Build all
@@ -140,7 +153,7 @@ jobs:
140153
done
141154
142155
- name: Save Artifact
143-
uses: actions/upload-artifact@v3
156+
uses: actions/upload-artifact@v4
144157
with:
145158
name: artifacts-${{ matrix.sys.os }}-${{ matrix.ghc }}
146159
path: ./artifacts
@@ -183,7 +196,7 @@ jobs:
183196
runs-on: ubuntu-latest
184197
steps:
185198
- name: Checkout code
186-
uses: actions/checkout@v3
199+
uses: actions/checkout@v4
187200

188201
- name: Create Release Tag
189202
id: create_release_tag

0 commit comments

Comments
 (0)