|
8 | 8 | runs: |
9 | 9 | using: 'composite' |
10 | 10 | 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 | + |
11 | 19 | - name: Find Latest Release Branch |
12 | 20 | shell: bash |
13 | 21 | run: | |
|
31 | 39 | echo "GO_MODCACHE=$(go env GOMODCACHE)" | tee -a "$GITHUB_ENV" |
32 | 40 | echo "GO_VERSION=$(go env GOVERSION | tr -d 'go')" | tee -a "$GITHUB_ENV" |
33 | 41 |
|
| 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 | + |
34 | 52 | - name: Setup read-only cache |
35 | 53 | if: github.ref != 'refs/heads/main' && github.ref != env.LATEST_RELEASE_REF # use custom cache for older minors |
36 | 54 | uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5 |
|
39 | 57 | ${{ env.GO_MODCACHE }} |
40 | 58 | ${{ env.GO_CACHE }} |
41 | 59 | # 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') }} |
43 | 61 | restore-keys: | |
44 | | - setup-go-${{ runner.os }}- |
| 62 | + setup-go-${{ runner.os }}-${{ env.ARCH_OPT }}-go-${{ env.GO_VERSION }}- |
0 commit comments