Skip to content

Commit

Permalink
Merge pull request #718 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. Clean-up windows jobs.
  • Loading branch information
carbolymer authored Apr 16, 2024
2 parents ad12f22 + 161e0a6 commit 492b85e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 39 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/cabal.project.local.ci.Darwin

This file was deleted.

5 changes: 0 additions & 5 deletions .github/workflows/cabal.project.local.ci.Linux

This file was deleted.

This file was deleted.

47 changes: 30 additions & 17 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@ 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:
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.sys.os }}

strategy:
fail-fast: false
matrix:
# If you edit these versions, make sure the version in the lonely macos-latest job below is updated accordingly
ghc: ["9.6.4", "9.8.2"]
cabal: ["3.10.2.1"]
os: [windows-latest, ubuntu-latest]
cabal: ["3.10.3.0"]
sys:
- { os: windows-latest, shell: 'C:/msys64/usr/bin/bash.exe -e {0}' }
- { os: ubuntu-latest, shell: bash }

defaults:
run:
shell: ${{ matrix.sys.shell }}

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2024-02-23-4"
# these two are msys2 env vars, they have no effect on non-msys2 installs.
MSYS2_PATH_TYPE: inherit
MSYSTEM: MINGW64

concurrency:
group: >
Expand All @@ -32,7 +44,7 @@ jobs:
c+${{ github.job }}
d+${{ matrix.ghc }}
e+${{ matrix.cabal }}
f+${{ matrix.os }}
f+${{ matrix.sys.os }}
g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }}
cancel-in-progress: true

Expand All @@ -45,7 +57,7 @@ jobs:
c+${{ github.job }}
d+${{ matrix.ghc }}
e+${{ matrix.cabal }}
f+${{ matrix.os }}
f+${{ matrix.sys.os }}
g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }}
- name: Install Haskell
Expand Down Expand Up @@ -74,11 +86,12 @@ jobs:
- name: Record dependencies
id: record-deps
run: |
# The tests call out to msys2 commands. We generally do not want to mix toolchains, so
# we are very deliberate about only adding msys64 to the path where absolutely necessary.
${{ (runner.os == 'Windows' && '$env:PATH=("C:\msys64\mingw64\bin;{0}" -f $env:PATH)') || '' }}
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 @@ -89,7 +102,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 @@ -105,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 All @@ -115,23 +133,18 @@ jobs:
# files that tests designate as golden files are actually golden files
# and can be generated.
name: Delete golden files
shell: bash
run: |
rm -rf cardano-cli/test/cardano-cli-golden/files/golden
- name: Run tests regenerate golden files
env:
# these two are msys2 env vars, they have no effect on non-msys2 installs.
MSYS2_PATH_TYPE: inherit
MSYSTEM: MINGW64
TMPDIR: ${{ runner.temp }}
TMP: ${{ runner.temp }}
KEEP_WORKSPACE: 1
CREATE_GOLDEN_FILES: 1
run: cabal test all --enable-tests --test-show-details=direct -j1

- name: "Tar artifacts"
shell: bash
run: |
mkdir -p artifacts
Expand All @@ -150,7 +163,7 @@ jobs:
- name: Save Artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.os }}-${{ matrix.ghc }}
name: artifacts-${{ matrix.sys.os }}-${{ matrix.ghc }}
path: ./artifacts

# Uncomment the following back in for debugging. Remember to launch a `pwsh` from
Expand Down
8 changes: 1 addition & 7 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ index-state:
packages:
cardano-cli

package cardano-cli
ghc-options: -Werror

package cardano-api
ghc-options: -Werror

package cardano-api-gen
program-options
ghc-options: -Werror

package cryptonite
Expand Down

0 comments on commit 492b85e

Please sign in to comment.