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