| 1 | name: Go build cache |
| 2 | description: >- |
| 3 | Restore the newest Go build and module cache for this runner and module. |
| 4 | setup-go keys its cache on go.sum alone and GitHub never rewrites an existing |
| 5 | key, so that snapshot freezes at the last dependency change and every package |
| 6 | touched since misses. This cache is keyed per run and restored by prefix; a |
| 7 | main-v2 push saves it from one job per OS and module (actions/cache/save with |
| 8 | the outputs below), pull requests only restore. Windows jobs do not use it: |
| 9 | restoring it there measured slower than setup-go's frozen cache. |
| 10 | |
| 11 | inputs: |
| 12 | module: |
| 13 | description: Cache namespace, e.g. root, root-race, desktop, desktop-race |
| 14 | required: true |
| 15 | |
| 16 | outputs: |
| 17 | key: |
| 18 | description: Exact key for this run's save step |
| 19 | value: ${{ steps.key.outputs.key }} |
| 20 | paths: |
| 21 | description: GOCACHE and GOMODCACHE, one per line |
| 22 | value: ${{ steps.key.outputs.paths }} |
| 23 | |
| 24 | runs: |
| 25 | using: composite |
| 26 | steps: |
| 27 | - id: key |
| 28 | shell: bash |
| 29 | run: | |
| 30 | set -euo pipefail |
| 31 | sums="$(git hash-object go.sum desktop/go.sum | git hash-object --stdin)" |
| 32 | base="go-${{ runner.os }}-${{ runner.arch }}-${{ inputs.module }}" |
| 33 | { |
| 34 | echo "key=${base}-${sums:0:16}-${{ github.run_id }}-${{ github.run_attempt }}" |
| 35 | echo "sums=${base}-${sums:0:16}-" |
| 36 | echo "base=${base}-" |
| 37 | echo "paths<<EOF" |
| 38 | go env GOCACHE |
| 39 | go env GOMODCACHE |
| 40 | echo "EOF" |
| 41 | } >> "$GITHUB_OUTPUT" |
| 42 | |
| 43 | - uses: actions/cache/restore@v4 |
| 44 | with: |
| 45 | path: ${{ steps.key.outputs.paths }} |
| 46 | key: ${{ steps.key.outputs.key }} |
| 47 | restore-keys: | |
| 48 | ${{ steps.key.outputs.sums }} |
| 49 | ${{ steps.key.outputs.base }} |
| 50 |