Skip to content

Commit

Permalink
ci: avoid using default caching feature of actions/setup-go
Browse files Browse the repository at this point in the history
`actions/setup-go` configures the cache under the assumption that a single module will be built with one setup.

Signed-off-by: Norio Nomura <[email protected]>
  • Loading branch information
norio-nomura committed Sep 2, 2024
1 parent dc36df8 commit 7cfcddd
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 10 deletions.
47 changes: 47 additions & 0 deletions .github/actions/setup_cache_for_go/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: setup cache for go
description: setup cache for go. export GOMODCACHE environment variable
inputs:
go-version:
description: go version
required: true
runs-on:
description: runs on
required: true
working-directory:
description: working directory
default: '.'
runs:
using: "composite"
steps:
- name: Set GOMODCACHE environment variable
run: echo "GOMODCACHE=$(pwd)/.gomodcache" >> $GITHUB_ENV
shell: bash
- id: go-env
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "GOMOD=$(go env GOMOD)" >> $GITHUB_OUTPUT
echo "GOSUM=$(realpath go.sum)" >> $GITHUB_OUTPUT
shell: bash
working-directory: ${{ inputs.working-directory }}
- name: Cache go modules
uses: actions/cache@v4
with:
path: .gomodcache
key: go-modcache-${{ inputs.working-directory }}-${{ inputs.go-version }}-${{ hashFiles(steps.go-env.outputs.GOMOD) }}
restore-keys: |
go-modcache-${{ inputs.working-directory }}-${{ inputs.go-version }}-
go-modcache-${{ inputs.working-directory }}-
enableCrossOsArchive: true
- name: Cache go build cache
uses: actions/cache@v4
with:
path: ${{ steps.go-env.outputs.GOCACHE }}
key: go-cache-${{ inputs.working-directory }}-${{ inputs.runs-on }}-${{ inputs.go-version }}-${{ hashFiles(steps.go-env.outputs.GOSUM) }}
restore-keys: |
go-cache-${{ inputs.working-directory }}-${{ inputs.runs-on }}-${{ inputs.go-version }}-
go-cache-${{ inputs.working-directory }}-${{ inputs.runs-on }}-
go-cache-${{ inputs.working-directory }}-
- name: Download dependencies
run: go mod download -x
shell: bash
working-directory: ${{ inputs.working-directory }}
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
- id: setup-go
uses: actions/setup-go@v5
with:
cache: false
go-version: ${{ inputs.go-version }}
- uses: ./.github/actions/setup_cache_for_go
with:
go-version: ${{ steps.setup-go.outputs.go-version }}
runs-on: ${{ inputs.runs-on }}
- name: Make
run: make
- name: Make install on Linux
Expand Down
47 changes: 38 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-go@v5
- id: setup-go
uses: actions/setup-go@v5
with:
cache: false
go-version: ${{ matrix.go-version }}
- uses: ./.github/actions/setup_cache_for_go
with:
go-version: ${{ steps.setup-go.outputs.go-version }}
runs-on: ubuntu-24.04
- name: Unit tests
run: go test -v ./...
- name: Make
Expand Down Expand Up @@ -161,9 +167,15 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-go@v5
- id: setup-go
uses: actions/setup-go@v5
with:
cache: false
go-version: 1.23.x
- uses: ./.github/actions/setup_cache_for_go
with:
go-version: ${{ steps.setup-go.outputs.go-version }}
runs-on: macos-12
- name: Unit tests
run: go test -v ./...
- name: Make
Expand Down Expand Up @@ -287,23 +299,34 @@ jobs:
# fetch-depth is set to 0 to let `limactl --version` print semver-ish version
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-go@v5
with:
go-version: 1.23.x
- uses: actions/cache@v4
with:
path: ~/.cache/lima/download
key: ${{ runner.os }}-colima-${{ matrix.colima-version }}
- uses: ./.github/actions/install_lima_from_artifact
with:
artifact: ${{ needs.build-on-ubuntu.outputs.artifact }}
- name: Checkout colima
uses: actions/checkout@v4
with:
repository: abiosoft/colima
ref: ${{ matrix.colima-version }}
path: colima
- id: setup-go
uses: actions/setup-go@v5
with:
cache: false
go-version: 1.23.x
- uses: ./.github/actions/setup_cache_for_go
with:
go-version: ${{ steps.setup-go.outputs.go-version }}
runs-on: macos-12
working-directory: ./colima
- name: Install colima
run: |
git clone https://github.com/abiosoft/colima
cd colima
git checkout ${{ matrix.colima-version }}
make
sudo make install
working-directory: ./colima
- name: Install test dependencies
run: |
sudo apt-get update
Expand Down Expand Up @@ -382,9 +405,15 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
- id: setup-go
uses: actions/setup-go@v5
with:
cache: false
go-version: 1.23.x
- uses: ./.github/actions/setup_cache_for_go
with:
go-version: ${{ steps.setup-go.outputs.go-version }}
runs-on: macos-12
- name: Cache image used by ${{ matrix.oldver }}/examples/ubuntu-lts.yaml
uses: ./.github/actions/setup_cache_for_template
with:
Expand Down

0 comments on commit 7cfcddd

Please sign in to comment.