Skip to content

Commit a540e62

Browse files
authored
ci: improve caching (#7954)
1 parent 4bc4e63 commit a540e62

File tree

5 files changed

+93
-73
lines changed

5 files changed

+93
-73
lines changed

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

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
11
name: "Setup Go"
22
description: |
33
Sets up the Go environment for tests, builds, etc.
4+
inputs:
5+
version:
6+
description: "The Go version to use."
7+
default: "1.20.5"
48
runs:
59
using: "composite"
610
steps:
11+
- name: Cache go toolchain
12+
uses: buildjet/cache@v3
13+
with:
14+
path: |
15+
${{ runner.tool_cache }}/go/${{ inputs.version }}
16+
key: gotoolchain-${{ runner.os }}-${{ inputs.version }}
17+
restore-keys: |
18+
gotoolchain-${{ runner.os }}-
19+
720
- uses: buildjet/setup-go@v4
821
with:
9-
cache: true
10-
go-version: "1.20.5"
22+
# We do our own caching for implementation clarity.
23+
cache: false
24+
go-version: ${{ inputs.version }}
25+
26+
- name: Get cache dirs
27+
shell: bash
28+
run: |
29+
set -x
30+
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
31+
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
32+
33+
# We split up GOMODCACHE from GOCACHE because the latter must be invalidated
34+
# on code change, but the former can be kept.
35+
- name: Cache $GOMODCACHE
36+
uses: buildjet/cache@v3
37+
with:
38+
path: |
39+
${{ env.GOMODCACHE }}
40+
key: gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-${{ github.job }}
41+
restore-keys: |
42+
gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-
43+
gomodcache-${{ runner.os }}-
1144
12-
- name: Cache go
45+
- name: Cache $GOCACHE
1346
uses: buildjet/cache@v3
1447
with:
15-
# ~/go/pkg is the same across operating systems.
1648
path: |
17-
~/go/pkg
18-
~/.cache/go-build
19-
~/AppData/Local/go-build
20-
~/Library/Caches/go-build
49+
${{ env.GOCACHE }}
2150
# Job name must be included in the key for effective
2251
# test cache reuse.
23-
key: go-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
52+
# The key format is intentionally different than GOMODCACHE, because any
53+
# time a Go file changes we invalidate this cache, whereas GOMODCACHE
54+
# is only invalidated when go.sum changes.
55+
key: gocache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
2456
restore-keys: |
25-
go-${{ runner.os }}-${{ github.job }}-
26-
go-${{ runner.os }}-
27-
go-
57+
gocache-${{ runner.os }}-${{ github.job }}-
58+
gocache-${{ runner.os }}-
2859
2960
- name: Install gotestsum
30-
uses: jaxxstorm/action-install-gh-release@v1.10.0
31-
with:
32-
repo: gotestyourself/gotestsum
33-
tag: v1.9.0
61+
shell: bash
62+
run: go install gotest.tools/gotestsum@latest
3463

3564
# It isn't necessary that we ever do this, but it helps
3665
# separate the "setup" from the "run" times.

.github/workflows/ci.yaml

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -100,49 +100,45 @@ jobs:
100100

101101
- uses: ./.github/actions/setup-go
102102

103-
# Check for any typos!
103+
- uses: ./.github/actions/setup-node
104+
105+
- name: Get golangci-lint cache dir
106+
run: |
107+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2
108+
dir=$(golangci-lint cache status | awk '/Dir/ { print $2 }')
109+
echo "LINT_CACHE_DIR=$dir" >> $GITHUB_ENV
110+
111+
- name: golangci-lint cache
112+
uses: buildjet/cache@v3
113+
with:
114+
path: |
115+
${{ env.LINT_CACHE_DIR }}
116+
key: golangci-lint-${{ runner.os }}-${{ hashFiles('**/*.go') }}
117+
restore-keys: |
118+
golangci-lint-${{ runner.os }}-
119+
120+
# Check for any typos
104121
- name: Check for typos
105122
uses: crate-ci/typos@v1.14.12
106123
with:
107124
config: .github/workflows/typos.toml
125+
108126
- name: Fix the typos
109127
if: ${{ failure() }}
110128
run: |
111129
echo "::notice:: you can automatically fix typos from your CLI:
112130
cargo install typos-cli
113131
typos -c .github/workflows/typos.toml -w"
114132
115-
# Check for Go linting errors!
116-
- name: Lint Go
117-
uses: golangci/golangci-lint-action@v3.5.0
118-
with:
119-
version: v1.52.2
120-
121-
- name: Lint shell scripts
122-
uses: ludeeus/action-shellcheck@2.0.0
123-
env:
124-
SHELLCHECK_OPTS: --external-sources
125-
with:
126-
ignore: node_modules
127-
128-
- uses: ./.github/actions/setup-node
129-
- name: Lint TypeScript
130-
run: yarn lint
131-
working-directory: site
132-
133-
# Make sure the Helm chart is linted!
133+
# Needed for helm chart linting
134134
- name: Install helm
135135
uses: azure/setup-helm@v3
136136
with:
137137
version: v3.9.2
138-
- name: Lint Helm chart
139-
run: |
140-
cd helm
141-
make lint
142138

143-
# Ensure AGPL and Enterprise are separated!
144-
- name: Check for AGPL code importing Enterprise...
145-
run: ./scripts/check_enterprise_imports.sh
139+
- name: make lint
140+
run: |
141+
make --output-sync=line -j lint
146142
147143
gen:
148144
timeout-minutes: 8
@@ -158,16 +154,14 @@ jobs:
158154
- name: Install sqlc
159155
run: |
160156
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.17.2/sqlc_1.17.2_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
161-
- name: Install protoc-gen-go
162-
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
163-
- name: Install protoc-gen-go-drpc
164-
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
165-
- name: Install goimports
166-
run: go install golang.org/x/tools/cmd/goimports@latest
167-
- name: Install yq
168-
run: go run github.com/mikefarah/yq/v4@v4.30.6
169-
- name: Install mockgen
170-
run: go install github.com/golang/mock/mockgen@v1.6.0
157+
158+
- name: go install tools
159+
run: |
160+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
161+
go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
162+
go install golang.org/x/tools/cmd/goimports@latest
163+
go install github.com/mikefarah/yq/v4@v4.30.6
164+
go install github.com/golang/mock/mockgen@v1.6.0
171165
172166
- name: Install Protoc
173167
run: |
@@ -189,7 +183,7 @@ jobs:
189183
run: ./scripts/check_unstaged.sh
190184

191185
fmt:
192-
runs-on: ubuntu-latest
186+
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
193187
timeout-minutes: 5
194188
steps:
195189
- name: Checkout
@@ -268,7 +262,7 @@ jobs:
268262
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
269263
270264
- uses: ./.github/actions/upload-datadog
271-
if: always()
265+
if: success() || failure()
272266
with:
273267
api-key: ${{ secrets.DATADOG_API_KEY }}
274268

@@ -315,15 +309,8 @@ jobs:
315309
# so we need to print the test stats to the log.
316310
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
317311
318-
- uses: actions/upload-artifact@v3
319-
if: success() || failure()
320-
with:
321-
name: gotests-postgres.xml
322-
path: ./gotests.xml
323-
retention-days: 30
324-
325312
- uses: ./.github/actions/upload-datadog
326-
if: always()
313+
if: success() || failure()
327314
with:
328315
api-key: ${{ secrets.DATADOG_API_KEY }}
329316

@@ -349,11 +336,6 @@ jobs:
349336

350337
- uses: ./.github/actions/setup-go
351338

352-
- uses: hashicorp/setup-terraform@v2
353-
with:
354-
terraform_version: 1.1.9
355-
terraform_wrapper: false
356-
357339
- name: Run Tests
358340
run: |
359341
gotestsum --junitfile="gotests.xml" -- -race ./...

.golangci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,11 @@ issues:
200200
max-same-issues: 0
201201

202202
run:
203-
concurrency: 4
204203
skip-dirs:
205204
- node_modules
206205
skip-files:
207206
- scripts/rules.go
208-
timeout: 5m
207+
timeout: 10m
209208

210209
# Over time, add more and more linters from
211210
# https://golangci-lint.run/usage/linters/ as the code improves.

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,17 @@ else
402402
endif
403403
.PHONY: fmt/shfmt
404404

405-
lint: lint/shellcheck lint/go
405+
lint: lint/shellcheck lint/go lint/ts lint/helm
406406
.PHONY: lint
407407

408+
lint/ts:
409+
cd site
410+
yarn && yarn lint
411+
.PHONY: lint/ts
412+
408413
lint/go:
409414
./scripts/check_enterprise_imports.sh
415+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2
410416
golangci-lint run
411417
.PHONY: lint/go
412418

@@ -416,6 +422,11 @@ lint/shellcheck: $(SHELL_SRC_FILES)
416422
shellcheck --external-sources $(SHELL_SRC_FILES)
417423
.PHONY: lint/shellcheck
418424

425+
lint/helm:
426+
cd helm
427+
make lint
428+
.PHONY: lint/helm
429+
419430
# all gen targets should be added here and to gen/mark-fresh
420431
gen: \
421432
coderd/database/dump.sql \

enterprise/cli/root_internal_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package cli
33
import (
44
"testing"
55

6-
"github.com/coder/coder/cli"
76
"github.com/stretchr/testify/require"
87

8+
"github.com/coder/coder/cli"
99
"github.com/coder/coder/cli/clibase"
10-
1110
"github.com/coder/coder/cli/clitest"
1211
)
1312

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy