ci: add skip directives for long tests (#3151)

This PR introduces many CI optimizations:

1. The `[ci-skip]` PR body directive to skip the Postgres and end to end tests
2. Improved caching that cuts the Go test matrix in half
3. Increasing Go test parallelism for ~20% gains
4. Enable caching in webpack (4x frontend build)
This commit is contained in:
Ammar Bandukwala
2022-07-24 14:33:58 -05:00
committed by GitHub
parent 5578facf8f
commit 60de8d0279
8 changed files with 191 additions and 19 deletions
+69 -18
View File
@@ -60,13 +60,31 @@ jobs:
echo "${{ toJSON(steps.filter )}}"
# Debug step
show-changes:
needs: changes
debug-inputs:
needs:
- changes
- pr-context
runs-on: ubuntu-latest
steps:
- id: log
run: |
echo "${{ toJSON(needs.changes) }}"
echo "${{ toJSON(needs) }}"
echo "${{ contains(needs.pr-context.outputs.skips, 'postgres') }} "
pr-context:
runs-on: ubuntu-latest
outputs:
skips: ${{ steps.pr-context.outputs.skips }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "~1.18"
- id: pr-context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
go run github.com/coder/coder/.github/workflows/prcontext
style-lint-golangci:
name: style/lint/golangci
@@ -157,6 +175,25 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.18"
- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ github.job }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ github.job }}-go-mod-${{ hashFiles('**/go.sum') }}
- run: |
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.13.0/sqlc_1.13.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
@@ -229,7 +266,7 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
- name: Go Mod Cache
uses: actions/cache@v3
@@ -251,14 +288,23 @@ jobs:
terraform_wrapper: false
- name: Test with Mock Database
id: test
shell: bash
run: gotestsum --junitfile="gotests.xml" --packages="./..." --
-covermode=atomic -coverprofile="gotests.coverage"
-coverpkg=./...,github.com/coder/coder/codersdk
-timeout=5m -short -failfast
run: |
# Code coverage is more computationally expensive and also
# prevents test caching, so we disable it on alternate operating
# systems.
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo ::set-output name=cover::true
export COVERAGE_FLAGS='-covermode=atomic -coverprofile="gotests.coverage" -coverpkg=./...,github.com/coder/coder/codersdk'
else
echo ::set-output name=cover::false
fi
set -x
gotestsum --junitfile="gotests.xml" --packages="./..." -- -parallel=8 -timeout=5m -short -failfast $COVERAGE_FLAGS
- name: Upload DataDog Trace
if: always() && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DD_DATABASE: fake
@@ -272,7 +318,7 @@ jobs:
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
@@ -280,8 +326,12 @@ jobs:
test-go-postgres:
name: "test/go/postgres"
needs: changes
if: needs.changes.outputs.docs-only == 'false'
needs:
- changes
- pr-context
if: >
needs.changes.outputs.docs-only == 'false' &&
contains(needs.pr-context.outputs.skips, github.job) == 'false'
runs-on: 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
@@ -305,7 +355,7 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
- name: Go Mod Cache
uses: actions/cache@v3
@@ -517,8 +567,10 @@ jobs:
test-e2e:
name: "test/e2e/${{ matrix.os }}"
needs: changes
if: needs.changes.outputs.docs-only == 'false'
needs:
- changes
- pr-context
if: needs.changes.outputs.docs-only == 'false' && !contains(needs.pr-context.outputs.skips, 'test/e2e')
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
@@ -535,9 +587,7 @@ jobs:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
key: js-${{ runner.os }}-e2e-${{ hashFiles('**/yarn.lock') }}
# Go is required for uploading the test results to datadog
- uses: actions/setup-go@v3
@@ -573,6 +623,7 @@ jobs:
- name: Build
run: |
sudo npm install -g prettier
make -B site/out/index.html
- run: yarn playwright:install