Skip to content

Commit 6ce766b

Browse files
committed
Leverage post-hook
1 parent ce992c6 commit 6ce766b

File tree

7 files changed

+36
-37
lines changed

7 files changed

+36
-37
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ inputs:
1212
github-token:
1313
description: Github Authentication token used to create the check through GitHub API
1414
required: true
15-
status:
16-
description: Status check status
17-
required: false
18-
conclusion:
19-
description: Status check conclusion
20-
required: false
15+
job-status:
16+
description: Job check status
17+
required: true
2118
external-id:
2219
description: Status check external ID
2320
required: false

.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: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,46 @@
11
const github = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
22
const core = require('@actions/core');
33

4+
const {GITHUB_REPOSITORY} = process.env;
5+
46
async function run() {
7+
if (core.getState('check-run-is-concluded').length) {
8+
core.info('Check run already concluded, skipping check run update');
9+
}
10+
11+
const [repoOwner, repoName] = GITHUB_REPOSITORY.split('/');
12+
/** INPUTS **/
13+
const jobStatus = core.getInput('job-status', {required: true});
514
const checkRunId = core.getState('check-run-id');
615
if (checkRunId.length === 0) {
716
throw new Error('Unable to retrieve check run id !');
817
}
18+
const githubToken = core.getInput('github-token', {required: true});
919

1020
const requestParams = await core.group(
1121
'Build API params',
1222
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),
23+
return {
24+
conclusion: jobStatus,
2225
owner: repoOwner,
23-
repo: repoName
26+
repo: repoName,
27+
check_run_id: checkRunId
2428
};
25-
if (!isEmpty(outputTitle) || !isEmpty(outputSummary)) {
26-
res.output = {title: undefinedIfEmpty(outputTitle), summary: undefinedIfEmpty(outputSummary)};
27-
}
28-
29-
return res;
3029
}
3130
);
3231
core.debug('API params=' + JSON.stringify(requestParams));
3332

34-
const apiResponse = await core.group('Call API', async () => {
33+
const apiResponse = await core.group('Retrieve ', async () => {
3534
const octokit = github.getOctokit(githubToken);
3635

37-
// @TODO Move back to `octokit.rest.checks.create()`
38-
const res = await octokit.request('POST /repos/{owner}/{repo}/check-runs', requestParams);
36+
// @TODO Move back to `octokit.rest.checks.update()`
37+
const res = await octokit.request('PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}', requestParams);
3938

4039
core.info('TMP DEBUG0 ' + JSON.stringify(res));
4140

4241
return res;
4342
});
4443
core.info('TMP DEBUG' + JSON.stringify(apiResponse));
45-
46-
core.setOutput('check-run-id', apiResponse.data.id);
4744
}
4845

4946
run();

.github/actions/reports-group/attach-check-run-to-triggering-workflow-action/src/main.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const github = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
22
const core = require('@actions/core');
33

4+
const {GITHUB_REPOSITORY} = process.env;
5+
46
async function run() {
5-
const {GITHUB_REPOSITORY: repository} = process.env;
6-
const [repoOwner, repoName] = repository.split('/');
7+
const [repoOwner, repoName] = GITHUB_REPOSITORY.split('/');
78
/** INPUTS **/
89
const commitSha = core.getInput('commit-sha', {required: true});
910
const checkName = core.getInput('name', {required: true});
1011
const githubToken = core.getInput('github-token', {required: true});
12+
const jobStatus = core.getInput('job-status', {required: true});
1113

1214
// Following inputs are not required and may not have any value attached !
13-
const checkStatus = core.getInput('status');
14-
const checkConclusion = core.getInput('conclusion');
1515
const externalId = core.getInput('external-id');
1616
const startedAt = core.getInput('started-at');
1717
const completedAt = core.getInput('completed-at');
1818
const detailsUrl = core.getInput('details-url');
1919
const outputTitle = core.getInput('output');
2020
const outputSummary = core.getInput('output-summary');
2121

22+
const isSuccessfulJobAsOfNow = 'success' === jobStatus;
23+
2224
const requestParams = await core.group(
2325
'Build API params',
2426
async () => {
@@ -27,8 +29,8 @@ async function run() {
2729
head_sha: commitSha,
2830
details_url: undefinedIfEmpty(detailsUrl),
2931
external_id: undefinedIfEmpty(externalId),
30-
status: undefinedIfEmpty(checkStatus),
31-
conclusion: undefinedIfEmpty(checkConclusion),
32+
status: isSuccessfulJobAsOfNow ? 'in_progress' : 'completed',
33+
conclusion: isSuccessfulJobAsOfNow ? undefined : jobStatus,
3234
started_at: undefinedIfEmpty(startedAt),
3335
completed_at: undefinedIfEmpty(completedAt),
3436
owner: repoOwner,
@@ -57,6 +59,9 @@ async function run() {
5759

5860
core.setOutput('check-run-id', apiResponse.data.id);
5961
core.saveState('check-run-id', apiResponse.data.id); // In order to use it during POST hook
62+
if (true === isSuccessfulJobAsOfNow) {
63+
core.saveState('check-run-already-concluded', 'yes'); // In order to use it during POST hook
64+
}
6065
}
6166

6267
/**

.github/workflows/codacy-upload-from-artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
name: "${{ github.workflow }} (${{ github.event.workflow.name}}) / Codacy / Upload all reports"
5151
commit-sha: "${{ ('workflow_run' == github.event_name && ('pull_request' == github.event.workflow_run.event || 'push' == github.event.workflow_run.event) && github.event.workflow_run.head_sha) || ('pull_request' == github.event_name && github.event.pull_request.head.sha) || ('push' == github.event_name && github.sha) || null }}"
5252
github-token: ${{ github.token }}
53-
status: queued
53+
job-status: ${{ job.status }}
5454

5555
- name: Download artifacts
5656
uses: actions/download-artifact@v4

.github/workflows/codecov-upload-from-artifacts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
name: "${{ github.workflow }} (${{ github.event.workflow.name}}) / Codecov / Prepare"
4343
commit-sha: "${{ ('workflow_run' == github.event_name && ('pull_request' == github.event.workflow_run.event || 'push' == github.event.workflow_run.event) && github.event.workflow_run.head_sha) || ('pull_request' == github.event_name && github.event.pull_request.head.sha) || ('push' == github.event_name && github.sha) || null }}"
4444
github-token: ${{ github.token }}
45-
status: queued
45+
job-status: ${{ job.status }}
4646

4747
- name: Download artifacts
4848
uses: actions/download-artifact@v4
@@ -129,7 +129,7 @@ jobs:
129129
name: "${{ github.workflow }} (${{ github.event.workflow.name}}) / Codecov / ${{ matrix.artifact}} - ${{ matrix.path }}"
130130
commit-sha: "${{ ('workflow_run' == github.event_name && ('pull_request' == github.event.workflow_run.event || 'push' == github.event.workflow_run.event) && github.event.workflow_run.head_sha) || ('pull_request' == github.event_name && github.event.pull_request.head.sha) || ('push' == github.event_name && github.sha) || null }}"
131131
github-token: ${{ github.token }}
132-
status: queued
132+
job-status: ${{ job.status }}
133133

134134
- name: Download '${{ matrix.artifact }}' artifact
135135
uses: actions/download-artifact@v4

0 commit comments

Comments
 (0)