Skip to content

Commit 6aa7e9e

Browse files
committed
Fix install-go cache key
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 50da0bb commit 6aa7e9e

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ inputs:
88
runs:
99
using: 'composite'
1010
steps:
11+
# On self-hosted runners, the env.ImageOS variable may not be set correctly, which can cause issues with the cache key.
12+
# We need to handle this case to ensure the cache key is consistent.
13+
- name: Set ImageOS
14+
if: ${{ runner.os == 'Linux' && env.ImageOS == '' }}
15+
shell: bash
16+
# Key is ubuntu<MAJOR>, as there is not other linux os in GHA other than Ubuntu
17+
run: echo "ImageOS=ubuntu$(lsb_release -rs | cut -d. -f1)" >> $GITHUB_ENV
18+
1119
- name: Find Latest Release Branch
1220
shell: bash
1321
run: |
@@ -31,6 +39,16 @@ runs:
3139
echo "GO_MODCACHE=$(go env GOMODCACHE)" | tee -a "$GITHUB_ENV"
3240
echo "GO_VERSION=$(go env GOVERSION | tr -d 'go')" | tee -a "$GITHUB_ENV"
3341
42+
- name: Create arch key (Linux)
43+
if: ${{ runner.os == 'Linux' }}
44+
shell: bash
45+
run: echo "ARCH_OPT=$(echo ${{ runner.arch }} | tr '[:upper:]' '[:lower:]')-${{ env.ImageOS }}" >> $GITHUB_ENV
46+
47+
- name: Create arch key (non-Linux)
48+
if: ${{ runner.os != 'Linux' }}
49+
shell: pwsh
50+
run: echo "ARCH_OPT=$('${{ runner.arch }}'.ToLower())" | Out-File -FilePath $env:GITHUB_ENV -Append
51+
3452
- name: Setup read-only cache
3553
if: github.ref != 'refs/heads/main' && github.ref != env.LATEST_RELEASE_REF # use custom cache for older minors
3654
uses: actions/cache/restore@v5
@@ -39,6 +57,6 @@ runs:
3957
${{ env.GO_MODCACHE }}
4058
${{ env.GO_CACHE }}
4159
# Match the cache key to the setup-go action https://github.com/actions/setup-go/blob/main/src/cache-restore.ts#L34
42-
key: setup-go-${{ runner.os }}-${{ env.ImageOS }}-go-${{ env.GO_VERSION }}-${{ hashFiles('go.sum') }}
60+
key: setup-go-${{ runner.os }}-${{ env.ARCH_OPT }}-go-${{ env.GO_VERSION }}-${{ hashFiles('go.sum') }}
4361
restore-keys: |
44-
setup-go-${{ runner.os }}-
62+
setup-go-${{ runner.os }}-${{ env.ARCH_OPT }}-go-${{ env.GO_VERSION }}-

0 commit comments

Comments
 (0)