Skip to content

Commit e4777ac

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 86fe95c commit e4777ac

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

.github/workflows/ci.yml

Lines changed: 52 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,23 @@ 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 }}
59+
restore-keys: |
60+
${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-${{ github.sha }}
61+
${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-
62+
${{ runner.os }}-ghc-${{ matrix.ghc }}-
4463
4564
- name: Test with Stack
4665
run: |
@@ -95,8 +114,32 @@ jobs:
95114
cabal v2-freeze
96115
mv cabal.project.freeze frozen
97116
98-
- name: Cache dependencies
99-
uses: actions/cache@v4
117+
- name: Restore cached dependencies
118+
uses: actions/cache/restore@v4
119+
id: cache
120+
env:
121+
key:
122+
${{ runner.os }}-ghc-${{ matrix.ghc }}-cabal-${{
123+
steps.setup-haskell.outputs.cabal-version }}${{
124+
matrix.project-variant }}
125+
with:
126+
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
127+
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }}
128+
restore-keys: |
129+
${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }}
130+
${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-
131+
${{ runner.os }}-ghc-${{ matrix.ghc }}-
132+
133+
- name: Install dependencies
134+
run: cabal v2-build all --enable-tests --only-dependencies
135+
136+
# Cache dependencies already at this point, so that we do not have to
137+
# rebuild them should the subsequent steps fail
138+
- name: Save cached dependencies
139+
uses: actions/cache/save@v3
140+
# Trying to save over an existing cache gives distracting
141+
# "Warning: Cache save failed." since they are immutable
142+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
100143
with:
101144
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
102145
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }}
@@ -107,7 +150,7 @@ jobs:
107150
108151
- name: Build
109152
run: |
110-
cabal build all --enable-tests
153+
cabal v2-build all --enable-tests
111154
112155
- name: Test
113156
run: |

0 commit comments

Comments
 (0)