Skip to content

Commit

Permalink
ci: Split cabal and stack caches into deps and work
Browse files Browse the repository at this point in the history
More fine-grained caching should give us better cache hits and much
fewer upload size in the regular case, improving CI performance.
  • Loading branch information
wolfgangwalther committed May 12, 2024
1 parent 4dc6ce3 commit 20b1d80
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 23 deletions.
16 changes: 13 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ build_task:
'**.hs'
)
stack_cache:
stack_deps_cache:
folders: /.stack
fingerprint_script: cat postgrest.cabal stack.yaml.lock
reupload_on_changes: false
fingerprint_script:
- echo $CIRRUS_OS
- stack --version
- cat stack.yaml.lock

stack_work_cache:
folders: .stack-work
fingerprint_script:
- echo $CIRRUS_OS
- stack --version
- cat stack.yaml.lock
- find main src -type f -iname '*.hs' -exec md5sum "{}" +

build_script: |
stack build -j 1 --local-bin-path . --copy-bins
Expand Down
69 changes: 49 additions & 20 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,48 @@ jobs:
runs-on: ubuntu-22.04
cache: |
~/.stack
.stack-work
# no artifact for Linux, because we use the static build

- name: MacOS
runs-on: macos-12
cache: |
~/.stack
.stack-work
artifact: postgrest-macos-x64

- name: Windows
runs-on: windows-2022
cache: |
~\AppData\Roaming\stack
~\AppData\Local\Programs\stack
.stack-work
deps: Add-Content $env:GITHUB_PATH $env:PGBIN
artifact: postgrest-windows-x64

name: Stack - ${{ matrix.name }}
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Restore stack working files cache
- name: Install dependencies
if: matrix.deps
run: ${{ matrix.deps }}
- name: Restore ~/.stack cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: restore-cache
id: restore-stack
with:
path: ${{ matrix.cache }}
key: stack-${{ runner.os }}-${{ hashFiles('stack.yaml.lock') }}
key: stack-${{ runner.os }}-deps-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('postgrest.cabal') }}
restore-keys: |
stack-${{ runner.os }}-
- name: Install dependencies
if: matrix.deps
run: ${{ matrix.deps }}
stack-${{ runner.os }}-deps-${{ hashFiles('stack.yaml.lock') }}-
stack-${{ runner.os }}-deps-
- name: Restore .stack-work cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: restore-stack-work
with:
path: .stack-work
key: stack-${{ runner.os }}-work-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('postgrest.cabal') }}-${{ hashFiles('main/*.hs', 'src/**/*.hs') }}
restore-keys: |
stack-${{ runner.os }}-work-${{ hashFiles('stack.yaml.lock') }}-${{ hashFiles('postgrest.cabal') }}-
stack-${{ runner.os }}-work-${{ hashFiles('stack.yaml.lock') }}-
stack-${{ runner.os }}-work-
- name: Build with Stack
run: stack build --lock-file error-on-write --local-bin-path result --copy-bins
- name: Strip Executable
Expand All @@ -138,12 +146,18 @@ jobs:
result/postgrest
result/postgrest.exe
if-no-files-found: error
- name: Save stack working files cache
- name: Save .stack-work cache
if: startsWith(github.ref, 'refs/heads/')
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: .stack-work
key: ${{ steps.restore-stack-work.outputs.cache-primary-key }}
- name: Save ~/.stack cache
if: startsWith(github.ref, 'refs/heads/')
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ matrix.cache }}
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
key: ${{ steps.restore-stack.outputs.cache-primary-key }}


freebsd:
Expand Down Expand Up @@ -177,29 +191,44 @@ jobs:
- name: Fix caching
run: |
mkdir ~/.cabal
- name: Restore cache
- name: Restore .cabal cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: restore-cache
id: restore-cabal
with:
path: |
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: cabal-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('postgrest.cabal', 'cabal.project', 'cabal.project.freeze') }}
key: cabal-${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-${{ hashFiles('postgrest.cabal') }}
restore-keys: |
cabal-${{ runner.os }}-${{ matrix.ghc }}-
cabal-${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-
cabal-${{ runner.os }}-${{ matrix.ghc }}-cabal-
- name: Restore dist-newstyle cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: restore-dist-newstyle
with:
path: dist-newstyle
key: cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-${{ hashFiles('postgrest.cabal') }}-${{ hashFiles('**/*.hs') }}
restore-keys: |
cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-${{ hashFiles('postgrest.cabal') }}-
cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-${{ hashFiles('cabal.project', 'cabal.project.freeze') }}-
cabal-${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle-
- name: Install dependencies
run: |
cabal update
cabal build --only-dependencies --enable-tests --enable-benchmarks
- name: Build
run: cabal build --enable-tests --enable-benchmarks all
- name: Save cache
- name: Save dist-newstyle cache
if: startsWith(github.ref, 'refs/heads/')
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: dist-newstyle
key: ${{ steps.restore-dist-newstyle.outputs.cache-primary-key }}
- name: Save .cabal cache
if: startsWith(github.ref, 'refs/heads/')
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
key: ${{ steps.restore-cabal.outputs.cache-primary-key }}

0 comments on commit 20b1d80

Please sign in to comment.