Skip to content

Commit

Permalink
chore: Upload cache only from test jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Nov 10, 2024
1 parent 92f8a98 commit dc5aaa9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 32 deletions.
46 changes: 46 additions & 0 deletions .github/actions/setup-go/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
59 changes: 27 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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: |
Expand Down Expand Up @@ -428,24 +427,20 @@ jobs:
fail-fast: false
matrix:
runs-on:
- macos-14
- macos-13
- ubuntu-22.04
- windows-2022
needs: changes
if: github.event_name == 'push' || needs.changes.outputs.code == 'true'
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 }}
Expand Down

0 comments on commit dc5aaa9

Please sign in to comment.