|
| 1 | +name: Build Verification |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - '**' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Build Website |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + issues: write # Required to create issues |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v6 |
| 21 | + |
| 22 | + - uses: actions/setup-node@v6 |
| 23 | + with: |
| 24 | + node-version: 20 |
| 25 | + cache: yarn |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: yarn install |
| 29 | + |
| 30 | + - name: Build website |
| 31 | + id: build |
| 32 | + run: yarn build |
| 33 | + continue-on-error: true |
| 34 | + |
| 35 | + - name: Create issue on build failure |
| 36 | + if: steps.build.outcome == 'failure' |
| 37 | + uses: actions/github-script@v7 |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const buildUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; |
| 41 | + const issueTitle = `Build Failed: ${process.env.GITHUB_REF_NAME}`; |
| 42 | + const issueBody = `## Build Failure Report |
| 43 | + |
| 44 | + The website build has failed. |
| 45 | + |
| 46 | + **Branch:** ${process.env.GITHUB_REF_NAME} |
| 47 | + **Commit:** ${process.env.GITHUB_SHA} |
| 48 | + **Workflow Run:** ${buildUrl} |
| 49 | + **Triggered by:** ${process.env.GITHUB_ACTOR} |
| 50 | + |
| 51 | + Please check the workflow logs for details on the build failure. |
| 52 | + `; |
| 53 | + |
| 54 | + // Check if there's already an open issue for this |
| 55 | + const issues = await github.rest.issues.listForRepo({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + state: 'open', |
| 59 | + labels: 'build-failure', |
| 60 | + per_page: 100 |
| 61 | + }); |
| 62 | + |
| 63 | + const existingIssue = issues.data.find(issue => |
| 64 | + issue.title === issueTitle |
| 65 | + ); |
| 66 | + |
| 67 | + if (existingIssue) { |
| 68 | + // Comment on existing issue |
| 69 | + await github.rest.issues.createComment({ |
| 70 | + owner: context.repo.owner, |
| 71 | + repo: context.repo.repo, |
| 72 | + issue_number: existingIssue.number, |
| 73 | + body: `Build failed again.\n\n**New Run:** ${buildUrl}\n**Commit:** ${process.env.GITHUB_SHA}` |
| 74 | + }); |
| 75 | + console.log(`Commented on existing issue #${existingIssue.number}`); |
| 76 | + } else { |
| 77 | + // Create new issue |
| 78 | + try { |
| 79 | + const issue = await github.rest.issues.create({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + title: issueTitle, |
| 83 | + body: issueBody, |
| 84 | + labels: ['build-failure'], |
| 85 | + assignees: ['copilot'] |
| 86 | + }); |
| 87 | + console.log(`Created issue #${issue.data.number}`); |
| 88 | + } catch (error) { |
| 89 | + // If assigning to 'copilot' fails, create issue without assignee |
| 90 | + console.log(`Failed to assign to copilot: ${error.message}`); |
| 91 | + const issue = await github.rest.issues.create({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + title: issueTitle, |
| 95 | + body: issueBody, |
| 96 | + labels: ['build-failure'] |
| 97 | + }); |
| 98 | + console.log(`Created issue #${issue.data.number} without assignee`); |
| 99 | + } |
| 100 | + } |
| 101 | +
|
| 102 | + - name: Fail the workflow if build failed |
| 103 | + if: steps.build.outcome == 'failure' |
| 104 | + run: exit 1 |
0 commit comments