Skip to content

Commit 4374ef4

Browse files
authored
fix: When issue updates fail, immediately halt execution (#23)
Fixes the issue I flagged in github/continuous-ai-for-accessibility#18 (comment) (Hubber access only): > I discovered today that workflows can be green even if “File” fails to file anything (e.g. if you provide a `token` without “contents: write” access to the provided `repository`): https://github.com/github/accessibility-sandbox/actions/runs/17081630847 [(Hubber access only)] This PR makes it so that—as soon as issue closure, creation, reopen, or assignment fails—the workflow exits immediately (i.e. subsequent issue updates are not attempted) and when it exits, it is red. Implementation details: - [`core.error`](https://github.com/actions/toolkit/blob/227b1ce741a925ae9f5fdef91fd10415f2d0ca45/packages/core/src/core.ts#L270-L284) — note this neither sets an exit code nor exits the process. - [`core.setFailed`](https://github.com/actions/toolkit/blob/227b1ce741a925ae9f5fdef91fd10415f2d0ca45/packages/core/src/core.ts#L240-L249) — note this calls `core.error` and sets an exit code, but it _doesn’t_ exit the process.
2 parents f07b08b + d86c49d commit 4374ef4

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.github/actions/file/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Finding } from "./types.d.js";
2+
import process from "node:process";
23
import core from "@actions/core";
34
import { Octokit } from '@octokit/core';
45
import { toFindingsMap } from "./toFindingsMap.js"
@@ -31,7 +32,8 @@ export default async function () {
3132
closedIssueUrls.push(response.data.html_url);
3233
core.info(`Closed issue: ${response.data.title} (${repoWithOwner}#${response.data.number})`);
3334
} catch (error) {
34-
core.error(`Failed to close issue for finding: ${error}`);
35+
core.setFailed(`Failed to close issue for finding: ${error}`);
36+
process.exit(1);
3537
}
3638
}
3739
}
@@ -52,7 +54,8 @@ export default async function () {
5254
core.info(`Created issue: ${response.data.title} (${repoWithOwner}#${response.data.number})`);
5355
}
5456
} catch (error) {
55-
core.error(`Failed to open/reopen issue for finding: ${error}`);
57+
core.setFailed(`Failed to open/reopen issue for finding: ${error}`);
58+
process.exit(1);
5659
}
5760
}
5861

.github/actions/fix/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import process from "node:process";
12
import core from "@actions/core";
23
import { Octokit } from '@octokit/core';
34
import { fixIssue } from "./fixIssue.js";
@@ -16,7 +17,8 @@ export default async function () {
1617
await fixIssue(octokit, repoWithOwner, issueUrl);
1718
core.info(`Assigned ${repoWithOwner}#${issueUrl.split('/').pop()} to Copilot!`);
1819
} catch (error) {
19-
core.error(`Failed to assign ${repoWithOwner}#${issueUrl.split('/').pop()} to Copilot: ${error}`);
20+
core.setFailed(`Failed to assign ${repoWithOwner}#${issueUrl.split('/').pop()} to Copilot: ${error}`);
21+
process.exit(1);
2022
}
2123
}
2224
core.info("Finished 'fix' action");

0 commit comments

Comments
 (0)