@@ -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 ( ) ,
0 commit comments