Skip to content

Commit bfcff14

Browse files
committed
ci: tolerate restricted GITHUB_TOKEN in tool authoring guidance
When org policy caps GITHUB_TOKEN to read-only, posting a PR comment returns 403 and fails the check. Fall back to writing the reminder to the job summary so the check passes and contributors still see the guidance in the run output.
1 parent e3e2ee5 commit bfcff14

1 file changed

Lines changed: 35 additions & 14 deletions

File tree

.github/workflows/tool-authoring-guidance.yml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,40 @@ jobs:
9393
.map((line) => line.trimStart())
9494
.join('\n');
9595
96-
if (existingComment) {
97-
await github.rest.issues.updateComment({
98-
owner,
99-
repo,
100-
comment_id: existingComment.id,
101-
body: normalizedBody,
102-
});
103-
return;
96+
async function writeJobSummary(reason) {
97+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
98+
if (!summaryPath) return;
99+
const fs = require('fs');
100+
const note = reason
101+
? `> Could not post PR comment (${reason}). Showing reminder here instead.\n\n`
102+
: '';
103+
fs.appendFileSync(summaryPath, `${note}${normalizedBody}\n`);
104104
}
105105
106-
await github.rest.issues.createComment({
107-
owner,
108-
repo,
109-
issue_number: pull_number,
110-
body: normalizedBody,
111-
});
106+
try {
107+
if (existingComment) {
108+
await github.rest.issues.updateComment({
109+
owner,
110+
repo,
111+
comment_id: existingComment.id,
112+
body: normalizedBody,
113+
});
114+
} else {
115+
await github.rest.issues.createComment({
116+
owner,
117+
repo,
118+
issue_number: pull_number,
119+
body: normalizedBody,
120+
});
121+
}
122+
await writeJobSummary(null);
123+
} catch (error) {
124+
if (error.status === 403) {
125+
core.warning(
126+
'GITHUB_TOKEN lacks issues:write permission; posting reminder to the job summary instead of a PR comment.',
127+
);
128+
await writeJobSummary('token lacks issues:write');
129+
return;
130+
}
131+
throw error;
132+
}

0 commit comments

Comments
 (0)