Skip to content

Commit ce992c6

Browse files
committed
Add post hook
1 parent c7aa769 commit ce992c6

File tree

6 files changed

+136
-76
lines changed

6 files changed

+136
-76
lines changed

.github/actions/reports-group/attach-check-run-to-triggering-workflow-action/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ outputs:
4444
runs:
4545
using: 'node20'
4646
main: 'dist/index.js'
47+
post: 'dist/index.js'

.github/actions/reports-group/attach-check-run-to-triggering-workflow-action/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/attach-check-run-to-triggering-workflow-action/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,7 @@
1-
const github = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
2-
const core = require('@actions/core');
1+
const core = require("@actions/core"); // @TODO move to 'imports from' when moved to TS !
32

4-
async function run() {
5-
const {GITHUB_REPOSITORY: repository} = process.env;
6-
const [repoOwner, repoName] = repository.split('/');
7-
/** INPUTS **/
8-
const commitSha = core.getInput('commit-sha', {required: true});
9-
const checkName = core.getInput('name', {required: true});
10-
const githubToken = core.getInput('github-token', {required: true});
11-
12-
// Following inputs are not required and may not have any value attached !
13-
const checkStatus = core.getInput('status');
14-
const checkConclusion = core.getInput('conclusion');
15-
const externalId = core.getInput('external-id');
16-
const startedAt = core.getInput('started-at');
17-
const completedAt = core.getInput('completed-at');
18-
const detailsUrl = core.getInput('details-url');
19-
const outputTitle = core.getInput('output');
20-
const outputSummary = core.getInput('output-summary');
21-
22-
const requestParams = await core.group(
23-
'Build API params',
24-
async () => {
25-
const res = {
26-
name: checkName,
27-
head_sha: commitSha,
28-
details_url: undefinedIfEmpty(detailsUrl),
29-
external_id: undefinedIfEmpty(externalId),
30-
status: undefinedIfEmpty(checkStatus),
31-
conclusion: undefinedIfEmpty(checkConclusion),
32-
started_at: undefinedIfEmpty(startedAt),
33-
completed_at: undefinedIfEmpty(completedAt),
34-
};
35-
if (!isEmpty(outputTitle) || !isEmpty(outputSummary)) {
36-
res.output = {title: undefinedIfEmpty(outputTitle), summary: undefinedIfEmpty(outputSummary)};
37-
}
38-
39-
return res;
40-
}
41-
);
42-
core.debug('API params=' + JSON.stringify(requestParams));
43-
44-
const apiResponse = await core.group('Call API', async () => {
45-
const octokit = github.getOctokit(githubToken);
46-
47-
// @TODO Move back to `octokit.rest.checks.create()`
48-
const res = await octokit.request('POST /repos/' + repoOwner+ '/' + repoName + '/check-runs', requestParams);
49-
50-
core.info('TMP DEBUG0 ' + JSON.stringify(res));
51-
52-
return res;
53-
});
54-
core.info('TMP DEBUG' + JSON.stringify(apiResponse));
55-
56-
core.setOutput('check-run-id', apiResponse.data.id);
57-
}
58-
59-
/**
60-
* @param {string} val
61-
*
62-
* @returns {string|undefined}
63-
*/
64-
function undefinedIfEmpty(val) {
65-
return !isEmpty(val) ? val : undefined
66-
}
67-
/**
68-
* @param {string} val
69-
*
70-
* @returns {boolean}
71-
*/
72-
function isEmpty(val) {
73-
return val.trim().length === 0;
3+
if (!!core.getState('check-run-id')) {
4+
require('./src/cleanup');
5+
} else {
6+
require('./src/main');
747
}
75-
76-
run();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const github = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
2+
const core = require('@actions/core');
3+
4+
async function run() {
5+
const checkRunId = core.getState('check-run-id');
6+
if (checkRunId.length === 0) {
7+
throw new Error('Unable to retrieve check run id !');
8+
}
9+
10+
const requestParams = await core.group(
11+
'Build API params',
12+
async () => {
13+
const res = {
14+
name: checkName,
15+
head_sha: commitSha,
16+
details_url: undefinedIfEmpty(detailsUrl),
17+
external_id: undefinedIfEmpty(externalId),
18+
status: undefinedIfEmpty(checkStatus),
19+
conclusion: undefinedIfEmpty(checkConclusion),
20+
started_at: undefinedIfEmpty(startedAt),
21+
completed_at: undefinedIfEmpty(completedAt),
22+
owner: repoOwner,
23+
repo: repoName
24+
};
25+
if (!isEmpty(outputTitle) || !isEmpty(outputSummary)) {
26+
res.output = {title: undefinedIfEmpty(outputTitle), summary: undefinedIfEmpty(outputSummary)};
27+
}
28+
29+
return res;
30+
}
31+
);
32+
core.debug('API params=' + JSON.stringify(requestParams));
33+
34+
const apiResponse = await core.group('Call API', async () => {
35+
const octokit = github.getOctokit(githubToken);
36+
37+
// @TODO Move back to `octokit.rest.checks.create()`
38+
const res = await octokit.request('POST /repos/{owner}/{repo}/check-runs', requestParams);
39+
40+
core.info('TMP DEBUG0 ' + JSON.stringify(res));
41+
42+
return res;
43+
});
44+
core.info('TMP DEBUG' + JSON.stringify(apiResponse));
45+
46+
core.setOutput('check-run-id', apiResponse.data.id);
47+
}
48+
49+
run();
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const github = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
2+
const core = require('@actions/core');
3+
4+
async function run() {
5+
const {GITHUB_REPOSITORY: repository} = process.env;
6+
const [repoOwner, repoName] = repository.split('/');
7+
/** INPUTS **/
8+
const commitSha = core.getInput('commit-sha', {required: true});
9+
const checkName = core.getInput('name', {required: true});
10+
const githubToken = core.getInput('github-token', {required: true});
11+
12+
// Following inputs are not required and may not have any value attached !
13+
const checkStatus = core.getInput('status');
14+
const checkConclusion = core.getInput('conclusion');
15+
const externalId = core.getInput('external-id');
16+
const startedAt = core.getInput('started-at');
17+
const completedAt = core.getInput('completed-at');
18+
const detailsUrl = core.getInput('details-url');
19+
const outputTitle = core.getInput('output');
20+
const outputSummary = core.getInput('output-summary');
21+
22+
const requestParams = await core.group(
23+
'Build API params',
24+
async () => {
25+
const res = {
26+
name: checkName,
27+
head_sha: commitSha,
28+
details_url: undefinedIfEmpty(detailsUrl),
29+
external_id: undefinedIfEmpty(externalId),
30+
status: undefinedIfEmpty(checkStatus),
31+
conclusion: undefinedIfEmpty(checkConclusion),
32+
started_at: undefinedIfEmpty(startedAt),
33+
completed_at: undefinedIfEmpty(completedAt),
34+
owner: repoOwner,
35+
repo: repoName
36+
};
37+
if (!isEmpty(outputTitle) || !isEmpty(outputSummary)) {
38+
res.output = {title: undefinedIfEmpty(outputTitle), summary: undefinedIfEmpty(outputSummary)};
39+
}
40+
41+
return res;
42+
}
43+
);
44+
core.debug('API params=' + JSON.stringify(requestParams));
45+
46+
const apiResponse = await core.group('Call API', async () => {
47+
const octokit = github.getOctokit(githubToken);
48+
49+
// @TODO Move back to `octokit.rest.checks.create()`
50+
const res = await octokit.request('POST /repos/{owner}/{repo}/check-runs', requestParams);
51+
52+
core.info('TMP DEBUG0 ' + JSON.stringify(res));
53+
54+
return res;
55+
});
56+
core.info('TMP DEBUG' + JSON.stringify(apiResponse));
57+
58+
core.setOutput('check-run-id', apiResponse.data.id);
59+
core.saveState('check-run-id', apiResponse.data.id); // In order to use it during POST hook
60+
}
61+
62+
/**
63+
* @param {string} val
64+
*
65+
* @returns {string|undefined}
66+
*/
67+
function undefinedIfEmpty(val) {
68+
return !isEmpty(val) ? val : undefined
69+
}
70+
/**
71+
* @param {string} val
72+
*
73+
* @returns {boolean}
74+
*/
75+
function isEmpty(val) {
76+
return val.trim().length === 0;
77+
}
78+
79+
run();

0 commit comments

Comments
 (0)