Skip to content

Commit 7204fd5

Browse files
authored
Merge pull request #7 from mainmatter/fix-branch-build
Ignore action run events other than pull requests
2 parents ea4562b + f9f2917 commit 7204fd5

File tree

5 files changed

+100
-87
lines changed

5 files changed

+100
-87
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ Considering you have the following `.github/workflow` file:
1616
name: CI
1717

1818
on:
19-
push:
20-
branches:
21-
- main
19+
# NOTE: continue-on-error-comment only makes sense to run on a Pull Request
20+
# see below for more information
2221
pull_request: {}
2322

2423
jobs:
@@ -60,6 +59,12 @@ and then you add a step after that one that uses this action making sure that yo
6059

6160
Test-id is used to identify which test failed, so make sure that you pass the relevant `matrix` variables so that you can identify it later.
6261

62+
### Pull Request Context
63+
64+
`continue-on-error-comment` is designed to be used in the context of a Pull Request. It doesn't make much sense to run this on a commit on a branch.
65+
66+
If you do end up adding this action in a non-PR context then it is designed to just do nothing and continue without error. If you find that isn't true please open a bug report with reproduction instructions and we will fix the problem.
67+
6368
## Inputs
6469

6570
### `repo-token`

dist/index.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9586,53 +9586,57 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
95869586

95879587

95889588

9589-
try {
9590-
const myToken = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('repo-token', { required: true });
9591-
const outcome = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('outcome', { required: true });
9592-
const testId = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('test-id', { required: true });
9593-
9594-
if (outcome === 'failure') {
9595-
const octokit = (0,_actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit)(myToken);
9596-
const pullRequest = await (0,_lib_get_pull_request_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context, octokit);
9597-
9598-
const { data: comments } = await octokit.rest.issues.listComments({
9599-
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
9600-
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
9601-
issue_number: pullRequest.number,
9602-
});
9603-
9604-
const existingComment = comments.find((comment) => comment.user.login === 'github-actions[bot]' && comment.body.endsWith(_lib_constants_js__WEBPACK_IMPORTED_MODULE_3__/* .signiture */ .o) && comment.body.includes(`sha: ${_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha}`));
9605-
9606-
if (existingComment) {
9607-
9608-
let body = existingComment.body.split('\n');
9609-
9610-
body.splice(body.length - 3, 0, `- ${testId}`);
9611-
9612-
await octokit.rest.issues.updateComment({
9613-
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
9614-
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
9615-
comment_id: existingComment.id,
9616-
body: body.join('\n'),
9617-
});
9618-
} else {
9619-
const body = `Some tests with 'continue-on-error: true' have failed:
9620-
9621-
- ${testId}
9622-
9623-
sha: ${_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha}
9624-
${_lib_constants_js__WEBPACK_IMPORTED_MODULE_3__/* .signiture */ .o}`;
9625-
await octokit.rest.issues.createComment({
9589+
if(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.eventName !== 'pull_request') {
9590+
console.log(`continue-on-error-comment is designed to be used with pull request and does not work with a [${_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.eventName}] event. We are ignoring this event.`);
9591+
} else {
9592+
try {
9593+
const myToken = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('repo-token', { required: true });
9594+
const outcome = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('outcome', { required: true });
9595+
const testId = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('test-id', { required: true });
9596+
9597+
if (outcome === 'failure') {
9598+
const octokit = (0,_actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit)(myToken);
9599+
const pullRequest = await (0,_lib_get_pull_request_js__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context, octokit);
9600+
9601+
const { data: comments } = await octokit.rest.issues.listComments({
96269602
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
96279603
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
96289604
issue_number: pullRequest.number,
9629-
body,
96309605
});
9606+
9607+
const existingComment = comments.find((comment) => comment.user.login === 'github-actions[bot]' && comment.body.endsWith(_lib_constants_js__WEBPACK_IMPORTED_MODULE_3__/* .signiture */ .o) && comment.body.includes(`sha: ${_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha}`));
9608+
9609+
if (existingComment) {
9610+
9611+
let body = existingComment.body.split('\n');
9612+
9613+
body.splice(body.length - 3, 0, `- ${testId}`);
9614+
9615+
await octokit.rest.issues.updateComment({
9616+
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
9617+
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
9618+
comment_id: existingComment.id,
9619+
body: body.join('\n'),
9620+
});
9621+
} else {
9622+
const body = `Some tests with 'continue-on-error: true' have failed:
9623+
9624+
- ${testId}
9625+
9626+
sha: ${_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha}
9627+
${_lib_constants_js__WEBPACK_IMPORTED_MODULE_3__/* .signiture */ .o}`;
9628+
await octokit.rest.issues.createComment({
9629+
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
9630+
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
9631+
issue_number: pullRequest.number,
9632+
body,
9633+
});
9634+
}
96319635
}
9632-
}
96339636

9634-
} catch (error) {
9635-
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed)(error.message);
9637+
} catch (error) {
9638+
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed)(error.message);
9639+
}
96369640
}
96379641
__webpack_handle_async_dependencies__();
96389642
}, 1);

index.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,55 @@ import getPullRequest from './lib/get-pull-request.js';
55

66
import { signiture } from './lib/constants.js';
77

8-
try {
9-
const myToken = getInput('repo-token', { required: true });
10-
const outcome = getInput('outcome', { required: true });
11-
const testId = getInput('test-id', { required: true });
12-
13-
if (outcome === 'failure') {
14-
const octokit = getOctokit(myToken);
15-
const pullRequest = await getPullRequest(context, octokit);
16-
17-
const { data: comments } = await octokit.rest.issues.listComments({
18-
owner: context.repo.owner,
19-
repo: context.repo.repo,
20-
issue_number: pullRequest.number,
21-
});
22-
23-
const existingComment = comments.find((comment) => comment.user.login === 'github-actions[bot]' && comment.body.endsWith(signiture) && comment.body.includes(`sha: ${context.sha}`));
24-
25-
if (existingComment) {
26-
27-
let body = existingComment.body.split('\n');
28-
29-
body.splice(body.length - 3, 0, `- ${testId}`);
30-
31-
await octokit.rest.issues.updateComment({
32-
owner: context.repo.owner,
33-
repo: context.repo.repo,
34-
comment_id: existingComment.id,
35-
body: body.join('\n'),
36-
});
37-
} else {
38-
const body = `Some tests with 'continue-on-error: true' have failed:
39-
40-
- ${testId}
41-
42-
sha: ${context.sha}
43-
${signiture}`;
44-
await octokit.rest.issues.createComment({
8+
if(context.eventName !== 'pull_request') {
9+
console.log(`continue-on-error-comment is designed to be used with pull request and does not work with a [${context.eventName}] event. We are ignoring this event.`);
10+
} else {
11+
try {
12+
const myToken = getInput('repo-token', { required: true });
13+
const outcome = getInput('outcome', { required: true });
14+
const testId = getInput('test-id', { required: true });
15+
16+
if (outcome === 'failure') {
17+
const octokit = getOctokit(myToken);
18+
const pullRequest = await getPullRequest(context, octokit);
19+
20+
const { data: comments } = await octokit.rest.issues.listComments({
4521
owner: context.repo.owner,
4622
repo: context.repo.repo,
4723
issue_number: pullRequest.number,
48-
body,
4924
});
25+
26+
const existingComment = comments.find((comment) => comment.user.login === 'github-actions[bot]' && comment.body.endsWith(signiture) && comment.body.includes(`sha: ${context.sha}`));
27+
28+
if (existingComment) {
29+
30+
let body = existingComment.body.split('\n');
31+
32+
body.splice(body.length - 3, 0, `- ${testId}`);
33+
34+
await octokit.rest.issues.updateComment({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
comment_id: existingComment.id,
38+
body: body.join('\n'),
39+
});
40+
} else {
41+
const body = `Some tests with 'continue-on-error: true' have failed:
42+
43+
- ${testId}
44+
45+
sha: ${context.sha}
46+
${signiture}`;
47+
await octokit.rest.issues.createComment({
48+
owner: context.repo.owner,
49+
repo: context.repo.repo,
50+
issue_number: pullRequest.number,
51+
body,
52+
});
53+
}
5054
}
51-
}
5255

53-
} catch (error) {
54-
setFailed(error.message);
56+
} catch (error) {
57+
setFailed(error.message);
58+
}
5559
}

pre-dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9647,7 +9647,7 @@ try {
96479647

96489648
} catch (error) {
96499649
// we want to ignore any failure at this stage but we will log it in case we need to debug something
9650-
console.log(error.message);
9650+
console.log(`Error during pre-run step: [${error.message}]`);
96519651
}
96529652
__webpack_handle_async_dependencies__();
96539653
}, 1);

pre.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ try {
3131

3232
} catch (error) {
3333
// we want to ignore any failure at this stage but we will log it in case we need to debug something
34-
console.log(error.message);
34+
console.log(`Error during pre-run step: [${error.message}]`);
3535
}

0 commit comments

Comments
 (0)