|
| 1 | +name: warm caches |
| 2 | + |
| 3 | +# Builds the dependencies and the packages on every platform after each push |
| 4 | +# to trunk, and saves the stack caches (~/.stack and **/.stack-work) under |
| 5 | +# trunk's cache scope. |
| 6 | +# |
| 7 | +# A workflow run can only restore caches made on its own branch or on the |
| 8 | +# default branch. The merge queue runs on throwaway gh-readonly-queue/* |
| 9 | +# branches, so the caches it saves die with them, and no other workflow builds |
| 10 | +# on trunk, so until this one existed every merge-queue build started cold and |
| 11 | +# spent 20 to 48 minutes rebuilding dependencies. With trunk's caches warm, a |
| 12 | +# merge-queue build restores them and compiles only what the pull request |
| 13 | +# changed. |
| 14 | + |
| 15 | +on: |
| 16 | + push: |
| 17 | + branches: |
| 18 | + - trunk |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +defaults: |
| 22 | + run: |
| 23 | + shell: bash |
| 24 | + |
| 25 | +jobs: |
| 26 | + warm: |
| 27 | + name: warm caches (${{ matrix.os }}) |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + # a newer trunk push supersedes a run still going for the same platform |
| 30 | + concurrency: |
| 31 | + group: warm-caches-${{ matrix.os }} |
| 32 | + cancel-in-progress: true |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + matrix: |
| 36 | + os: ["ubuntu-24.04", "ubuntu-24.04-arm", "macos-15-intel", "macos-15", "windows-2025"] |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 39 | + |
| 40 | + - name: restore stack caches |
| 41 | + id: restore-stack-caches |
| 42 | + uses: unisonweb/actions/stack/cache/restore@main |
| 43 | + with: |
| 44 | + cache-prefix: ci |
| 45 | + |
| 46 | + - name: install stack |
| 47 | + if: steps.restore-stack-caches.outputs.work-cache-hit != 'true' |
| 48 | + uses: unisonweb/actions/stack/install@main |
| 49 | + with: |
| 50 | + stack-version: 3.9.3 |
| 51 | + |
| 52 | + - name: build dependencies |
| 53 | + if: steps.restore-stack-caches.outputs.work-cache-hit != 'true' |
| 54 | + run: | |
| 55 | + stack --version |
| 56 | + tries=1 |
| 57 | + if [[ ${{matrix.os}} = "windows-"* ]]; then |
| 58 | + tries=5 |
| 59 | + fi |
| 60 | +
|
| 61 | + for (( i = 0; i < $tries; i++ )); do |
| 62 | + stack build --fast --only-dependencies --test --bench && break; |
| 63 | + done |
| 64 | +
|
| 65 | + - name: build |
| 66 | + if: steps.restore-stack-caches.outputs.work-cache-hit != 'true' |
| 67 | + run: stack build --fast --test --no-run-tests |
| 68 | + |
| 69 | + - name: save stack caches |
| 70 | + if: | |
| 71 | + !cancelled() |
| 72 | + && steps.restore-stack-caches.outputs.work-cache-hit != 'true' |
| 73 | + uses: unisonweb/actions/stack/cache/save@main |
| 74 | + with: |
| 75 | + cache-prefix: ci |
0 commit comments