Skip to content

Commit 8608245

Browse files
committed
persist go build cache
1 parent 650a48c commit 8608245

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

.github/actions/setup-go/action.yaml

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ inputs:
55
version:
66
description: "The Go version to use."
77
default: "1.24.2"
8+
build-cache-path:
9+
description: "The path to the build cache."
10+
default: ""
11+
required: false
812
runs:
913
using: "composite"
1014
steps:
1115
- name: Setup Go
1216
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
1317
with:
1418
go-version: ${{ inputs.version }}
15-
1619
- name: Install gotestsum
1720
shell: bash
1821
run: go install gotest.tools/gotestsum@latest
@@ -21,4 +24,11 @@ runs:
2124
# separate the "setup" from the "run" times.
2225
- name: go mod download
2326
shell: bash
24-
run: go mod download -x
27+
run: |
28+
export BUILD_CACHE_PATH="${{ inputs.build-cache-path }}"
29+
if [ -n "${BUILD_CACHE_PATH}" ]; then
30+
export ABSOLUTE_PATH="$(realpath ${BUILD_CACHE_PATH})"
31+
mkdir -p "${ABSOLUTE_PATH}"
32+
export GOCACHE="${ABSOLUTE_PATH}"
33+
fi
34+
go mod download -x

.github/actions/test-cache/upload/action.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ inputs:
99
required: true
1010
# This path is defined in testutil/cache.go
1111
default: "~/.cache/coderv2-test"
12+
override-condition:
13+
description: "Override condition"
14+
required: false
15+
default: "false"
1216
runs:
1317
using: "composite"
1418
steps:
1519
- name: Upload test cache
16-
if: ${{ github.ref == 'refs/heads/main' }}
20+
if: ${{ github.ref == 'refs/heads/main' || inputs.override-condition == 'true' }}
1721
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
1822
with:
1923
path: ${{ inputs.cache-path }}

.github/workflows/ci.yaml

+20-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ jobs:
313313
run: ./scripts/check_unstaged.sh
314314

315315
test-go:
316-
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
316+
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'depot-windows-2022-16' || matrix.os }}
317317
needs: changes
318318
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
319319
timeout-minutes: 20
@@ -337,6 +337,8 @@ jobs:
337337

338338
- name: Setup Go
339339
uses: ./.github/actions/setup-go
340+
with:
341+
build-cache-path: ~/.cache/go-build
340342

341343
- name: Setup Terraform
342344
uses: ./.github/actions/setup-tf
@@ -347,6 +349,14 @@ jobs:
347349
with:
348350
key-prefix: test-go-${{ runner.os }}-${{ runner.arch }}
349351

352+
- name: Download Go Build Cache
353+
id: download-go-build-cache
354+
uses: ./.github/actions/test-cache/download
355+
if: runner.os == 'Windows'
356+
with:
357+
key-prefix: test-go-${{ runner.os }}-${{ runner.arch }}-golang
358+
cache-path: "~/.cache/go-build"
359+
350360
- name: Test with Mock Database
351361
id: test
352362
shell: bash
@@ -368,6 +378,7 @@ jobs:
368378
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
369379
fi
370380
export TS_DEBUG_DISCO=true
381+
export GOCACHE="$(realpath ~/.cache/go-build)"
371382
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
372383
--packages="./..." -- $PARALLEL_FLAG -short -failfast
373384
@@ -376,6 +387,14 @@ jobs:
376387
with:
377388
cache-key: ${{ steps.download-cache.outputs.cache-key }}
378389

390+
- name: Upload Go Build Cache
391+
if: runner.os == 'Windows'
392+
uses: ./.github/actions/test-cache/upload
393+
with:
394+
cache-key: ${{ steps.download-go-build-cache.outputs.cache-key }}
395+
cache-path: "~/.cache/go-build"
396+
override-condition: "true"
397+
379398
- name: Upload test stats to Datadog
380399
timeout-minutes: 1
381400
continue-on-error: true

0 commit comments

Comments
 (0)