Skip to content

Commit d710cf7

Browse files
committed
Deduplicate actions
1 parent 80269ba commit d710cf7

File tree

3 files changed

+39
-191
lines changed

3 files changed

+39
-191
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: 14 additions & 191 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
@@ -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
@@ -442,34 +341,8 @@ jobs:
442341
cache: false
443342
go-version: ${{ env.CODER_GO_VERSION }}
444343

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 }}-
344+
- uses: ./.github/actions/setup-go
345+
- uses: ./.github/actions/setup-node
473346

474347
- name: Install goimports
475348
run: go install golang.org/x/tools/cmd/goimports@latest
@@ -538,23 +411,7 @@ jobs:
538411
steps:
539412
- uses: actions/checkout@v3
540413

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
414+
- uses: ./.github/actions/setup-node
558415

559416
- run: yarn test:ci --max-workers ${{ steps.cpu-cores.outputs.count }}
560417
working-directory: site
@@ -580,19 +437,8 @@ jobs:
580437
steps:
581438
- uses: actions/checkout@v3
582439

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 }}
440+
- uses: ./.github/actions/setup-node
441+
- uses: ./.github/actions/setup-go
596442

597443
- uses: hashicorp/setup-terraform@v2
598444
with:
@@ -603,24 +449,6 @@ jobs:
603449
with:
604450
node-version: "16.16.0"
605451

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-
624452
- name: Build
625453
run: |
626454
sudo npm install -g prettier
@@ -655,12 +483,7 @@ jobs:
655483
# only get 1 commit on shallow checkout.
656484
fetch-depth: 0
657485

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

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

0 commit comments

Comments
 (0)