-
Notifications
You must be signed in to change notification settings - Fork 891
ci: improve Go caching #7954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: improve Go caching #7954
Changes from all commits
a26fd50
0c2c580
d2909e8
ece4e2a
2eeb2ae
1004b9a
9f90b78
1c36a07
de837ce
f8df5c9
901853b
06f7168
0b26856
2cb7884
fe09085
cc87000
2c7208a
9676000
0453d7e
9865c38
45aaa1e
82320d5
eb6a3ed
39c1fe5
1ebc06e
6fcd675
18a4011
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,65 @@ | ||
name: "Setup Go" | ||
description: | | ||
Sets up the Go environment for tests, builds, etc. | ||
inputs: | ||
version: | ||
description: "The Go version to use." | ||
default: "1.20.5" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Cache go toolchain | ||
uses: buildjet/cache@v3 | ||
with: | ||
path: | | ||
${{ runner.tool_cache }}/go/${{ inputs.version }} | ||
key: gotoolchain-${{ runner.os }}-${{ inputs.version }} | ||
restore-keys: | | ||
gotoolchain-${{ runner.os }}- | ||
|
||
- uses: buildjet/setup-go@v4 | ||
with: | ||
cache: true | ||
go-version: "1.20.5" | ||
# We do our own caching for implementation clarity. | ||
cache: false | ||
go-version: ${{ inputs.version }} | ||
|
||
- name: Get cache dirs | ||
shell: bash | ||
run: | | ||
set -x | ||
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV | ||
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV | ||
|
||
# We split up GOMODCACHE from GOCACHE because the latter must be invalidated | ||
# on code change, but the former can be kept. | ||
- name: Cache $GOMODCACHE | ||
uses: buildjet/cache@v3 | ||
with: | ||
path: | | ||
${{ env.GOMODCACHE }} | ||
key: gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-${{ github.job }} | ||
restore-keys: | | ||
gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GOCACHE also has the github.job one listed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment that may help this make more sense |
||
gomodcache-${{ runner.os }}- | ||
|
||
- name: Cache go | ||
- name: Cache $GOCACHE | ||
uses: buildjet/cache@v3 | ||
with: | ||
# ~/go/pkg is the same across operating systems. | ||
path: | | ||
~/go/pkg | ||
~/.cache/go-build | ||
~/AppData/Local/go-build | ||
~/Library/Caches/go-build | ||
${{ env.GOCACHE }} | ||
# Job name must be included in the key for effective | ||
# test cache reuse. | ||
key: go-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }} | ||
# The key format is intentionally different than GOMODCACHE, because any | ||
# time a Go file changes we invalidate this cache, whereas GOMODCACHE | ||
# is only invalidated when go.sum changes. | ||
key: gocache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }} | ||
restore-keys: | | ||
go-${{ runner.os }}-${{ github.job }}- | ||
go-${{ runner.os }}- | ||
go- | ||
gocache-${{ runner.os }}-${{ github.job }}- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hyphen at the end? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was on purpose. It's how I've seen it done on a few docs. I guess it clearly symbolizes the end of a token. |
||
gocache-${{ runner.os }}- | ||
|
||
- name: Install gotestsum | ||
uses: jaxxstorm/action-install-gh-release@v1.10.0 | ||
with: | ||
repo: gotestyourself/gotestsum | ||
tag: v1.9.0 | ||
shell: bash | ||
run: go install gotest.tools/gotestsum@latest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not work on Windows AFAIK There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? |
||
|
||
# It isn't necessary that we ever do this, but it helps | ||
# separate the "setup" from the "run" times. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,11 +402,17 @@ else | |
endif | ||
.PHONY: fmt/shfmt | ||
|
||
lint: lint/shellcheck lint/go | ||
lint: lint/shellcheck lint/go lint/ts lint/helm | ||
.PHONY: lint | ||
|
||
lint/ts: | ||
cd site | ||
yarn && yarn lint | ||
.PHONY: lint/ts | ||
|
||
lint/go: | ||
./scripts/check_enterprise_imports.sh | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be skipped if golangci-lint is in PATH? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do it though? It runs almost instantly if already installed. |
||
golangci-lint run | ||
.PHONY: lint/go | ||
|
||
|
@@ -416,6 +422,11 @@ lint/shellcheck: $(SHELL_SRC_FILES) | |
shellcheck --external-sources $(SHELL_SRC_FILES) | ||
.PHONY: lint/shellcheck | ||
|
||
lint/helm: | ||
cd helm | ||
make lint | ||
.PHONY: lint/helm | ||
|
||
# all gen targets should be added here and to gen/mark-fresh | ||
gen: \ | ||
coderd/database/dump.sql \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work on Windows runners
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh?