Skip to content

Commit 01cec59

Browse files
committed
Improve
1 parent f142699 commit 01cec59

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

.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/main.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,27 @@ function guessTriggeringRunId() {
5656
}
5757

5858
/**
59-
* @param octokit
60-
* @param owner
61-
* @param repo
62-
* @param runId
6359
* @returns {Promise<Record<string, any>|undefined>}
6460
*/
65-
async function guessCurrentJob(octokit, owner, repo, runId) {
61+
async function retrieveCurrentJob(octokit, owner, repo, runId) {
6662
const jobList = await getWorkflowJobsForRunId(octokit, owner, repo, runId);
6763
core.info('TMP DEBUG jobsForCurrentWorkflow=' + JSON.stringify(jobList));
6864
const candidateList = [];
6965
for (const job of jobList) {
70-
if (RUNNER_NAME === job.runner_name) {
66+
if (RUNNER_NAME === job.runner_name && 'in_progress' === job.status) {
7167
candidateList.push(job);
7268
}
7369
}
70+
if (candidateList.length === 0) {
71+
core.info('Unable to retrieve the current job !');
72+
return undefined;
73+
}
7474
if (candidateList.length > 1) {
75-
core.warning('Multiple jobs rely on runners with the same name, first job one will be used !');
75+
core.warning(
76+
'Multiple running jobs rely on runners with the same name, unable to retrieve the current job !'
77+
+ '\nCandidates: ' + Object.entries(candidateList).map(([k, v]) => v.name + '(' + k + ')').join(', ')
78+
);
79+
return undefined;
7680
}
7781

7882
return candidateList.shift();
@@ -120,7 +124,7 @@ async function run() {
120124
core.info('TMP DEBUG RUNNER_ARCH=' + process.env.RUNNER_ARCH);
121125
core.info('TMP DEBUG RUNNER_NAME=' + process.env.RUNNER_NAME);
122126
core.info('TMP DEBUG RUNNER_OS=' + process.env.RUNNER_OS);
123-
const currentJob = await guessCurrentJob(octokit, repoInfo.owner, repoInfo.repo, github.context.runId);
127+
const currentJob = await retrieveCurrentJob(octokit, repoInfo.owner, repoInfo.repo, github.context.runId);
124128
core.info('TMP DEBUG CURRENT JOB=' + JSON.stringify(currentJob));
125129
const commitSha = guessTriggeringCommitSha();
126130
const startedAt = (new Date()).toISOString();
@@ -129,15 +133,13 @@ async function run() {
129133
const currentWorkflowName = github.context.workflow;
130134
const outputTitle = '🔔 ' + currentWorkflowName;
131135
const currentWorkflowUrl = github.context.serverUrl + '/' + GITHUB_REPOSITORY + '/actions/runs/' + github.context.runId.toString() + (undefined !== prNumber ? '?pr=' + prNumber : '');
132-
const outputSummary = '🪢 Check added by <a href="' + currentWorkflowUrl + '" target="blank">**' + currentWorkflowName + '** workflow</a>'
133-
+ (currentJob ? ' (<a href="' + currentJob.html_url + '" target="blank">**' + currentJob.name + '**</a>)' : '')
136+
const outputSummary = '🪢 Check added by '
137+
+ (currentJob ? '<a href="' + currentJob.html_url + '" target="blank">**' + currentJob.name + '**</a>' : '')
138+
+ (currentJob ? ' (' : '') + '<a href="' + currentWorkflowUrl + '" target="blank">**' + currentWorkflowName + '** workflow</a>' + (currentJob ? ')' : '')
134139
;
135-
if (!checkName && !currentJob) {
136-
core.setFailed('Unable to guess the current job name, you must specify the check name !');
137-
}
138140

139141
return {
140-
name: !checkName ? currentJob.name : checkName,
142+
name: checkName ? checkName : (currentJob?.name ?? currentWorkflowName + ' Check run'),
141143
head_sha: commitSha,
142144
//details_url: detailsUrl,
143145
external_id: triggeringWorkflowRunId?.toString(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939

4040
- uses: ./custom-action-repo/.github/actions/reports-group/attach-check-run-to-triggering-workflow-action
4141
with:
42+
name: "My custom check"
4243
github-token: ${{ github.token }}
4344
job-status: ${{ job.status }}
4445

@@ -124,7 +125,6 @@ jobs:
124125

125126
- uses: ./custom-action-repo/.github/actions/reports-group/attach-check-run-to-triggering-workflow-action
126127
with:
127-
name: "Codecov / ${{ matrix.artifact }} - ${{ matrix.path }}"
128128
github-token: ${{ github.token }}
129129
job-status: ${{ job.status }}
130130

0 commit comments

Comments
 (0)