diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82e4a6aaf82eb4d..ef5a7b23435aa1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,11 +89,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: npx tsx bin/post-pr-ci-failure-comment/index.ts - build: - name: Build + pre-build: + name: Pre Build runs-on: ubuntu-latest - outputs: - link_check_failed: ${{ steps.check_link_result.outputs.failed }} permissions: contents: read pull-requests: write @@ -114,7 +112,8 @@ jobs: exit 1 fi - - run: | + - name: Check for invalid file extensions + run: | FILES=$( find src/content \ -type f \ @@ -132,27 +131,17 @@ jobs: exit 1 fi - - name: Cache node_modules + - name: Restore node_modules (cache hit) id: node-modules-cache uses: actions/cache@v5 with: path: node_modules key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} - - name: Run sync (if cache hit) - run: npm run sync - if: steps.node-modules-cache.outputs.cache-hit == 'true' - - - name: Node install (cache miss) + - name: Install node_modules (cache miss) run: npm ci if: steps.node-modules-cache.outputs.cache-hit != 'true' - - uses: actions/cache/restore@v5 - with: - path: | - node_modules/.astro/assets - key: static - - run: npx tsx bin/post-codeowners-comment/index.ts continue-on-error: true env: @@ -160,10 +149,64 @@ jobs: - run: npm run check + - run: npm run check:worker + + - uses: reviewdog/action-eslint@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + fail_level: error + filter_mode: nofilter + + - run: npm run format:core:check + + - name: Validate redirects + run: npx tsm bin/validate-redirects.ts + + - name: Tests + run: npm run test:prebuild + + build: + name: Build + needs: pre-build + runs-on: ubuntu-latest + outputs: + link_check_failed: ${{ steps.check_link_result.outputs.failed }} + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 1 + + - uses: actions/setup-node@v6 + with: + node-version: 22.x + cache: npm + + - name: Restore node_modules (cache hit) + id: node-modules-cache + uses: actions/cache@v5 + with: + path: node_modules + key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install node_modules (cache miss) + run: npm ci + if: steps.node-modules-cache.outputs.cache-hit != 'true' + + - name: Restore Astro assets from cache + uses: actions/cache@v5 + with: + path: | + node_modules/.astro/assets + key: static + # The starlight-links-validator plugin runs in astro:build:done, which fires # AFTER all pages have been written to dist/. If link validation fails, the # build exits non-zero but dist/ is complete. We use continue-on-error so the - # job succeeds (allowing deploy + validate to run), then check the outcome below. + # job succeeds (allowing deploy + post-build to run), then check the outcome below. - run: npm run build id: build_step name: Build @@ -188,19 +231,13 @@ jobs: echo "failed=false" >> "$GITHUB_OUTPUT" fi - - uses: actions/cache/save@v5 - with: - path: | - node_modules/.astro/assets - key: static - - uses: actions/upload-artifact@v7 with: name: dist path: dist - validate: - name: Validate + post-build: + name: Post Build needs: build runs-on: ubuntu-latest permissions: @@ -216,27 +253,24 @@ jobs: node-version: 22.x cache: npm - - run: npm ci + - name: Restore node_modules (cache hit) + id: node-modules-cache + uses: actions/cache@v5 + with: + path: node_modules + key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install node_modules (cache miss) + run: npm ci + if: steps.node-modules-cache.outputs.cache-hit != 'true' - uses: actions/download-artifact@v8 with: name: dist path: dist - - uses: reviewdog/action-eslint@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - reporter: github-pr-review - fail_level: error - filter_mode: nofilter - - - run: npm run format:core:check - - - name: Validate redirects - run: npx tsm bin/validate-redirects.ts - - - name: Tests - run: npm run test + - name: Tests (Workers) + run: npm run test:postbuild - name: Link validation if: needs.build.outputs.link_check_failed == 'true' @@ -246,7 +280,7 @@ jobs: notify: name: Notify - needs: [build, validate] + needs: [pre-build, build, post-build] if: always() runs-on: ubuntu-latest permissions: @@ -262,7 +296,16 @@ jobs: node-version: 22.x cache: npm - - run: npm ci + - name: Restore node_modules (cache hit) + id: node-modules-cache + uses: actions/cache@v5 + with: + path: node_modules + key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install node_modules (cache miss) + run: npm ci + if: steps.node-modules-cache.outputs.cache-hit != 'true' - name: Post PR CI failure comment continue-on-error: true @@ -288,7 +331,16 @@ jobs: node-version: 22.x cache: npm - - run: npm ci + - name: Restore node_modules (cache hit) + id: node-modules-cache + uses: actions/cache@v5 + with: + path: node_modules + key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install node_modules (cache miss) + run: npm ci + if: steps.node-modules-cache.outputs.cache-hit != 'true' - uses: actions/download-artifact@v8 with: diff --git a/bin/post-pr-ci-failure-comment/index.ts b/bin/post-pr-ci-failure-comment/index.ts index 3f168bde4a03638..0afca2394e59fac 100644 --- a/bin/post-pr-ci-failure-comment/index.ts +++ b/bin/post-pr-ci-failure-comment/index.ts @@ -25,11 +25,14 @@ async function run(): Promise { }); const ciJobs = run.jobs.filter( - (job) => job.name === "Build" || job.name === "Validate", + (job) => + job.name === "Pre Build" || + job.name === "Build" || + job.name === "Post Build", ); if (ciJobs.length === 0) { - core.setFailed(`Could not find Build or Validate jobs`); + core.setFailed(`Could not find Pre Build, Build, or Post Build jobs`); process.exit(); } diff --git a/package.json b/package.json index df570841140c3b0..eb0b981129666d8 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ "start": "npx astro dev", "sync": "npx astro sync", "test": "npx vitest", + "test:prebuild": "npx vitest --project Node --project Astro", + "test:postbuild": "npx vitest --project Workers", "lint": "npx eslint", "ai-setup:import-from-opencode": "npx rulesync import --targets opencode --features rules,commands,subagents", "ai-setup:claudecode": "npm run ai-setup:import-from-opencode && npx rulesync generate --targets claudecode --features rules,commands,subagents",