Skip to content

Commit 2ac4e18

Browse files
committed
Fix the validate plugin toml ci
1 parent 972b306 commit 2ac4e18

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

.github/workflows/validate-plugin-toml.yml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name: Validate Plugin TOML
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches:
66
- master
77
paths:
88
- 'plugins/**'
99

1010
permissions:
11-
pull-requests: write
11+
contents: read
12+
issues: write
1213

1314
jobs:
1415
validate:
@@ -20,11 +21,12 @@ jobs:
2021
with:
2122
submodules: recursive
2223
fetch-depth: 0
24+
ref: ${{ github.event.pull_request.head.sha }}
2325

2426
- name: Get changed plugins
2527
id: changed
2628
run: |
27-
CHANGED_PLUGINS=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^plugins/' | cut -d'/' -f2 | sort -u | tr '\n' ' ')
29+
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' ' ')
2830
echo "plugins=$CHANGED_PLUGINS" >> $GITHUB_OUTPUT
2931
echo "Changed plugins: $CHANGED_PLUGINS"
3032
@@ -53,8 +55,6 @@ jobs:
5355
run: |
5456
pnpm validate ${{ steps.changed.outputs.plugins }}
5557
echo "result=success" >> $GITHUB_OUTPUT
56-
# If validation fails (exit 1), continue-on-error keeps the workflow running
57-
# but 'result=success' won't be written to GITHUB_OUTPUT
5858
5959
- name: Post validation comment
6060
if: always() && steps.changed.outputs.plugins != ''
@@ -72,28 +72,37 @@ jobs:
7272
body = marker + '\n## Plugin TOML Validation Report\n\n> No validation report generated.';
7373
}
7474
75-
const { data: comments } = await github.rest.issues.listComments({
76-
owner: context.repo.owner,
77-
repo: context.repo.repo,
78-
issue_number: context.issue.number,
79-
});
80-
81-
const existing = comments.find(c => c.body && c.body.includes(marker));
82-
83-
if (existing) {
84-
await github.rest.issues.updateComment({
85-
owner: context.repo.owner,
86-
repo: context.repo.repo,
87-
comment_id: existing.id,
88-
body,
89-
});
90-
} else {
91-
await github.rest.issues.createComment({
75+
try {
76+
const { data: comments } = await github.rest.issues.listComments({
9277
owner: context.repo.owner,
9378
repo: context.repo.repo,
9479
issue_number: context.issue.number,
95-
body,
9680
});
81+
82+
const existing = comments.find(c => c.body && c.body.includes(marker));
83+
84+
if (existing) {
85+
await github.rest.issues.updateComment({
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
comment_id: existing.id,
89+
body,
90+
});
91+
} else {
92+
await github.rest.issues.createComment({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
issue_number: context.issue.number,
96+
body,
97+
});
98+
}
99+
} catch (error) {
100+
if (error.status === 403) {
101+
core.warning(`Skipping PR comment because the workflow token cannot write comments: ${error.message}`);
102+
return;
103+
}
104+
105+
throw error;
97106
}
98107
99108
- name: Fail if validation failed

0 commit comments

Comments
 (0)