@@ -59,186 +59,6 @@ jobs:
59
59
- name : Validate Changeset
60
60
run : pnpm changeset status --since=origin/${{ github.base_ref }}
61
61
62
- validate-checklist :
63
- name : Validate PR Checklist Completion
64
- runs-on : ubuntu-latest
65
- steps :
66
- - name : Checkout code
67
- uses : actions/checkout@v4
68
- with :
69
- fetch-depth : 0
70
- - name : Check that all checklist items are complete
71
- uses : actions/github-script@v6
72
- with :
73
- script : |
74
- (async () => {
75
- const fs = require('fs');
76
- const path = require('path');
77
- const marker = "<!-- validation-comment -->";
78
-
79
- // Get PR details
80
- const pr = context.payload.pull_request;
81
- const prBody = pr.body || "";
82
-
83
- // Load the checklist template from the current checkout, or fallback to the GitHub API.
84
- let templateContent = "";
85
- const templateFilePath = path.join(process.cwd(), ".github/pull_request_template.md");
86
- if (fs.existsSync(templateFilePath)) {
87
- templateContent = fs.readFileSync(templateFilePath, { encoding: "utf8" });
88
- } else {
89
- const response = await github.rest.repos.getContent({
90
- owner: context.repo.owner,
91
- repo: context.repo.repo,
92
- path: ".github/pull_request_template.md",
93
- });
94
- const buff = Buffer.from(response.data.content, 'base64');
95
- templateContent = buff.toString('utf8');
96
- }
97
-
98
- // Count the checklist items in the template and the checkmarked items in the PR
99
- const expectedCount = (templateContent.match(/-\s*\[\s*\]/g) || []).length;
100
- const checkedCount = (prBody.match(/-\s*\[[xX]\]/g) || []).length;
101
-
102
- if (checkedCount < expectedCount) {
103
- const errorMessage = `${marker}❌ Incomplete checklist: expected ${expectedCount} completed items, but found ${checkedCount}. Please complete all checklist items in the PR template.`;
104
-
105
- // List all comments and look for an existing error comment.
106
- const { data: comments } = await github.rest.issues.listComments({
107
- owner: context.repo.owner,
108
- repo: context.repo.repo,
109
- issue_number: pr.number,
110
- });
111
- const existingComment = comments.find(comment => comment.body && comment.body.includes(marker));
112
-
113
- if (existingComment) {
114
- await github.rest.issues.updateComment({
115
- owner: context.repo.owner,
116
- repo: context.repo.repo,
117
- comment_id: existingComment.id,
118
- body: errorMessage,
119
- });
120
- } else {
121
- await github.rest.issues.createComment({
122
- owner: context.repo.owner,
123
- repo: context.repo.repo,
124
- issue_number: pr.number,
125
- body: errorMessage,
126
- });
127
- }
128
- throw new Error(errorMessage);
129
- } else {
130
- // If the checklist is complete, remove any existing error comment.
131
- const { data: comments } = await github.rest.issues.listComments({
132
- owner: context.repo.owner,
133
- repo: context.repo.repo,
134
- issue_number: pr.number,
135
- });
136
- const existingComment = comments.find(comment => comment.body && comment.body.includes(marker));
137
- if (existingComment) {
138
- await github.rest.issues.deleteComment({
139
- owner: context.repo.owner,
140
- repo: context.repo.repo,
141
- comment_id: existingComment.id,
142
- });
143
- }
144
- console.log("All checklist items have been completed.");
145
- }
146
- })().catch(error => {
147
- console.error(error);
148
- throw error;
149
- });
150
- verify-issue-reference :
151
- name : Validate PR Issue References
152
- runs-on : ubuntu-latest
153
- steps :
154
- - name : Check for GitHub and Linear issue references
155
- uses : actions/github-script@v6
156
- with :
157
- script : |
158
- (async () => {
159
- const pr = context.payload.pull_request;
160
- const prBody = pr.body || "";
161
- // Regex for a GitHub issue reference, for example "Closes #123"
162
- const githubIssueRegex = /#\d+/;
163
- // Regex for a Linear issue reference, for example "FE-123"
164
- const linearIssueRegex = /FE-\d+/;
165
-
166
- const githubIssueMatch = prBody.match(githubIssueRegex);
167
- const linearIssueMatch = prBody.match(linearIssueRegex);
168
- let missingRefs = [];
169
-
170
- if (!githubIssueMatch) {
171
- missingRefs.push("GitHub Issue (e.g., Closes #123)");
172
- }
173
- if (!linearIssueMatch) {
174
- missingRefs.push("Linear Issue (e.g., FE-123)");
175
- }
176
-
177
- if (missingRefs.length > 0) {
178
- const marker = "<!-- validation-comment -->";
179
- const errorMessage = `${marker}❌ Missing required references: " + missingRefs.join(" and ") + ". Please include both a GitHub and a Linear issue reference in your PR description.`;
180
- // Add a comment in the PR conversation
181
- // List all comments and look for an existing error comment.
182
- const { data: comments } = await github.rest.issues.listComments({
183
- owner: context.repo.owner,
184
- repo: context.repo.repo,
185
- issue_number: pr.number,
186
- });
187
- const existingComment = comments.find(comment => comment.body && comment.body.includes(marker));
188
-
189
- if (existingComment) {
190
- await github.rest.issues.updateComment({
191
- owner: context.repo.owner,
192
- repo: context.repo.repo,
193
- comment_id: existingComment.id,
194
- body: errorMessage,
195
- });
196
- } else {
197
- await github.rest.issues.createComment({
198
- owner: context.repo.owner,
199
- repo: context.repo.repo,
200
- issue_number: pr.number,
201
- body: errorMessage,
202
- });
203
- }
204
- throw new Error("Missing required issue references in the PR description.");
205
- } else {
206
- console.log("Both GitHub and Linear issue references are present in the PR.");
207
- }
208
- })().catch(error => {
209
- console.error(error);
210
- throw error;
211
- });
212
-
213
- cleanup-gh-comments :
214
- name : Remove validation comments
215
- runs-on : ubuntu-latest
216
- needs : [validate-checklist, verify-issue-reference]
217
- steps :
218
- - name : Remove checklist and reference validation comments
219
- uses : actions/github-script@v6
220
- with :
221
- script : |
222
- (async () => {
223
- const pr = context.payload.pull_request;
224
- const { data: comments } = await github.rest.issues.listComments({
225
- owner: context.repo.owner,
226
- repo: context.repo.repo,
227
- issue_number: pr.number,
228
- });
229
- const marker = "<!-- validation-comment -->";
230
- const errorComments = comments.filter(comment => comment.body && comment.body.includes(marker));
231
- for (const comment of errorComments) {
232
- await github.rest.issues.deleteComment({
233
- owner: context.repo.owner,
234
- repo: context.repo.repo,
235
- comment_id: comment.id,
236
- });
237
- }
238
- })().catch(error => {
239
- console.error(error);
240
- throw error;
241
- });
242
62
audit :
243
63
name : Audit
244
64
runs-on : ubuntu-latest
@@ -296,16 +116,19 @@ jobs:
296
116
steps :
297
117
- name : Checkout
298
118
uses : actions/checkout@v4
119
+
299
120
- name : Extract pnpm version from .tool-versions
300
121
id : get_pnpm
301
122
run : |
302
123
PNPM_VERSION=$(grep '^pnpm' .tool-versions | awk '{print $2}')
303
124
echo "PNPM_VERSION=${PNPM_VERSION}" >> $GITHUB_ENV
125
+
304
126
- name : Setup Node
305
127
uses : FuelLabs/github-actions/setups/node@master
306
128
with :
307
129
node-version : 20.11.0
308
130
pnpm-version : ${{ env.PNPM_VERSION }}
131
+
309
132
- name : Run lint
310
133
run : |
311
134
pnpm ts:check
0 commit comments