Skip to content

Commit 45c04a6

Browse files
committed
Leverage post-hook
1 parent ce992c6 commit 45c04a6

File tree

7 files changed

+32
-37
lines changed

7 files changed

+32
-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.

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

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,43 @@ const github = require('@actions/github'); // @TODO move to 'imports from' when
22
const core = require('@actions/core');
33

44
async function run() {
5+
if (core.getState('check-run-is-concluded').length) {
6+
core.info('Check run already concluded, skipping check run update');
7+
}
8+
9+
const [repoOwner, repoName] = process.env.repository.split('/');
10+
/** INPUTS **/
11+
const jobStatus = core.getInput('job-status', {required: true});
512
const checkRunId = core.getState('check-run-id');
613
if (checkRunId.length === 0) {
714
throw new Error('Unable to retrieve check run id !');
815
}
16+
const githubToken = core.getInput('github-token', {required: true});
917

1018
const requestParams = await core.group(
1119
'Build API params',
1220
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),
21+
return {
22+
conclusion: jobStatus,
2223
owner: repoOwner,
23-
repo: repoName
24+
repo: repoName,
25+
check_run_id: checkRunId
2426
};
25-
if (!isEmpty(outputTitle) || !isEmpty(outputSummary)) {
26-
res.output = {title: undefinedIfEmpty(outputTitle), summary: undefinedIfEmpty(outputSummary)};
27-
}
28-
29-
return res;
3027
}
3128
);
3229
core.debug('API params=' + JSON.stringify(requestParams));
3330

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

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

4037
core.info('TMP DEBUG0 ' + JSON.stringify(res));
4138

4239
return res;
4340
});
4441
core.info('TMP DEBUG' + JSON.stringify(apiResponse));
45-
46-
core.setOutput('check-run-id', apiResponse.data.id);
4742
}
4843

4944
run();

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ const github = require('@actions/github'); // @TODO move to 'imports from' when
22
const core = require('@actions/core');
33

44
async function run() {
5-
const {GITHUB_REPOSITORY: repository} = process.env;
6-
const [repoOwner, repoName] = repository.split('/');
5+
const [repoOwner, repoName] = process.env.GITHUB_REPOSITORY.split('/');
76
/** INPUTS **/
87
const commitSha = core.getInput('commit-sha', {required: true});
98
const checkName = core.getInput('name', {required: true});
109
const githubToken = core.getInput('github-token', {required: true});
10+
const jobStatus = core.getInput('job-status', {required: true});
1111

1212
// Following inputs are not required and may not have any value attached !
13-
const checkStatus = core.getInput('status');
14-
const checkConclusion = core.getInput('conclusion');
1513
const externalId = core.getInput('external-id');
1614
const startedAt = core.getInput('started-at');
1715
const completedAt = core.getInput('completed-at');
1816
const detailsUrl = core.getInput('details-url');
1917
const outputTitle = core.getInput('output');
2018
const outputSummary = core.getInput('output-summary');
2119

20+
const isSuccessfulJobAsOfNow = 'success' === jobStatus;
21+
2222
const requestParams = await core.group(
2323
'Build API params',
2424
async () => {
@@ -27,8 +27,8 @@ async function run() {
2727
head_sha: commitSha,
2828
details_url: undefinedIfEmpty(detailsUrl),
2929
external_id: undefinedIfEmpty(externalId),
30-
status: undefinedIfEmpty(checkStatus),
31-
conclusion: undefinedIfEmpty(checkConclusion),
30+
status: isSuccessfulJobAsOfNow ? 'in_progress' : 'completed',
31+
conclusion: isSuccessfulJobAsOfNow ? undefined : jobStatus,
3232
started_at: undefinedIfEmpty(startedAt),
3333
completed_at: undefinedIfEmpty(completedAt),
3434
owner: repoOwner,
@@ -57,6 +57,9 @@ async function run() {
5757

5858
core.setOutput('check-run-id', apiResponse.data.id);
5959
core.saveState('check-run-id', apiResponse.data.id); // In order to use it during POST hook
60+
if (true === isSuccessfulJobAsOfNow) {
61+
core.saveState('check-run-already-concluded', 'yes'); // In order to use it during POST hook
62+
}
6063
}
6164

6265
/**

.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)