ci: Split cabal and stack work caches from regular cache

This is a first step to split up the cabal and stack caches in separate
pieces. Here we split the work folder, which just contains the
postgrest-specific build artifacts, into a separate cache.

More fine-grained caching should give us better cache hits and much
fewer upload size in the regular case, improving CI performance.

Since the work file caches are very small (about 30-40 MB) they are
cached for PRs, too. This will allow the majority of PRs, which only
change source code files, but no dependencies, to still have cached
their build files for additional commits.
This commit is contained in:
Wolfgang Walther
2024-05-20 15:43:00 +02:00
committed by Wolfgang Walther
parent c4b0bd347b
commit 279febe26b
3 changed files with 38 additions and 12 deletions
+14 -2
View File
@@ -19,8 +19,20 @@ build_task:
stack_cache: stack_cache:
folders: /.stack folders: /.stack
fingerprint_script: cat postgrest.cabal stack.yaml.lock fingerprint_script:
reupload_on_changes: false - echo $CIRRUS_OS
- stack --version
- md5sum postgrest.cabal
- md5sum stack.yaml.lock
stack_work_cache:
folders: .stack-work
fingerprint_script:
- echo $CIRRUS_OS
- stack --version
- md5sum postgrest.cabal
- md5sum stack.yaml.lock
- find main src -type f -iname '*.hs' -exec md5sum "{}" +
build_script: | build_script: |
stack build -j 1 --local-bin-path . --copy-bins --stack-yaml stack-21.7.yaml stack build -j 1 --local-bin-path . --copy-bins --stack-yaml stack-21.7.yaml
+7 -3
View File
@@ -1,29 +1,33 @@
name: Cache on main name: Cache on main
description: Stores caches on main only, but restores them on all branches. description: Stores caches on main and release branches only, but restores them on all branches.
inputs: inputs:
path: path:
description: Path(s) to cache description: Path(s) to cache
required: true required: true
save-prs:
description: Whether to additionally store the cache in a pull request, too. Should only be used for very small caches.
default: false
prefix: prefix:
description: Cache key prefix to be used in both primary key and restore-keys. description: Cache key prefix to be used in both primary key and restore-keys.
required: true required: true
suffix: suffix:
description: Cache key suffix to be used only in primary key. description: Cache key suffix to be used only in primary key.
required: true
runs: runs:
using: composite using: composite
steps: steps:
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
if: ${{ startsWith(github.ref, 'refs/heads/') }} if: ${{ startsWith(github.ref, 'refs/heads/') || (inputs.save-prs && github.head_ref) }}
with: with:
path: ${{ inputs.path }} path: ${{ inputs.path }}
key: ${{ runner.os }}-${{ inputs.prefix }}-${{ inputs.suffix }} key: ${{ runner.os }}-${{ inputs.prefix }}-${{ inputs.suffix }}
restore-keys: | restore-keys: |
${{ runner.os }}-${{ inputs.prefix }}- ${{ runner.os }}-${{ inputs.prefix }}-
- uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
if: ${{ !startsWith(github.ref, 'refs/heads/') }} if: ${{ !startsWith(github.ref, 'refs/heads/') && !(inputs.save-prs && github.head_ref) }}
with: with:
path: ${{ inputs.path }} path: ${{ inputs.path }}
key: ${{ runner.os }}-${{ inputs.prefix }}-${{ inputs.suffix }} key: ${{ runner.os }}-${{ inputs.prefix }}-${{ inputs.suffix }}
+17 -7
View File
@@ -91,14 +91,12 @@ jobs:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
cache: | cache: |
~/.stack ~/.stack
.stack-work
# no artifact for Linux, because we use the static build # no artifact for Linux, because we use the static build
- name: MacOS - name: MacOS
runs-on: macos-12 runs-on: macos-12
cache: | cache: |
~/.stack ~/.stack
.stack-work
artifact: postgrest-macos-x64 artifact: postgrest-macos-x64
- name: Windows - name: Windows
@@ -106,7 +104,6 @@ jobs:
cache: | cache: |
~\AppData\Roaming\stack ~\AppData\Roaming\stack
~\AppData\Local\Programs\stack ~\AppData\Local\Programs\stack
.stack-work
deps: Add-Content $env:GITHUB_PATH $env:PGBIN deps: Add-Content $env:GITHUB_PATH $env:PGBIN
artifact: postgrest-windows-x64 artifact: postgrest-windows-x64
@@ -114,12 +111,19 @@ jobs:
runs-on: ${{ matrix.runs-on }} runs-on: ${{ matrix.runs-on }}
steps: steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Stack working files cache - name: Cache ~/.stack
uses: ./.github/actions/cache-on-main uses: ./.github/actions/cache-on-main
with: with:
path: ${{ matrix.cache }} path: ${{ matrix.cache }}
prefix: stack prefix: stack
suffix: ${{ hashFiles('stack.yaml.lock') }} suffix: ${{ hashFiles('postgrest.cabal', 'stack.yaml.lock') }}
- name: Cache .stack-work
uses: ./.github/actions/cache-on-main
with:
path: .stack-work
save-prs: true
prefix: stack-work-${{ hashFiles('postgrest.cabal', 'stack.yaml.lock') }}
suffix: ${{ hashFiles('main/**/*.hs', 'src/**/*.hs') }}
- name: Install dependencies - name: Install dependencies
if: matrix.deps if: matrix.deps
run: ${{ matrix.deps }} run: ${{ matrix.deps }}
@@ -169,15 +173,21 @@ jobs:
- name: Fix caching - name: Fix caching
run: | run: |
mkdir ~/.cabal mkdir ~/.cabal
- name: Cache - name: Cache .cabal
uses: ./.github/actions/cache-on-main uses: ./.github/actions/cache-on-main
with: with:
path: | path: |
~/.cabal/packages ~/.cabal/packages
~/.cabal/store ~/.cabal/store
dist-newstyle
prefix: cabal-${{ matrix.ghc }} prefix: cabal-${{ matrix.ghc }}
suffix: ${{ hashFiles('postgrest.cabal', 'cabal.project', 'cabal.project.freeze') }} suffix: ${{ hashFiles('postgrest.cabal', 'cabal.project', 'cabal.project.freeze') }}
- name: Cache dist-newstyle
uses: ./.github/actions/cache-on-main
with:
path: dist-newstyle
save-prs: true
prefix: cabal-${{ matrix.ghc }}-dist-newstyle-${{ hashFiles('postgrest.cabal', 'cabal.project', 'cabal.project.freeze') }}
suffix: ${{ hashFiles('**/*.hs') }}
- name: Install dependencies - name: Install dependencies
run: | run: |
cabal update cabal update