Skip to content

ci: skip ts or go tests based on changed files #7134

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 15 commits into from
Jun 9, 2023
146 changes: 91 additions & 55 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,71 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
changes:
runs-on: ubuntu-latest
outputs:
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
go: ${{ steps.filter.outputs.go }}
ts: ${{ steps.filter.outputs.ts }}
k8s: ${{ steps.filter.outputs.k8s }}
ci: ${{ steps.filter.outputs.ci }}
steps:
- uses: actions/checkout@v3
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
all:
- "**"
docs:
- "docs/**"
- "README.md"
# For testing:
# - ".github/**"
go:
- "**.sql"
- "**.go"
- "**.golden"
- "go.mod"
- "go.sum"
# Other non-Go files that may affect Go code:
- "**.rego"
- "**.sh"
- "**.tpl"
- "**.gotmpl"
- "**.gotpl"
- "Makefile"
- "site/static/error.html"
# Main repo directories for completeness in case other files are
# touched:
- "agent/**"
- "cli/**"
- "cmd/**"
- "coderd/**"
- "enterprise/**"
- "examples/**"
- "provisioner/**"
- "provisionerd/**"
- "provisionersdk/**"
- "pty/**"
- "scaletest/**"
- "tailnet/**"
- "testutil/**"
ts:
- "site/**"
- "Makefile"
k8s:
- "helm/**"
- "scripts/Dockerfile"
- "scripts/Dockerfile.base"
- "scripts/helm.sh"
ci:
- ".github/**"
- id: debug
run: |
echo "${{ toJSON(steps.filter )}}"

lint:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
steps:
Expand Down Expand Up @@ -79,44 +144,11 @@ jobs:
- name: Check for AGPL code importing Enterprise...
run: ./scripts/check_enterprise_imports.sh

changes:
runs-on: ubuntu-latest
outputs:
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
sh: ${{ steps.filter.outputs.sh }}
ts: ${{ steps.filter.outputs.ts }}
k8s: ${{ steps.filter.outputs.k8s }}
steps:
- uses: actions/checkout@v3
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
all:
- '**'
docs:
- 'docs/**'
# For testing:
# - '.github/**'
sh:
- "**.sh"
ts:
- 'site/**'
k8s:
- 'helm/**'
- scripts/Dockerfile
- scripts/Dockerfile.base
- scripts/helm.sh
- id: debug
run: |
echo "${{ toJSON(steps.filter )}}"

gen:
timeout-minutes: 8
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.docs-only == 'false'
if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -182,6 +214,8 @@ jobs:

test-go:
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'buildjet-4vcpu-ubuntu-2204' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xl' || matrix.os == 'windows-2019' && github.repository_owner == 'coder' && 'windows-latest-8-cores' || matrix.os }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 20
strategy:
matrix:
Expand All @@ -192,11 +226,6 @@ jobs:
steps:
- uses: actions/checkout@v3

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

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

- uses: hashicorp/setup-terraform@v2
Expand Down Expand Up @@ -257,6 +286,8 @@ jobs:

test-go-pg:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
# This timeout must be greater than the timeout set by `go test` in
# `make test-postgres` to ensure we receive a trace of running
# goroutines. Setting this to the timeout +5m should work quite well
Expand Down Expand Up @@ -310,6 +341,8 @@ jobs:

test-go-race:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 25
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -355,11 +388,6 @@ jobs:
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1

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

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

Expand Down Expand Up @@ -426,13 +454,15 @@ jobs:

test-js:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 20
steps:
- uses: actions/checkout@v3

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

- run: yarn test:ci --max-workers ${{ steps.cpu-cores.outputs.count }}
- run: yarn test:ci --max-workers $(nproc)
working-directory: site

- uses: codecov/codecov-action@v3
Expand All @@ -448,10 +478,9 @@ jobs:
flags: unittest-js

test-e2e:
needs:
- changes
if: needs.changes.outputs.docs-only == 'false'
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
Expand All @@ -464,10 +493,6 @@ jobs:
terraform_version: 1.1.9
terraform_wrapper: false

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

- name: Build
run: |
sudo npm install -g prettier
Expand All @@ -492,9 +517,8 @@ jobs:
chromatic:
# REMARK: this is only used to build storybook and deploy it to Chromatic.
runs-on: ubuntu-latest
needs:
- changes
if: needs.changes.outputs.ts == 'true'
needs: changes
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -538,3 +562,15 @@ jobs:
buildScriptName: "storybook:build"
projectToken: 695c25b6cb65
workingDir: "./site"

required:
runs-on: ubuntu-latest
needs: [test-go, test-go-pg, test-js]
# allow this job to run even if the previous jobs are skipped
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
steps:
- name: Ensure required checks
run: echo "Required checks have passed"