-
Notifications
You must be signed in to change notification settings - Fork 3
111 lines (95 loc) · 3.35 KB
/
validate-plugin-toml.yml
File metadata and controls
111 lines (95 loc) · 3.35 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
name: Validate Plugin TOML
on:
pull_request_target:
branches:
- master
paths:
- 'plugins/**'
permissions:
contents: read
issues: write
pull-requests: write
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Get changed plugins
id: changed
run: |
CHANGED_PLUGINS=$(git diff --name-only origin/${{ github.base_ref }}...${{ github.event.pull_request.head.sha }} | grep '^plugins/' | cut -d'/' -f2 | sort -u | tr '\n' ' ')
echo "plugins=$CHANGED_PLUGINS" >> $GITHUB_OUTPUT
echo "Changed plugins: $CHANGED_PLUGINS"
- name: Setup Node.js
if: steps.changed.outputs.plugins != ''
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Setup pnpm
if: steps.changed.outputs.plugins != ''
uses: pnpm/action-setup@v4
with:
version: 10
- name: Install dependencies
if: steps.changed.outputs.plugins != ''
run: pnpm install
- name: Validate plugin.toml files
id: validate
if: steps.changed.outputs.plugins != ''
continue-on-error: true
env:
VALIDATION_REPORT_PATH: validation-report.md
run: |
pnpm validate ${{ steps.changed.outputs.plugins }}
echo "result=success" >> $GITHUB_OUTPUT
- name: Post validation comment
if: always() && steps.changed.outputs.plugins != ''
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const marker = '<!-- plugin-toml-validation -->';
let body;
const reportPath = 'validation-report.md';
if (fs.existsSync(reportPath)) {
body = marker + '\n' + fs.readFileSync(reportPath, 'utf8');
} else {
body = marker + '\n## Plugin TOML Validation Report\n\n> No validation report generated.';
}
try {
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body && c.body.includes(marker));
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: context.issue.number,
body,
});
}
} catch (error) {
if (error.status === 403) {
core.warning(`Skipping PR comment because the workflow token cannot write comments: ${error.message}`);
return;
}
throw error;
}
- name: Fail if validation failed
if: steps.validate.outcome == 'failure'
run: exit 1