Skip to content

Commit 409db0a

Browse files
Also create cache when CI fails
This can drastically reduce CI running times when a PR is opened and it initially fails CI, as it no longer needs to rebuild dependencies on every new push.
1 parent 0bf6604 commit 409db0a

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ jobs:
2727
enable-stack: true
2828
stack-version: 'latest'
2929

30-
- name: Cache dependencies
31-
uses: actions/cache@v4
30+
# Ask Stack to use system GHC instead of installing its own copy
31+
- name: Use system GHC
32+
run: |
33+
stack config set system-ghc --global true
34+
35+
- name: Restore cached dependencies
36+
uses: actions/cache/restore@v4
37+
id: cache
3238
with:
3339
path: ~/.stack
3440
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-${{ github.sha }}
@@ -37,10 +43,19 @@ jobs:
3743
${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-
3844
${{ runner.os }}-ghc-${{ matrix.ghc }}-
3945
40-
# Ask Stack to use system GHC instead of installing its own copy
41-
- name: Use system GHC
42-
run: |
43-
stack config set system-ghc --global true
46+
- name: Install dependencies
47+
run: stack build --test --only-dependencies
48+
49+
# Cache dependencies already at this point, so that we do not have to
50+
# rebuild them should the subsequent steps fail
51+
- name: Save cached dependencies
52+
uses: actions/cache/save@v4
53+
# Trying to save over an existing cache gives distracting
54+
# "Warning: Cache save failed." since they are immutable
55+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
56+
with:
57+
path: ~/.stack
58+
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-${{ github.sha }}
4459

4560
- name: Test with Stack
4661
run: |
@@ -95,8 +110,14 @@ jobs:
95110
cabal v2-freeze
96111
mv cabal.project.freeze frozen
97112
98-
- name: Cache dependencies
99-
uses: actions/cache@v4
113+
- name: Restore cached dependencies
114+
uses: actions/cache/restore@v4
115+
id: cache
116+
env:
117+
key:
118+
${{ runner.os }}-ghc-${{ matrix.ghc }}-cabal-${{
119+
steps.setup-haskell.outputs.cabal-version }}${{
120+
matrix.project-variant }}
100121
with:
101122
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
102123
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }}
@@ -105,9 +126,23 @@ jobs:
105126
${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-
106127
${{ runner.os }}-ghc-${{ matrix.ghc }}-
107128
129+
- name: Install dependencies
130+
run: cabal v2-build all --enable-tests --only-dependencies
131+
132+
# Cache dependencies already at this point, so that we do not have to
133+
# rebuild them should the subsequent steps fail
134+
- name: Save cached dependencies
135+
uses: actions/cache/save@v4
136+
# Trying to save over an existing cache gives distracting
137+
# "Warning: Cache save failed." since they are immutable
138+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
139+
with:
140+
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
141+
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }}
142+
108143
- name: Build
109144
run: |
110-
cabal build all --enable-tests
145+
cabal v2-build all --enable-tests
111146
112147
- name: Test
113148
run: |

0 commit comments

Comments
 (0)