Skip to content

ci: deduplicate language setup #7753

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

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/actions/setup-go/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Setup Go"
description: |
Sets up the Go environment for tests, builds, etc.
runs:
using: "composite"
steps:
- uses: buildjet/setup-go@v4
with:
cache: true
go-version: "~1.20"
15 changes: 15 additions & 0 deletions .github/actions/setup-node/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Setup Node"
description: |
Sets up the node environment for tests, builds, etc.
runs:
using: "composite"
steps:
- uses: buildjet/setup-node@v3
with:
node-version: 16.16.0
# See https://github.com/actions/setup-node#caching-global-packages-data
cache: "yarn"
cache-dependency-path: "site/yarn.lock"
- name: Install node_modules
shell: bash
run: ./scripts/yarn_install.sh
224 changes: 32 additions & 192 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
CODER_GO_VERSION: "~1.20"

jobs:
lint:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
steps:
- name: Checkout
uses: actions/checkout@v3

# Install Go!
- uses: buildjet/setup-go@v4
with:
go-version: ${{ env.CODER_GO_VERSION }}
cache: true
- uses: ./.github/actions/setup-go

# Check for any typos!
- name: Check for typos
Expand All @@ -67,19 +60,7 @@ jobs:
with:
ignore: node_modules

# Lint our dashboard!
- name: Cache node_modules
id: cache-node
uses: buildjet/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- name: Install node_modules
run: ./scripts/yarn_install.sh
- uses: ./.github/actions/setup-node
- name: Lint TypeScript
run: yarn lint
working-directory: site
Expand Down Expand Up @@ -139,42 +120,8 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Cache Node
id: cache-node
uses: buildjet/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-

- name: Install node_modules
run: ./scripts/yarn_install.sh

- uses: buildjet/setup-go@v4
with:
cache: false
go-version: ${{ env.CODER_GO_VERSION }}

- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT

- name: Go Build Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
key: ${{ github.job }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}

- name: Go Mod Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
key: ${{ github.job }}-go-mod-${{ hashFiles('**/go.sum') }}
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/setup-go

- name: Install sqlc
run: |
Expand Down Expand Up @@ -219,19 +166,8 @@ jobs:
fetch-depth: 0
submodules: true

- name: Cache Node
id: cache-node
uses: buildjet/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-

- name: Install node_modules
run: ./scripts/yarn_install.sh
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/setup-go

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

- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT
echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT

- name: Go Build Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}

- name: Go Mod Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- uses: ./.github/actions/setup-go

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

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

- uses: buildjet/setup-go@v4
with:
cache: false
go-version: ${{ env.CODER_GO_VERSION }}

- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT

- name: Go Build Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}

- name: Go Mod Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- uses: ./.github/actions/setup-go

- name: Install gotestsum
uses: jaxxstorm/action-install-gh-release@v1.10.0
Expand Down Expand Up @@ -412,6 +311,23 @@ jobs:
files: ./gotests.coverage
flags: unittest-go-postgres-linux

test-go-race:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
timeout-minutes: 25
steps:
- uses: actions/checkout@v3

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

- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.1.9
terraform_wrapper: false

- name: Run Tests
run: |
go test -race ./...

deploy:
name: "deploy"
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
Expand Down Expand Up @@ -442,34 +358,8 @@ jobs:
cache: false
go-version: ${{ env.CODER_GO_VERSION }}

- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT

- name: Go Build Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
key: ${{ runner.os }}-release-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}

- name: Cache Node
id: cache-node
uses: buildjet/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-release-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-node

- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
Expand Down Expand Up @@ -538,23 +428,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Cache Node
id: cache-node
uses: buildjet/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-

- uses: buildjet/setup-node@v3
with:
node-version: "16.16.0"

- name: Install node_modules
run: ./scripts/yarn_install.sh
- uses: ./.github/actions/setup-node

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

- name: Cache Node
id: cache-node
uses: buildjet/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-e2e-${{ hashFiles('**/yarn.lock') }}

- uses: buildjet/setup-go@v4
with:
cache: false
go-version: ${{ env.CODER_GO_VERSION }}
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/setup-go

- uses: hashicorp/setup-terraform@v2
with:
Expand All @@ -603,24 +466,6 @@ jobs:
with:
node-version: "16.16.0"

- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT

- name: Go Build Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: buildjet/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

- name: Build
run: |
sudo npm install -g prettier
Expand Down Expand Up @@ -655,12 +500,7 @@ jobs:
# only get 1 commit on shallow checkout.
fetch-depth: 0

- uses: buildjet/setup-node@v3
with:
node-version: "16.16.0"

- name: Install dependencies
run: cd site && yarn
- uses: ./.github/actions/setup-node

# This step is not meant for mainline because any detected changes to
# storybook snapshots will require manual approval/review in order for
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ test-postgres: test-clean test-postgres-docker
--packages="./..." -- \
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
-coverpkg=./... \
-race -failfast
-failfast
.PHONY: test-postgres

test-postgres-docker:
Expand Down