Repository navigation
ci: run tests in parallel and shard the slowest jobs #531
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| workflow_call: | |
| inputs: | |
| mutation_base_ref: | |
| required: false | |
| type: string | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| concurrency: | |
| group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.event_name }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| env: | |
| FORCE_COLOR: "0" | |
| NO_COLOR: "1" | |
| TERRADB_TEST_SILENT: "1" | |
| # Test jobs run `bun test --parallel` with one database per worker | |
| # (src/test/support/worker-database.ts) and shard files by the durations in | |
| # tools/test-timings.json. Jobs that are split into shards keep a summary job | |
| # under their original name. | |
| jobs: | |
| lint: | |
| name: lint | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: bun install | |
| - run: bunx tsc --noEmit | |
| test-unit: | |
| name: test:unit | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| services: | |
| postgres: | |
| image: postgres:17-alpine | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run tools/tune-ci-postgres.ts postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| - run: bun run test:unit | |
| env: | |
| DATABASE_URL: postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| test-sqlite: | |
| name: test:sqlite | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run test:sqlite | |
| test-pg14-shard: | |
| name: test:pg:14 (${{ matrix.shard }}/2) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| shard: [1, 2] | |
| services: | |
| postgres: | |
| image: postgres:14-alpine | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run tools/tune-ci-postgres.ts postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| - run: bun run test:pg:14 --shard=${{ matrix.shard }}/2 | |
| env: | |
| DATABASE_URL_PG14: postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| test-pg14: | |
| name: test:pg:14 | |
| needs: test-pg14-shard | |
| if: always() | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - run: test "${{ needs.test-pg14-shard.result }}" = success | |
| test-pg18-shard: | |
| name: test:pg:18 (${{ matrix.shard }}/2) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| shard: [1, 2] | |
| services: | |
| postgres: | |
| image: postgres:18-alpine | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run tools/tune-ci-postgres.ts postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| - run: bun run test:pg:18 --shard=${{ matrix.shard }}/2 | |
| env: | |
| DATABASE_URL_PG18: postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| test-pg18: | |
| name: test:pg:18 | |
| needs: test-pg18-shard | |
| if: always() | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - run: test "${{ needs.test-pg18-shard.result }}" = success | |
| test-pg-extensions: | |
| name: test:pg:extensions | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| services: | |
| postgres-pgvector: | |
| image: pgvector/pgvector:0.8.1-pg17 | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5488:5432 | |
| postgres-postgis: | |
| image: postgis/postgis:17-3.5 | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5489:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run test:pg:extensions | |
| test-e2e: | |
| name: test:e2e | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run test:e2e | |
| test-property-pr: | |
| name: test:property:pr | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| services: | |
| postgres: | |
| image: postgres:17-alpine | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run tools/tune-ci-postgres.ts postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| - run: bun run test:property:pr | |
| env: | |
| FC_SEED: "20260218" | |
| DATABASE_URL: postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| test-flake: | |
| name: test:flake | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| services: | |
| postgres: | |
| image: postgres:17-alpine | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run tools/tune-ci-postgres.ts postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| - run: bun run test:flake | |
| env: | |
| DATABASE_URL: postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| test-mutation-changed-shard: | |
| name: test:mutation:changed (${{ matrix.shard }}/4) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| shard: [1, 2, 3, 4] | |
| services: | |
| postgres: | |
| image: postgres:17-alpine | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run tools/tune-ci-postgres.ts postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| - run: bun run test:mutation:changed:report --shard ${{ matrix.shard }}/4 | |
| env: | |
| DATABASE_URL: postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| DATABASE_URL_PG14: "" | |
| DATABASE_URL_PG15: "" | |
| DATABASE_URL_PG16: "" | |
| DATABASE_URL_PG17: postgres://test_user:test_password@localhost:5432/sql_terraform_test | |
| MUTATION_BASE_REF: ${{ inputs.mutation_base_ref || github.event.pull_request.base.sha || github.event.before }} | |
| MUTATION_HEAD_REF: ${{ github.sha }} | |
| MUTATION_MAX_MUTANTS_PER_FILE: "4" | |
| MUTATION_TIMEOUT_MS: "180000" | |
| - uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: mutation-shard-${{ matrix.shard }} | |
| path: coverage/mutation/ | |
| test-mutation-changed: | |
| name: test:mutation:changed | |
| needs: test-mutation-changed-shard | |
| if: always() | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - run: test "${{ needs.test-mutation-changed-shard.result }}" = success | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: bun install | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: mutation-shard-* | |
| path: mutation-shards | |
| - run: bun run tools/merge-mutation-reports.ts --out coverage/mutation/mutation-report.json mutation-shards/*/mutation-report.json | |
| - run: bun run tools/check-mutation-gate.ts --mode gate --threshold 85 --min-risk high --out coverage/mutation/changed-files-baseline.json --report coverage/mutation/mutation-report.json | |
| env: | |
| MUTATION_BASE_REF: ${{ inputs.mutation_base_ref || github.event.pull_request.base.sha || github.event.before }} | |
| MUTATION_HEAD_REF: ${{ github.sha }} | |
| - uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: mutation-reports | |
| path: coverage/mutation/ | |
| coverage-build: | |
| name: coverage gate + build | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| services: | |
| postgres: | |
| image: postgres:17-alpine | |
| env: | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_USER: test_user | |
| POSTGRES_DB: sql_terraform_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 2s | |
| --health-timeout 5s | |
| --health-retries 30 | |
| ports: | |
| - 5487:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.4.2" | |
| - run: cp .env.example .env | |
| - run: bun install | |
| - run: bun run test:doctor | |
| - run: bun run tools/tune-ci-postgres.ts postgres://test_user:test_password@localhost:5487/sql_terraform_test | |
| - run: bun run test:coverage | |
| env: | |
| DATABASE_URL: postgres://test_user:test_password@localhost:5487/sql_terraform_test | |
| - run: bun run build |