Skip to content

Commit f0368ff

Browse files
ammariopull[bot]
authored andcommitted
ci: improve caching (#7943)
1 parent b649bfc commit f0368ff

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,32 @@ runs:
88
with:
99
cache: true
1010
go-version: "1.20.5"
11+
12+
- name: Cache go
13+
uses: buildjet/cache@v3
14+
with:
15+
# ~/go/pkg is the same across operating systems.
16+
path: |
17+
~/go/pkg
18+
~/.cache/go-build
19+
~/AppData/Local/go-build
20+
~/Library/Caches/go-build
21+
# Job name must be included in the key for effective
22+
# test cache reuse.
23+
key: go-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
24+
restore-keys: |
25+
go-${{ runner.os }}-${{ github.job }}-
26+
go-${{ runner.os }}-
27+
go-
28+
1129
- name: Install gotestsum
1230
uses: jaxxstorm/action-install-gh-release@v1.10.0
1331
with:
1432
repo: gotestyourself/gotestsum
1533
tag: v1.9.0
34+
35+
# It isn't necessary that we ever do this, but it helps
36+
# separate the "setup" from the "run" times.
37+
- name: go mod download
38+
shell: bash
39+
run: go mod download -x

.github/workflows/ci.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,18 @@ jobs:
218218
echo "cover=false" >> $GITHUB_OUTPUT
219219
fi
220220
221+
# By default Go will use the number of logical CPUs, which
222+
# is a fine default.
223+
PARALLEL_FLAG=""
224+
if [ "${{ matrix.os }}" == "windows-2019" ]; then
225+
# Windows appears more I/O bound, so we increase parallelism
226+
# to make better use of CPU.
227+
PARALLEL_FLAG="-parallel=16"
228+
fi
229+
221230
export TS_DEBUG_DISCO=true
222-
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" --packages="./..." -- -parallel=8 -timeout=7m -short -failfast $COVERAGE_FLAGS
231+
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
232+
--packages="./..." -- $PARALLEL_FLAG -short -failfast $COVERAGE_FLAGS
223233
224234
- name: Print test stats
225235
if: success() || failure()
@@ -228,13 +238,6 @@ jobs:
228238
# so we need to print the test stats to the log.
229239
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
230240
231-
- uses: actions/upload-artifact@v3
232-
if: success() || failure()
233-
with:
234-
name: gotests-${{ matrix.os }}.xml
235-
path: ./gotests.xml
236-
retention-days: 30
237-
238241
- uses: ./.github/actions/upload-datadog
239242
if: always()
240243
with:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,15 @@ test: test-clean
610610

611611
# When updating -timeout for this test, keep in sync with
612612
# test-go-postgres (.github/workflows/coder.yaml).
613+
# Do add coverage flags so that test caching works.
613614
test-postgres: test-clean test-postgres-docker
614615
# The postgres test is prone to failure, so we limit parallelism for
615616
# more consistent execution.
616617
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum \
617618
--junitfile="gotests.xml" \
618619
--jsonfile="gotests.json" \
619620
--packages="./..." -- \
620-
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
621-
-coverpkg=./... \
621+
-timeout=20m \
622622
-failfast
623623
.PHONY: test-postgres
624624

0 commit comments

Comments
 (0)