forked from js-org/js.org
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (70 loc) · 2.59 KB
/
validate.yml
File metadata and controls
86 lines (70 loc) · 2.59 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
name: Validate
on:
push:
branches:
- master
pull_request:
branches:
- master
types:
- opened
- reopened
- edited
- synchronize
permissions:
contents: read
jobs:
validate-cnames:
runs-on: ubuntu-latest
env:
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.GH_EVENT_HASH }}
- uses: actions/checkout@v4
with:
repository: js-org/js.org-cleanup
path: cleanup
- uses: actions/setup-node@v4
with:
node-version-file: cleanup/.nvmrc
cache: npm
cache-dependency-path: cleanup/package-lock.json
- name: Install dependencies
run: npm ci
working-directory: cleanup
- name: Validate cnames_active.js
run: node index.js --validate ../cnames_active.js
working-directory: cleanup
validate-pr-template:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Validate PR template
uses: actions/github-script@v7
with:
script: |
const body = context.payload.pull_request.body || "";
// 1. Check both checkboxes
const checkbox1 = /\[x\].*?There is reasonable content/i.test(body);
const checkbox2 = /\[x\].*?I have read and accepted/i.test(body);
// 2. URL must be on the exact "The site content can be seen at ..." line
// https://regex101.com/r/N36fsT
const urlLineRegex = /^[ \t]*-[ \t]*The site content can be seen at[ \t]+(?:<)?(?:\[.*?\]\()?https?:\/\/[^\s>()]+(?:\))?(?:>)?/m;
const urlMatch = urlLineRegex.exec(body);
const urlValid = urlMatch !== null;
// 3. Explanation must follow the blockquote marker
const explanationMatch = />\s*The site content is(?:\s*|\s*\n)(.+)/i.exec(body);
const explanation = explanationMatch && explanationMatch[1].trim().length > 10;
if (!checkbox1 || !checkbox2 || !urlValid || !explanation) {
core.setFailed(
"❌ PR template is not properly filled:\n" +
`Checkbox1: ${checkbox1 ? '✅' : '❌'}\n` +
`Checkbox2: ${checkbox2 ? '✅' : '❌'}\n` +
`URL on correct line: ${urlValid ? '✅' : '❌'}\n` +
`Explanation: ${explanation ? '✅' : '❌'}`
);
} else {
console.log("✅ PR template format is valid.");
}