Skip to content

Commit 20b1d80

Browse files
ci: Split cabal and stack caches into deps and work
More fine-grained caching should give us better cache hits and much fewer upload size in the regular case, improving CI performance.
1 parent 4dc6ce3 commit 20b1d80

File tree

2 files changed

+62
-23
lines changed

2 files changed

+62
-23
lines changed

.cirrus.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ build_task:
1717
'**.hs'
1818
)
1919
20-
stack_cache:
20+
stack_deps_cache:
2121
folders: /.stack
22-
fingerprint_script: cat postgrest.cabal stack.yaml.lock
23-
reupload_on_changes: false
22+
fingerprint_script:
23+
- echo $CIRRUS_OS
24+
- stack --version
25+
- cat stack.yaml.lock
26+
27+
stack_work_cache:
28+
folders: .stack-work
29+
fingerprint_script:
30+
- echo $CIRRUS_OS
31+
- stack --version
32+
- cat stack.yaml.lock
33+
- find main src -type f -iname '*.hs' -exec md5sum "{}" +
2434

2535
build_script: |
2636
stack build -j 1 --local-bin-path . --copy-bins

.github/workflows/build.yaml

+49-20
Original file line numberDiff line numberDiff line change
@@ -91,40 +91,48 @@ jobs:
9191
runs-on: ubuntu-22.04
9292
cache: |
9393
~/.stack
94-
.stack-work
9594
# no artifact for Linux, because we use the static build
9695

9796
- name: MacOS
9897
runs-on: macos-12
9998
cache: |
10099
~/.stack
101-
.stack-work
102100
artifact: postgrest-macos-x64
103101

104102
- name: Windows
105103
runs-on: windows-2022
106104
cache: |
107105
~\AppData\Roaming\stack
108106
~\AppData\Local\Programs\stack
109-
.stack-work
110107
deps: Add-Content $env:GITHUB_PATH $env:PGBIN
111108
artifact: postgrest-windows-x64
112109

113110
name: Stack - ${{ matrix.name }}
114111
runs-on: ${{ matrix.runs-on }}
115112
steps:
116113
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
117-
- name: Restore stack working files cache
114+
- name: Install dependencies
115+
if: matrix.deps
116+
run: ${{ matrix.deps }}
117+
- name: Restore ~/.stack cache
118118
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
119-
id: restore-cache
119+
id: restore-stack
120120
with:
121121
path: ${{ matrix.cache }}
122-
key: stack-${{ runner.os }}-${{ hashFiles('stack.yaml.lock') }}
122+
key: stack-${{ runner.os }}-deps-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('postgrest.cabal') }}
123123
restore-keys: |
124-
stack-${{ runner.os }}-
125-
- name: Install dependencies
126-
if: matrix.deps
127-
run: ${{ matrix.deps }}
124+
stack-${{ runner.os }}-deps-${{ hashFiles('stack.yaml.lock') }}-
125+
stack-${{ runner.os }}-deps-
126+
- name: Restore .stack-work cache
127+
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
128+
id: restore-stack-work
129+
with:
130+
path: .stack-work
131+
key: stack-${{ runner.os }}-work-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('postgrest.cabal') }}-${{ hashFiles('main/*.hs', 'src/**/*.hs') }}
132+
restore-keys: |
133+
stack-${{ runner.os }}-work-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('postgrest.cabal') }}-
134+
stack-${{ runner.os }}-work-${{ hashFiles('stack.yaml.lock') }}-
135+
stack-${{ runner.os }}-work-
128136
- name: Build with Stack
129137
run: stack build --lock-file error-on-write --local-bin-path result --copy-bins
130138
- name: Strip Executable
@@ -138,12 +146,18 @@ jobs:
138146
result/postgrest
139147
result/postgrest.exe
140148
if-no-files-found: error
141-
- name: Save stack working files cache
149+
- name: Save .stack-work cache
150+
if: startsWith(github.ref, 'refs/heads/')
151+
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
152+
with:
153+
path: .stack-work
154+
key: ${{ steps.restore-stack-work.outputs.cache-primary-key }}
155+
- name: Save ~/.stack cache
142156
if: startsWith(github.ref, 'refs/heads/')
143157
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
144158
with:
145159
path: ${{ matrix.cache }}
146-
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
160+
key: ${{ steps.restore-stack.outputs.cache-primary-key }}
147161

148162

149163
freebsd:
@@ -177,29 +191,44 @@ jobs:
177191
- name: Fix caching
178192
run: |
179193
mkdir ~/.cabal
180-
- name: Restore cache
194+
- name: Restore .cabal cache
181195
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
182-
id: restore-cache
196+
id: restore-cabal
183197
with:
184198
path: |
185199
~/.cabal/packages
186200
~/.cabal/store
187-
dist-newstyle
188-
key: cabal-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('postgrest.cabal', 'cabal.project', 'cabal.project.freeze') }}
201+
key: cabal-${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-${{ hashFiles('postgrest.cabal') }}
189202
restore-keys: |
190-
cabal-${{ runner.os }}-${{ matrix.ghc }}-
203+
cabal-${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-
204+
cabal-${{ runner.os }}-${{ matrix.ghc }}-cabal-
205+
- name: Restore dist-newstyle cache
206+
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
207+
id: restore-dist-newstyle
208+
with:
209+
path: dist-newstyle
210+
key: cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-${{ hashFiles('postgrest.cabal') }}-${{ hashFiles('**/*.hs') }}
211+
restore-keys: |
212+
cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-${{ hashFiles('postgrest.cabal') }}-
213+
cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-
214+
cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-
191215
- name: Install dependencies
192216
run: |
193217
cabal update
194218
cabal build --only-dependencies --enable-tests --enable-benchmarks
195219
- name: Build
196220
run: cabal build --enable-tests --enable-benchmarks all
197-
- name: Save cache
221+
- name: Save dist-newstyle cache
222+
if: startsWith(github.ref, 'refs/heads/')
223+
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
224+
with:
225+
path: dist-newstyle
226+
key: ${{ steps.restore-dist-newstyle.outputs.cache-primary-key }}
227+
- name: Save .cabal cache
198228
if: startsWith(github.ref, 'refs/heads/')
199229
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
200230
with:
201231
path: |
202232
~/.cabal/packages
203233
~/.cabal/store
204-
dist-newstyle
205-
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
234+
key: ${{ steps.restore-cabal.outputs.cache-primary-key }}

0 commit comments

Comments
 (0)