Skip to content

Commit 555ea64

Browse files
authored
ci: deduplicate language setup (#7753)
* Deduplicate actions * Split up go-race and go-pg
1 parent 80269ba commit 555ea64

File tree

4 files changed

+58
-193
lines changed

4 files changed

+58
-193
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "Setup Go"
2+
description: |
3+
Sets up the Go environment for tests, builds, etc.
4+
runs:
5+
using: "composite"
6+
steps:
7+
- uses: buildjet/setup-go@v4
8+
with:
9+
cache: true
10+
go-version: "~1.20"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "Setup Node"
2+
description: |
3+
Sets up the node environment for tests, builds, etc.
4+
runs:
5+
using: "composite"
6+
steps:
7+
- uses: buildjet/setup-node@v3
8+
with:
9+
node-version: 16.16.0
10+
# See https://github.com/actions/setup-node#caching-global-packages-data
11+
cache: "yarn"
12+
cache-dependency-path: "site/yarn.lock"
13+
- name: Install node_modules
14+
shell: bash
15+
run: ./scripts/yarn_install.sh

.github/workflows/ci.yaml

Lines changed: 32 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@ concurrency:
2626
group: ${{ github.workflow }}-${{ github.ref }}
2727
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2828

29-
env:
30-
CODER_GO_VERSION: "~1.20"
31-
3229
jobs:
3330
lint:
3431
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
3532
steps:
3633
- name: Checkout
3734
uses: actions/checkout@v3
3835

39-
# Install Go!
40-
- uses: buildjet/setup-go@v4
41-
with:
42-
go-version: ${{ env.CODER_GO_VERSION }}
43-
cache: true
36+
- uses: ./.github/actions/setup-go
4437

4538
# Check for any typos!
4639
- name: Check for typos
@@ -67,19 +60,7 @@ jobs:
6760
with:
6861
ignore: node_modules
6962

70-
# Lint our dashboard!
71-
- name: Cache node_modules
72-
id: cache-node
73-
uses: buildjet/cache@v3
74-
with:
75-
path: |
76-
**/node_modules
77-
.eslintcache
78-
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
79-
restore-keys: |
80-
js-${{ runner.os }}-
81-
- name: Install node_modules
82-
run: ./scripts/yarn_install.sh
63+
- uses: ./.github/actions/setup-node
8364
- name: Lint TypeScript
8465
run: yarn lint
8566
working-directory: site
@@ -139,42 +120,8 @@ jobs:
139120
steps:
140121
- uses: actions/checkout@v3
141122

142-
- name: Cache Node
143-
id: cache-node
144-
uses: buildjet/cache@v3
145-
with:
146-
path: |
147-
**/node_modules
148-
.eslintcache
149-
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
150-
restore-keys: |
151-
js-${{ runner.os }}-
152-
153-
- name: Install node_modules
154-
run: ./scripts/yarn_install.sh
155-
156-
- uses: buildjet/setup-go@v4
157-
with:
158-
cache: false
159-
go-version: ${{ env.CODER_GO_VERSION }}
160-
161-
- name: Echo Go Cache Paths
162-
id: go-cache-paths
163-
run: |
164-
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
165-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
166-
167-
- name: Go Build Cache
168-
uses: buildjet/cache@v3
169-
with:
170-
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
171-
key: ${{ github.job }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
172-
173-
- name: Go Mod Cache
174-
uses: buildjet/cache@v3
175-
with:
176-
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
177-
key: ${{ github.job }}-go-mod-${{ hashFiles('**/go.sum') }}
123+
- uses: ./.github/actions/setup-node
124+
- uses: ./.github/actions/setup-go
178125

179126
- name: Install sqlc
180127
run: |
@@ -219,19 +166,8 @@ jobs:
219166
fetch-depth: 0
220167
submodules: true
221168

222-
- name: Cache Node
223-
id: cache-node
224-
uses: buildjet/cache@v3
225-
with:
226-
path: |
227-
**/node_modules
228-
.eslintcache
229-
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
230-
restore-keys: |
231-
js-${{ runner.os }}-
232-
233-
- name: Install node_modules
234-
run: ./scripts/yarn_install.sh
169+
- uses: ./.github/actions/setup-node
170+
- uses: ./.github/actions/setup-go
235171

236172
- name: Install shfmt
237173
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.5.0
@@ -261,23 +197,7 @@ jobs:
261197
cache: false
262198
go-version: ${{ env.CODER_GO_VERSION }}
263199

264-
- name: Echo Go Cache Paths
265-
id: go-cache-paths
266-
run: |
267-
echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT
268-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT
269-
270-
- name: Go Build Cache
271-
uses: buildjet/cache@v3
272-
with:
273-
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
274-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
275-
276-
- name: Go Mod Cache
277-
uses: buildjet/cache@v3
278-
with:
279-
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
280-
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
200+
- uses: ./.github/actions/setup-go
281201

282202
- name: Install gotestsum
283203
uses: jaxxstorm/action-install-gh-release@v1.10.0
@@ -335,7 +255,7 @@ jobs:
335255
files: ./gotests.coverage
336256
flags: unittest-go-${{ matrix.os }}
337257

338-
test-go-psql:
258+
test-go-pg:
339259
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
340260
# This timeout must be greater than the timeout set by `go test` in
341261
# `make test-postgres` to ensure we receive a trace of running
@@ -345,28 +265,7 @@ jobs:
345265
steps:
346266
- uses: actions/checkout@v3
347267

348-
- uses: buildjet/setup-go@v4
349-
with:
350-
cache: false
351-
go-version: ${{ env.CODER_GO_VERSION }}
352-
353-
- name: Echo Go Cache Paths
354-
id: go-cache-paths
355-
run: |
356-
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
357-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
358-
359-
- name: Go Build Cache
360-
uses: buildjet/cache@v3
361-
with:
362-
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
363-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
364-
365-
- name: Go Mod Cache
366-
uses: buildjet/cache@v3
367-
with:
368-
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
369-
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
268+
- uses: ./.github/actions/setup-go
370269

371270
- name: Install gotestsum
372271
uses: jaxxstorm/action-install-gh-release@v1.10.0
@@ -412,6 +311,23 @@ jobs:
412311
files: ./gotests.coverage
413312
flags: unittest-go-postgres-linux
414313

314+
test-go-race:
315+
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
316+
timeout-minutes: 25
317+
steps:
318+
- uses: actions/checkout@v3
319+
320+
- uses: ./.github/actions/setup-go
321+
322+
- uses: hashicorp/setup-terraform@v2
323+
with:
324+
terraform_version: 1.1.9
325+
terraform_wrapper: false
326+
327+
- name: Run Tests
328+
run: |
329+
go test -race ./...
330+
415331
deploy:
416332
name: "deploy"
417333
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
@@ -442,34 +358,8 @@ jobs:
442358
cache: false
443359
go-version: ${{ env.CODER_GO_VERSION }}
444360

445-
- name: Echo Go Cache Paths
446-
id: go-cache-paths
447-
run: |
448-
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
449-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
450-
451-
- name: Go Build Cache
452-
uses: buildjet/cache@v3
453-
with:
454-
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
455-
key: ${{ runner.os }}-release-go-build-${{ hashFiles('**/go.sum') }}
456-
457-
- name: Go Mod Cache
458-
uses: buildjet/cache@v3
459-
with:
460-
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
461-
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}
462-
463-
- name: Cache Node
464-
id: cache-node
465-
uses: buildjet/cache@v3
466-
with:
467-
path: |
468-
**/node_modules
469-
.eslintcache
470-
key: js-${{ runner.os }}-release-node-${{ hashFiles('**/yarn.lock') }}
471-
restore-keys: |
472-
js-${{ runner.os }}-
361+
- uses: ./.github/actions/setup-go
362+
- uses: ./.github/actions/setup-node
473363

474364
- name: Install goimports
475365
run: go install golang.org/x/tools/cmd/goimports@latest
@@ -538,23 +428,7 @@ jobs:
538428
steps:
539429
- uses: actions/checkout@v3
540430

541-
- name: Cache Node
542-
id: cache-node
543-
uses: buildjet/cache@v3
544-
with:
545-
path: |
546-
**/node_modules
547-
.eslintcache
548-
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
549-
restore-keys: |
550-
js-${{ runner.os }}-
551-
552-
- uses: buildjet/setup-node@v3
553-
with:
554-
node-version: "16.16.0"
555-
556-
- name: Install node_modules
557-
run: ./scripts/yarn_install.sh
431+
- uses: ./.github/actions/setup-node
558432

559433
- run: yarn test:ci --max-workers ${{ steps.cpu-cores.outputs.count }}
560434
working-directory: site
@@ -580,19 +454,8 @@ jobs:
580454
steps:
581455
- uses: actions/checkout@v3
582456

583-
- name: Cache Node
584-
id: cache-node
585-
uses: buildjet/cache@v3
586-
with:
587-
path: |
588-
**/node_modules
589-
.eslintcache
590-
key: js-${{ runner.os }}-e2e-${{ hashFiles('**/yarn.lock') }}
591-
592-
- uses: buildjet/setup-go@v4
593-
with:
594-
cache: false
595-
go-version: ${{ env.CODER_GO_VERSION }}
457+
- uses: ./.github/actions/setup-node
458+
- uses: ./.github/actions/setup-go
596459

597460
- uses: hashicorp/setup-terraform@v2
598461
with:
@@ -603,24 +466,6 @@ jobs:
603466
with:
604467
node-version: "16.16.0"
605468

606-
- name: Echo Go Cache Paths
607-
id: go-cache-paths
608-
run: |
609-
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
610-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
611-
612-
- name: Go Build Cache
613-
uses: buildjet/cache@v3
614-
with:
615-
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
616-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
617-
618-
- name: Go Mod Cache
619-
uses: buildjet/cache@v3
620-
with:
621-
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
622-
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
623-
624469
- name: Build
625470
run: |
626471
sudo npm install -g prettier
@@ -655,12 +500,7 @@ jobs:
655500
# only get 1 commit on shallow checkout.
656501
fetch-depth: 0
657502

658-
- uses: buildjet/setup-node@v3
659-
with:
660-
node-version: "16.16.0"
661-
662-
- name: Install dependencies
663-
run: cd site && yarn
503+
- uses: ./.github/actions/setup-node
664504

665505
# This step is not meant for mainline because any detected changes to
666506
# storybook snapshots will require manual approval/review in order for

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ test-postgres: test-clean test-postgres-docker
615615
--packages="./..." -- \
616616
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
617617
-coverpkg=./... \
618-
-race -failfast
618+
-failfast
619619
.PHONY: test-postgres
620620

621621
test-postgres-docker:

0 commit comments

Comments
 (0)