Skip to content

Commit 67fedd4

Browse files
build: "Quick Checks" avoid repeating Install Go
This factors out the "Install Go" step into a separate composite action which we can then call from both of the jobs that need it. We can't factor out the "Cache Go Modules" because GitHub doesn't allow composite actions to refer to other external actions.
1 parent 9210ce6 commit 67fedd4

2 files changed

Lines changed: 53 additions & 26 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: 'Set Up Go Toolchain'
2+
description: 'Installs the Go toolchain specified in .go-version.'
3+
outputs:
4+
go-version:
5+
description: "Go toolchain version"
6+
value: ${{ steps.go.outputs.go-version }}
7+
gopath:
8+
description: "GOPATH location"
9+
value: ${{ steps.go.outputs.gopath }}
10+
goenv:
11+
description: "Path to the 'goenv' executable"
12+
value: ${{ steps.go.outputs.goenv }}
13+
goenv-bin-dir:
14+
description: "Path to the directory containing the 'goenv' executable"
15+
value: ${{ steps.go.outputs.goenv-bin-dir }}
16+
go:
17+
description: "Path to the 'go' executable"
18+
value: ${{ steps.go.outputs.go }}
19+
runs:
20+
using: "composite"
21+
steps:
22+
# We use goenv to make sure we're always using the same Go version we'd
23+
# use for releases, as recorded in the .go-version file.
24+
- name: "Install Go"
25+
id: go
26+
shell: bash
27+
run: |
28+
git clone https://github.com/syndbg/goenv.git ~/.goenv
29+
# "install" makes sure we have the .go-version-selected toolchain
30+
# available in goenv's repository of toolchains.
31+
# (this creates ~/.goenv/versions/VERSION/... to serve as GOROOT)
32+
~/.goenv/bin/goenv install
33+
# "rehash" generates the wrapper scripts that goenv uses to
34+
# select the correct executables for the selected toolchain.
35+
# (this is what creates the ~/.goenv/shims/go we refer to below)
36+
~/.goenv/bin/goenv rehash
37+
echo "::set-output name=go-version::$(~/.goenv/bin/goenv version-name)"
38+
echo "::set-output name=gopath::$HOME/go/$(~/.goenv/bin/goenv version-name)"
39+
echo "::set-output name=goenv::$HOME/.goenv/bin/goenv"
40+
echo "::set-output name=goenv-bin-dir::$HOME/.goenv/bin"
41+
echo "::set-output name=go::$HOME/.goenv/shims/go"

‎.github/workflows/checks.yml‎

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,31 @@ jobs:
3333
- name: "Fetch source code"
3434
uses: actions/checkout@v2
3535

36-
# For our Go tests in particular we use goenv to make sure we're always
37-
# using the same Go version we'd use for releases, as recorded in the
38-
# .go-version file.
3936
- name: "Install Go"
4037
id: go
41-
run: |
42-
git clone https://github.com/syndbg/goenv.git ~/.goenv
43-
~/.goenv/bin/goenv install
44-
~/.goenv/bin/goenv rehash
45-
echo "::set-output name=go-version::$(~/.goenv/bin/goenv version-name)"
38+
uses: ./.github/actions/go-setup
4639

47-
# Note: this cache is shared with the "e2e-tests" job, so must always
48-
# have identical configuration its corresponding step.
40+
# NOTE: This cache is shared with the e2e-tests job, so the corresponding
41+
# step in that job must always be identical to this one.
4942
- name: Cache Go modules
5043
uses: actions/cache@v3
5144
with:
52-
path: "~/go/${{steps.go.outputs.go-version}}/pkg"
45+
path: "${{steps.go.outputs.gopath}}/pkg"
5346
key: go-mod-${{ hashFiles('go.sum') }}
5447
restore-keys: |
5548
go-mod-
5649
5750
- name: "go.mod and go.sum consistency check"
5851
run: |
59-
~/.goenv/shims/go mod tidy
52+
"${{steps.go.outputs.go}}" mod tidy
6053
if [[ -n "$(git status --porcelain)" ]]; then
6154
echo "go.mod/go.sum are not up-to-date. Run 'go mod tidy' and then commit the updated files."
6255
exit 1
6356
fi
6457
6558
- name: "Unit tests"
6659
run: |
67-
~/.goenv/shims/go test ./...
60+
"${{steps.go.outputs.go}}" test ./...
6861
6962
# We'll also deal with some general consistency/lint/style checks
7063
# here just because they are relatively fast and so not worth running
@@ -75,7 +68,7 @@ jobs:
7568
# We do need to fully init goenv in this one case because we're
7669
# going to run Go indirectly via make and some shell scripts, so
7770
# we need PATH set up correctly.
78-
export PATH=~/.goenv/bin:$PATH
71+
export PATH="${{steps.go.outputs.goenv-bin-dir}}":$PATH
7972
eval "$(goenv init -)"
8073
go version
8174
make fmtcheck generate staticcheck exhaustive protobuf
@@ -97,27 +90,20 @@ jobs:
9790
- name: "Fetch source code"
9891
uses: actions/checkout@v2
9992

100-
# For our Go tests in particular we use goenv to make sure we're always
101-
# using the same Go version we'd use for releases, as recorded in the
102-
# .go-version file.
10393
- name: "Install Go"
10494
id: go
105-
run: |
106-
git clone https://github.com/syndbg/goenv.git ~/.goenv
107-
~/.goenv/bin/goenv install
108-
~/.goenv/bin/goenv rehash
109-
echo "::set-output name=go-version::$(~/.goenv/bin/goenv version-name)"
95+
uses: ./.github/actions/go-setup
11096

111-
# Note: this cache is shared with the "unit-tests" job, so must always
112-
# have identical configuration its corresponding step.
97+
# NOTE: This cache is shared with the e2e-tests job, so the corresponding
98+
# step in that job must always be identical to this one.
11399
- name: Cache Go modules
114100
uses: actions/cache@v3
115101
with:
116-
path: "~/go/${{steps.go.outputs.go-version}}/pkg"
102+
path: "${{steps.go.outputs.gopath}}/pkg"
117103
key: go-mod-${{ hashFiles('go.sum') }}
118104
restore-keys: |
119105
go-mod-
120106
121107
- name: "End-to-end tests"
122108
run: |
123-
TF_ACC=1 ~/.goenv/shims/go test -v ./internal/command/e2etest
109+
TF_ACC=1 "${{steps.go.outputs.go}}" test -v ./internal/command/e2etest

0 commit comments

Comments
 (0)