Skip to content

Commit

Permalink
Merge pull request #510 from IntersectMBO/mgalazyn/chore/improve-gha-…
Browse files Browse the repository at this point in the history
…caching

Make GHA cache restore any cache from current month if dependencies do not match
  • Loading branch information
carbolymer committed Apr 10, 2024
2 parents 03de67a + ae182ef commit 52d9a38
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
branches:
- main
# GH caches are removed when not accessed within 7 days - this schedule runs the job every 6 days making
# sure that we always have some caches on main
schedule:
- cron: '0 0 */6 * *'

jobs:
build:
Expand Down Expand Up @@ -69,7 +73,7 @@ jobs:
with:
use-sodium-vrf: true # default is true

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Cabal update
run: cabal update
Expand All @@ -85,6 +89,10 @@ jobs:
run: |
cat dist-newstyle/cache/plan.json | jq -r '."install-plan"[] | select(.style != "local") | .id' | sort | uniq > dependencies.txt
# Use a fresh cache each month
- name: Store month number as environment variable used in cache version
run: echo "MONTHNUM=$(/usr/bin/date -u '+%m')" >> $GITHUB_ENV

# From the dependency list we restore the cached dependencies.
# We use the hash of `dependencies.txt` as part of the cache key because that will be stable
# until the `index-state` values in the `cabal.project` file changes.
Expand All @@ -95,7 +103,11 @@ jobs:
path: |
${{ steps.setup-haskell.outputs.cabal-store }}
dist-newstyle
key: cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}
key:
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.MONTHNUM }}-${{ hashFiles('dependencies.txt') }}
# try to restore previous cache from this month if there's no cache for the dependencies set
restore-keys: |
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.MONTHNUM }}-
# Now we install the dependencies. If the cache was found and restored in the previous step,
# this should be a no-op, but if the cache key was not found we need to build stuff so we can
Expand All @@ -110,7 +122,8 @@ jobs:
path: |
${{ steps.setup-haskell.outputs.cabal-store }}
dist-newstyle
key: cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}
key:
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.MONTHNUM }}-${{ hashFiles('dependencies.txt') }}

# Now we build.
- name: Build all
Expand Down Expand Up @@ -140,7 +153,7 @@ jobs:
done
- name: Save Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.sys.os }}-${{ matrix.ghc }}
path: ./artifacts
Expand Down Expand Up @@ -183,7 +196,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Create Release Tag
id: create_release_tag
Expand Down

0 comments on commit 52d9a38

Please sign in to comment.