From dc5aaa96b96bf74e7db251ee78675cd4ad8ffef8 Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Sun, 10 Nov 2024 19:43:47 +0000 Subject: [PATCH] chore: Upload cache only from test jobs --- .github/actions/setup-go/action.yml | 46 ++++++++++++++++++++++ .github/workflows/main.yml | 59 +++++++++++++---------------- 2 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 .github/actions/setup-go/action.yml diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml new file mode 100644 index 00000000000..19c6ce74769 --- /dev/null +++ b/.github/actions/setup-go/action.yml @@ -0,0 +1,46 @@ +name: setup-go +description: Set up Go environment and enable caching +inputs: + go-version: + description: Go version to set up + required: true +runs: + using: composite + steps: + - name: setup-go-env + shell: bash + run: | + if [ "$RUNNER_OS" = "Windows" ]; then + echo "GOCACHE=D:\\golang\\cache" >> $GITHUB_ENV + echo "GOMODCACHE=D:\\golang\\modcache" >> $GITHUB_ENV + echo "GOPATH=D:\\golang\\go" >> $GITHUB_ENV + echo "USERPROFILE=D:\\homedir" >> $GITHUB_ENV + elif [ "$RUNNER_OS" = "macOS" ]; then + echo "GOCACHE=/Users/runner/go/pkg/mod" >> $GITHUB_ENV + echo "GOMODCACHE=/Users/runner/Library/Caches/go-build" >> $GITHUB_ENV + else + echo "GOCACHE=/home/runner/go/pkg/mod" >> $GITHUB_ENV + echo "GOMODCACHE=/home/runner/.cache/go-build" >> $GITHUB_ENV + fi + - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + if: ${{ startsWith(github.job, 'test-') }} + with: + path: | + ${{ env.GOCACHE }} + ${{ env.GOMODCACHE }} + key: test-go-${{ runner.os }}-${{ runner.arch }}-go-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + test-go-${{ runner.os }}-${{ runner.arch }}-go-${{ inputs.go-version }}- + - uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a + if: ${{ !startsWith(github.job, 'test-') }} + with: + path: | + ${{ env.GOCACHE }} + ${{ env.GOMODCACHE }} + key: test-go-${{ runner.os }}-${{ runner.arch }}-go-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + test-go-${{ runner.os }}-${{ runner.arch }}-go-${{ inputs.go-version }}- + - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed + with: + cache: false + go-version: ${{ inputs.go-version }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25408e66d05..80fafe332af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,14 +65,10 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: fetch-depth: 1 - - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + - name: setup-go + uses: ./.github/actions/setup-go with: - path: | - /home/runner/go/pkg/mod - /home/runner/.cache/go-build - key: setup-go-${{ runner.os }}-x64-ubuntu22-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - setup-go-${{ runner.os }}-x64-ubuntu22-go-${{ env.GO_VERSION }}- + go-version: ${{ env.GO_VERSION }} - uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd with: languages: go @@ -137,7 +133,8 @@ jobs: contents: read steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed + - name: setup-go + uses: ./.github/actions/setup-go with: go-version: ${{ env.GO_VERSION }} - name: build @@ -163,7 +160,7 @@ jobs: env: CHEZMOI_GITHUB_TOKEN: ${{ secrets.CHEZMOI_GITHUB_TOKEN }} run: | - go test -race ./... + go test -race -v ./... test-oldstable-go: needs: changes if: github.event_name == 'push' || needs.changes.outputs.code == 'true' @@ -269,6 +266,7 @@ jobs: name: chezmoi-windows-amd64 path: dist/chezmoi-nocgo_windows_amd64_v1/chezmoi.exe test-ubuntu: + name: test-ubuntu-umask${{ matrix.umask }} strategy: fail-fast: false matrix: @@ -283,17 +281,9 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: fetch-depth: 0 - - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a - with: - path: | - /home/runner/go/pkg/mod - /home/runner/.cache/go-build - key: setup-go-${{ runner.os }}-x64-ubuntu22-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - setup-go-${{ runner.os }}-x64-ubuntu22-go-${{ env.GO_VERSION }}- - - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed + - name: setup-go + uses: ./.github/actions/setup-go with: - cache: false go-version: ${{ env.GO_VERSION }} - name: install-age if: github.event_name == 'push' || needs.changes.outputs.code == 'true' @@ -319,7 +309,7 @@ jobs: env: CHEZMOI_GITHUB_TOKEN: ${{ secrets.CHEZMOI_GITHUB_TOKEN }} run: | - go test -ldflags="-X github.com/twpayne/chezmoi/v2/internal/chezmoitest.umaskStr=0o${{ matrix.umask }}" -race -timeout=1h ./... + go test -ldflags="-X github.com/twpayne/chezmoi/v2/internal/chezmoitest.umaskStr=0o${{ matrix.umask }}" -race -timeout=1h -v ./... test-website: runs-on: ubuntu-22.04 permissions: @@ -358,11 +348,10 @@ jobs: contents: read env: GOPATH: 'D:\golang\go' - GOCACHE: 'D:\golang\cache' - GOMODCACHE: 'D:\golang\modcache' steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed + - name: setup-go + uses: ./.github/actions/setup-go with: go-version: ${{ env.GO_VERSION }} - name: build @@ -375,7 +364,7 @@ jobs: env: CHEZMOI_GITHUB_TOKEN: ${{ secrets.CHEZMOI_GITHUB_TOKEN }} run: | - go test -race ./... + go test -race -v ./... check: runs-on: ubuntu-22.04 permissions: @@ -384,8 +373,18 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: fetch-depth: 0 + - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + with: + lookup-only: true + path: | + /home/runner/go/pkg/mod + /home/runner/.cache/go-build + key: tests-go-${{ runner.os }}-${{ runner.arch }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + tests-go-${{ runner.os }}-${{ runner.arch }}-go-${{ env.GO_VERSION }}- - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed with: + cache: false go-version: ${{ env.GO_VERSION }} - name: generate run: | @@ -428,7 +427,7 @@ jobs: fail-fast: false matrix: runs-on: - - macos-14 + - macos-13 - ubuntu-22.04 - windows-2022 needs: changes @@ -436,16 +435,12 @@ jobs: runs-on: ${{ matrix.runs-on }} permissions: contents: read - env: - GOPATH: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\golang\go' || '' }} - GOCACHE: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\golang\cache' || '' }} - GOMODCACHE: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\golang\modcache' || '' }} - USERPROFILE: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\homedir' || '' }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed + - name: setup-go + uses: ./.github/actions/setup-go with: - go-version: stable + go-version: ${{ env.GO_VERSION }} - uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 with: version: v${{ env.GOLANGCI_LINT_VERSION }}