-
Notifications
You must be signed in to change notification settings - Fork 3
71 lines (61 loc) · 2.41 KB
/
Copy pathpr-title-check.yml
File metadata and controls
71 lines (61 loc) · 2.41 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
name: PR Title Check
on:
pull_request:
types: [opened, edited, synchronize, reopened]
paths:
- 'vup/srcpkgs/**/*'
permissions: {}
jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: Check PR Title
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const title = context.payload.pull_request.title;
const prNumber = context.payload.pull_request.number;
// Allowed formats:
// feat: add <pkgname> [<version>]
// <pkgname>: update to <version>
// fix: <description>
// chore: <description>
// docs: <description>
// ci: <description>
const patterns = [
/^(feat|add):\s+add\s+\S+/i, // New package
/^\S+:\s+update\s+to\s+\S+/i, // Update package
/^(fix|chore|docs|ci|refactor|test):\s+/i, // Standard conventional commits
];
const valid = patterns.some(p => p.test(title));
const reportDir = 'pr-check-report';
fs.mkdirSync(reportDir, { recursive: true });
fs.writeFileSync(`${reportDir}/pr_number.txt`, `${prNumber}\n`);
fs.writeFileSync(`${reportDir}/status.txt`, valid ? 'success\n' : 'failure\n');
fs.writeFileSync(`${reportDir}/details.txt`, `${title}\n`);
if (!valid) {
const msg = [
`:warning: PR title does not follow conventions.`,
'',
'**New package:** `feat: add <pkgname>` or `feat: add <pkgname> <version>`',
'**Update:** `<pkgname>: update to <version>`',
'**Other:** `fix:`, `chore:`, `docs:`, `ci:`, `refactor:`, `test:`',
'',
`Current title: \`${title}\``,
].join('\n');
await core.summary
.addRaw(msg)
.write();
core.setFailed('PR title does not follow conventions. See job summary for format.');
} else {
console.log(`PR title "${title}" is valid.`);
}
- name: Upload PR Check Report
if: always()
uses: actions/upload-artifact@v7
with:
name: pr-check-report
path: pr-check-report/*
if-no-files-found: ignore