forked from kike-alt/DeWordle
-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (103 loc) · 4.68 KB
/
Copy pathdependency-link-validator.yml
File metadata and controls
119 lines (103 loc) · 4.68 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Dependency Link Validator
on:
issues:
types: [opened, edited]
permissions:
issues: write # post correction comment
contents: read
jobs:
validate:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Run dependency-link validator
id: validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_BODY: ${{ github.event.issue.body }}
# Always capture output; exit code drives the comment step
run: |
node scripts/validate-dependency-links.js 2>&1 | tee /tmp/dep-validation.log
echo "exit_code=${PIPESTATUS[0]}" >> "$GITHUB_OUTPUT"
continue-on-error: true
- name: Post correction comment on failure
if: steps.validate.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const log = fs.readFileSync('/tmp/dep-validation.log', 'utf8');
const marker = '<!-- dep-link-validator -->';
const issueNumber = context.issue.number;
// Check for an existing validator comment to update instead of spamming
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
per_page: 100,
});
const existing = comments.data.find(c => c.body.includes(marker));
const body = [
marker,
'## ⚠️ Dependency Link Validation Failed',
'',
'One or more dependency references in this issue body are invalid.',
'Please review the report below and update the issue body.',
'',
'```',
log.trim(),
'```',
'',
'---',
'_This comment is updated automatically on each edit. It will be removed once all references are valid._',
].join('\n');
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body,
});
}
- name: Resolve previous failure comment on success
if: steps.validate.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- dep-link-validator -->';
const issueNumber = context.issue.number;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
per_page: 100,
});
const existing = comments.data.find(c => c.body.includes(marker));
if (!existing) return;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: [
marker,
'## ✅ Dependency Links Resolved',
'',
'All dependency references in this issue are now valid. No further action needed.',
].join('\n'),
});
- name: Fail the job if validation did not pass
if: steps.validate.outcome == 'failure'
run: exit 1