Restore Go cache #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # name: Setup GO | |
| # on: push | |
| # # jobs: | |
| # # build: | |
| # # runs-on: ubuntu-latest | |
| # # strategy: | |
| # # matrix: | |
| # # test: [ '1', '2' ] | |
| # # name: Test Job | |
| # # steps: | |
| # # - name: Checkout code | |
| # # uses: actions/checkout@v5 | |
| # # - name: Setup go | |
| # # uses: actions/setup-go@v6 | |
| # # - run: echo "matrix run ${{ matrix.test }}" | |
| # jobs: | |
| # build: | |
| # runs-on: ubuntu-latest | |
| # steps: | |
| # - uses: actions/checkout@v5 | |
| # - name: Setup Go | |
| # id: setup-go | |
| # uses: actions/setup-go@v6 | |
| # with: | |
| # go-version: '1.24' | |
| # cache: false | |
| # - name: Set Go cache environment variables | |
| # run: | | |
| # echo "GO_MOD_CACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV | |
| # echo "GO_BUILD_CACHE=$(go env GOCACHE)" >> $GITHUB_ENV | |
| # - name: Set IMAGE_OS environment variable | |
| # run: | | |
| # if [ "$RUNNER_OS" = "Linux" ]; then | |
| # echo "IMAGE_OS=$ImageOS-" >> $GITHUB_ENV | |
| # else | |
| # echo "IMAGE_OS=" >> $GITHUB_ENV | |
| # fi | |
| # - name: Save lowercase arch | |
| # run: echo "ARCH=$(echo ${{ runner.arch }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| # - name: Restore Go cache | |
| # uses: actions/cache/restore@v4 | |
| # id: go-cache | |
| # with: | |
| # path: | | |
| # ${{ env.GO_MOD_CACHE }} | |
| # ${{ env.GO_BUILD_CACHE }} | |
| # key: setup-go-${{ runner.os }}-${{ env.ARCH }}-${{ env.IMAGE_OS }}-go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('**/go.sum') }} | |
| # restore-keys: | | |
| # setup-go-${{ runner.os }}-${{ env.ARCH }}-${{ env.IMAGE_OS }}-go-${{ steps.setup-go.outputs.go-version }}- | |
| # setup-go- | |
| # - name: Download modules | |
| # run: go mod download | |
| # - name: Build | |
| # run: go build ./... | |
| name: Setup GO | |
| on: push | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-22.04, ubuntu-latest, macos-latest, windows-latest, self-hosted, ubuntu-24.04-arm, windows-11-arm, windows-2022] | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup Go | |
| id: setup-go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.24' | |
| cache: false | |
| - name: Set Go cache variables (Linux/macOS) | |
| if: runner.os != 'Windows' | |
| run: | | |
| echo "GO_MOD_CACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV | |
| echo "GO_BUILD_CACHE=$(go env GOCACHE)" >> $GITHUB_ENV | |
| - name: Set Go cache variables (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| echo "GO_MOD_CACHE=$(go env GOMODCACHE)" | Out-File $env:GITHUB_ENV -Append | |
| echo "GO_BUILD_CACHE=$(go env GOCACHE)" | Out-File $env:GITHUB_ENV -Append | |
| - name: Save lowercase arch (POSIX) | |
| if: runner.os != 'Windows' | |
| run: echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| - name: Save lowercase arch (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| $arch = "${{ runner.arch }}".ToLower() | |
| echo "ARCH=$arch" | Out-File $env:GITHUB_ENV -Append | |
| - name: Set cache OS suffix (Ubuntu only) | |
| if: runner.os == 'Linux' | |
| run: echo "CACHE_OS_SUFFIX=$ImageOS-" >> $GITHUB_ENV | |
| - name: Restore Go cache | |
| id: go-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| ${{ env.GO_MOD_CACHE }} | |
| ${{ env.GO_BUILD_CACHE }} | |
| key: setup-go-${{ runner.os }}-${{ env.ARCH }}-${{ env.CACHE_OS_SUFFIX }}go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('**/go.sum') }} | |
| - name: Download modules | |
| run: go mod download | |
| - name: Build | |
| run: go build ./... |