[Docs Site] Post build errors as PR comments #46731
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: | |
| pull_request: | |
| branches: | |
| - production | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| compile: | |
| name: Compiles | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: bash --noprofile --norc -eo pipefail {0} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: "npm" | |
| - uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| node_modules/.astro | |
| key: static | |
| - run: npm ci |& tee -a build.log | |
| - run: npm run check | |
| - run: npm run format:core:check | |
| ## TODO: content formatting checks | |
| - run: npm run build |& tee -a build.log | |
| env: | |
| NODE_OPTIONS: "--max-old-space-size=4192" | |
| RUN_LINK_CHECK: true | |
| - run: npm run check:worker | |
| - uses: actions/cache/save@v4 | |
| with: | |
| path: | | |
| node_modules/.astro | |
| key: static | |
| - name: Check - Validate redirects (infinite loops, sources with fragment) | |
| run: npx tsm bin/validate-redirects.ts | |
| - name: Tests | |
| run: npm run test | |
| - name: post build errors as PR comment | |
| if: failure() | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # remove ANSI colours & try find some known error strings | |
| ERRORS=$(cat build.log | sed 's/\x1B\[[0-9;]*[A-Za-z]//g' | awk 'tolower($0) ~ /\[.*error.*\]|npm err|\[vite\] error /,0') | |
| if [ -n "$ERRORS" ]; then | |
| URL=$(gh run view ${{ github.run_id }} --json url --jq '.url') | |
| BODY="[Build failed]($URL)\n\n\`\`\`txt\n$ERRORS\n\`\`\`" | |
| echo -e "$BODY" | gh pr comment ${{ github.event.number }} --repo ${{ github.repository }} --body-file - | |
| fi |