Skip to content

Commit 23aad64

Browse files
authored
Keep reusing caches from previous runs for copilot runs (#1390)
1 parent 5f0157e commit 23aad64

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

.github/actions/setup-go/action.yml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
cache-name:
99
description: Name of scoped cache for this set up.
1010
default: 'cache'
11+
cache-from-previous-run:
12+
description: Use the cache from the previous run if available.
13+
default: 'false'
1114

1215
runs:
1316
using: composite
@@ -19,15 +22,37 @@ runs:
1922
go-version: ${{ inputs.go-version }}
2023
cache: false
2124

25+
# There is more code downloaded and built than is covered by '**/go.sum',
26+
# so give each job its own cache to try and not end up sharing the wrong
27+
# cache between jobs, and hash the Herebyfile and golancgi-lint version.
28+
29+
# In cache-from-previous-run mode, we try to restore the cache from the
30+
# previous run, and force the next cache to be saved by keying it on the
31+
# run ID.
32+
33+
- name: Create Go cache keys
34+
id: go-cache-keys
35+
shell: bash
36+
run: |
37+
if [[ "$CACHE_FROM_PREVIOUS_RUN" == "true" ]]; then
38+
echo "key=$PREFIX-$CACHE_NAME-$RUN_ID" >> $GITHUB_OUTPUT
39+
echo "restore-keys=$PREFIX-$CACHE_NAME" >> $GITHUB_OUTPUT
40+
else
41+
echo "key=$PREFIX-$CACHE_NAME" >> $GITHUB_OUTPUT
42+
echo "restore-keys=$PREFIX" >> $GITHUB_OUTPUT
43+
fi
44+
45+
env:
46+
PREFIX: ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}-${{ github.workflow }}
47+
CACHE_NAME: ${{ inputs.cache-name }}
48+
RUN_ID: ${{ github.run_id }}
49+
CACHE_FROM_PREVIOUS_RUN: ${{ inputs.cache-from-previous-run }}
50+
2251
- name: Go cache
2352
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
2453
with:
25-
# There is more code downloaded and built than is covered by '**/go.sum',
26-
# so give each job its own cache to try and not end up sharing the wrong
27-
# cache between jobs.
28-
key: ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}-${{ github.workflow }}-${{ inputs.cache-name }}
29-
restore-keys: |
30-
ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}
54+
key: ${{ steps.go-cache-keys.outputs.key }}
55+
restore-keys: ${{ steps.go-cache-keys.outputs.restore-keys }}
3156
path: |
3257
~/go/pkg/mod
3358
~/.cache/go-build

.github/workflows/copilot-setup-steps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
# Updated to 1.25.0-rc.1 to improve compilation time
2727
go-version: '>=1.25.0-rc.1'
2828
cache-name: copilot-setup-steps
29+
cache-from-previous-run: 'true'
2930
- run: npm i -g @playwright/mcp@0.0.28
3031
- run: npm ci
3132
# pull dprint caches before network access is blocked

0 commit comments

Comments
 (0)