diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44b17367f..7c0975700 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,34 @@ jobs: echo "PR targets '${BASE_REF}' branch - OK" fi - test: + test-isolated: + name: Isolated tests (${{ matrix.shard }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + shard: [0, 1, 2, 3] + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: "1.3.12" + + - uses: actions/cache@v4 + with: + path: ~/.bun/install/cache + key: ${{ runner.os }}-bun-1.3.12-${{ hashFiles('bun.lock') }} + + - name: Install dependencies + run: bun install --frozen-lockfile + env: + BUN_INSTALL_ALLOW_SCRIPTS: "@ast-grep/napi" + + - name: Run isolated tests + run: bun run script/run-ci-tests.ts --phase=isolated --shard-count=4 --shard-index=${{ matrix.shard }} + + test-shared: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -41,16 +68,24 @@ jobs: with: bun-version: "1.3.12" + - uses: actions/cache@v4 + with: + path: ~/.bun/install/cache + key: ${{ runner.os }}-bun-1.3.12-${{ hashFiles('bun.lock') }} + - name: Install dependencies run: bun install --frozen-lockfile env: BUN_INSTALL_ALLOW_SCRIPTS: "@ast-grep/napi" - - name: Build plugin - run: bun run build + - name: Run shared tests + run: bun run script/run-ci-tests.ts --phase=shared - - name: Run tests - run: bun run script/run-ci-tests.ts + test: + runs-on: ubuntu-latest + needs: [test-isolated, test-shared] + steps: + - run: echo "All test shards passed" typecheck: runs-on: ubuntu-latest @@ -61,6 +96,11 @@ jobs: with: bun-version: "1.3.12" + - uses: actions/cache@v4 + with: + path: ~/.bun/install/cache + key: ${{ runner.os }}-bun-1.3.12-${{ hashFiles('bun.lock') }} + - name: Install dependencies run: bun install --frozen-lockfile env: @@ -86,6 +126,11 @@ jobs: with: bun-version: "1.3.12" + - uses: actions/cache@v4 + with: + path: ~/.bun/install/cache + key: ${{ runner.os }}-bun-1.3.12-${{ hashFiles('bun.lock') }} + - name: Install dependencies run: bun install --frozen-lockfile env: @@ -99,6 +144,9 @@ jobs: test -f dist/index.js || (echo "ERROR: dist/index.js not found!" && exit 1) test -f dist/index.d.ts || (echo "ERROR: dist/index.d.ts not found!" && exit 1) + - name: Verify dist bundle tests + run: bun test src/shared/dist-bundle-bun-globals.test.ts + - name: Auto-commit schema changes if: github.event_name == 'push' && github.ref == 'refs/heads/master' run: | diff --git a/script/publish-workflow.test.ts b/script/publish-workflow.test.ts index f1f45eb5b..70e97a40b 100644 --- a/script/publish-workflow.test.ts +++ b/script/publish-workflow.test.ts @@ -3,19 +3,30 @@ import { describe, expect, test } from "bun:test" import { readFileSync } from "node:fs" -const workflowPaths = [ - new URL("../.github/workflows/ci.yml", import.meta.url), - new URL("../.github/workflows/publish.yml", import.meta.url), +const workflowChecks = [ + { + path: new URL("../.github/workflows/ci.yml", import.meta.url), + testRuns: [ + "run: bun run script/run-ci-tests.ts --phase=isolated --shard-count=4 --shard-index=${{ matrix.shard }}", + "run: bun run script/run-ci-tests.ts --phase=shared", + "run: bun test src/shared/dist-bundle-bun-globals.test.ts", + ], + }, + { + path: new URL("../.github/workflows/publish.yml", import.meta.url), + testRuns: ["run: bun run script/run-ci-tests.ts"], + }, ] describe("test workflows", () => { test("use pure bun test for workflows", () => { - for (const workflowPath of workflowPaths) { + for (const workflowCheck of workflowChecks) { // #given - const workflow = readFileSync(workflowPath, "utf8") + const workflow = readFileSync(workflowCheck.path, "utf8") - expect(workflow).toContain("- name: Run tests") - expect(workflow).toMatch(/run: bun (test|run script\/run-ci-tests\.ts)/) + for (const testRun of workflowCheck.testRuns) { + expect(workflow).toContain(testRun) + } } }) })