Skip to content

Commit 7781388

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

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

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

+26-4
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,42 @@ 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
12+
cache:
13+
description: "Whether to cache the build cache."
14+
default: "true"
815
runs:
916
using: "composite"
1017
steps:
1118
- name: Setup Go
1219
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
1320
with:
1421
go-version: ${{ inputs.version }}
15-
16-
- name: Install gotestsum
22+
cache: ${{ inputs.cache }}
23+
- name: Install gotestsum and mtimehash
1724
shell: bash
18-
run: go install gotest.tools/gotestsum@latest
25+
run: |
26+
export BUILD_CACHE_PATH=${{ inputs.build-cache-path }}
27+
if [ -n "${BUILD_CACHE_PATH}" ]; then
28+
mkdir -p "${BUILD_CACHE_PATH}"
29+
export GOCACHE="${BUILD_CACHE_PATH}/build"
30+
export GOMODCACHE="${BUILD_CACHE_PATH}/mod"
31+
fi
32+
go install gotest.tools/gotestsum@latest
33+
go install github.com/slsyy/mtimehash/cmd/mtimehash@latest
1934
2035
# It isn't necessary that we ever do this, but it helps
2136
# separate the "setup" from the "run" times.
2237
- name: go mod download
2338
shell: bash
24-
run: go mod download -x
39+
run: |
40+
export BUILD_CACHE_PATH=${{ inputs.build-cache-path }}
41+
if [ -n "${BUILD_CACHE_PATH}" ]; then
42+
mkdir -p "${BUILD_CACHE_PATH}"
43+
export GOCACHE="${BUILD_CACHE_PATH}/build"
44+
export GOMODCACHE="${BUILD_CACHE_PATH}/mod"
45+
fi
46+
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

+29-3
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
@@ -335,8 +335,25 @@ jobs:
335335
with:
336336
fetch-depth: 1
337337

338+
- name: Download Go Build Cache
339+
id: download-go-build-cache
340+
uses: ./.github/actions/test-cache/download
341+
if: runner.os == 'Windows'
342+
with:
343+
key-prefix: test-go-build-10-${{ runner.os }}-${{ runner.arch }}
344+
cache-path: "~/.cache/go-cache"
345+
338346
- name: Setup Go
339347
uses: ./.github/actions/setup-go
348+
with:
349+
build-cache-path: ~/.cache/go-cache
350+
cache: false
351+
352+
- name: Normalize File and Directory Timestamps
353+
shell: bash
354+
run: |
355+
find . -type f ! -path ./.git/\*\* | mtimehash
356+
find . -type d ! -path ./.git/\*\* -exec touch -t 200601010000 {} +
340357
341358
- name: Setup Terraform
342359
uses: ./.github/actions/setup-tf
@@ -368,14 +385,23 @@ jobs:
368385
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
369386
fi
370387
export TS_DEBUG_DISCO=true
371-
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
372-
--packages="./..." -- $PARALLEL_FLAG -short -failfast
388+
export GOCACHE=~/.cache/go-cache/build
389+
export GOMODCACHE=~/.cache/go-cache/mod
390+
go test -failfast -short ./...
373391
374392
- name: Upload Test Cache
375393
uses: ./.github/actions/test-cache/upload
376394
with:
377395
cache-key: ${{ steps.download-cache.outputs.cache-key }}
378396

397+
- name: Upload Go Build Cache
398+
if: runner.os == 'Windows'
399+
uses: ./.github/actions/test-cache/upload
400+
with:
401+
cache-key: ${{ steps.download-go-build-cache.outputs.cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
402+
cache-path: "~/.cache/go-cache"
403+
override-condition: "true"
404+
379405
- name: Upload test stats to Datadog
380406
timeout-minutes: 1
381407
continue-on-error: true

cli/gitssh_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ func TestGitSSH(t *testing.T) {
117117
t.Run("Dial", func(t *testing.T) {
118118
t.Parallel()
119119

120+
fmt.Println("Dial")
121+
120122
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
121123
defer cancel()
122124

0 commit comments

Comments
 (0)