3535 outputs :
3636 source_workflow_run_id : ${{ steps.resolve.outputs.source_workflow_run_id }}
3737 only_process_job : ${{ steps.resolve.outputs.only_process_job }}
38+ end_sha : ${{ steps.fetch-end-sha.outputs.end_sha }}
3839 docker : ${{ steps.fetch-inputs.outputs.docker }}
3940 job : ${{ steps.fetch-inputs.outputs.job }}
4041 slack_report_channel : ${{ steps.fetch-inputs.outputs.slack_report_channel }}
@@ -124,46 +125,74 @@ jobs:
124125 core.setOutput(key, value);
125126 }
126127
127- // --- Extract END_SHA from env of "Check failed tests" step ---
128+ - name : Fetch END_SHA from source run job log
129+ id : fetch-end-sha
130+ uses : actions/github-script@v6
131+ with :
132+ script : |
133+ const sourceRunId = parseInt('${{ steps.resolve.outputs.source_workflow_run_id }}');
134+ const jobName = `${{ inputs.job_name || env.job_name }}`;
135+ const targetJobPrefix = `${jobName} / Check new failures / Find commits for new failing tests`;
136+
137+ // Find any matrix instance — they all share the same END_SHA
138+ let targetJobId = null;
139+ let page = 1;
140+ while (true) {
141+ const { data } = await github.rest.actions.listJobsForWorkflowRun({
142+ owner: context.repo.owner,
143+ repo: context.repo.repo,
144+ run_id: sourceRunId,
145+ per_page: 100,
146+ page: page,
147+ });
148+ const job = data.jobs.find(j => j.name.startsWith(targetJobPrefix));
149+ if (job) {
150+ targetJobId = job.id;
151+ break;
152+ }
153+ if (data.jobs.length < 100) break;
154+ page++;
155+ }
156+
157+ if (!targetJobId) {
158+ core.warning(`No "Find commits for new failing tests" job found in run ${sourceRunId}. END_SHA will be computed automatically.`);
159+ return;
160+ }
161+
162+ const logResponse = await github.rest.actions.downloadJobLogsForWorkflowRun({
163+ owner: context.repo.owner,
164+ repo: context.repo.repo,
165+ job_id: targetJobId,
166+ });
167+
168+ const logText = logResponse.data;
128169 let endSha = null;
129170 let inTargetStep = false;
130171 let inEnvBlock = false;
131- let stepDepth = 0;
132-
172+
133173 for (const line of logText.split('\n')) {
134174 const content = line.replace(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z /, '');
135-
136- if (content.includes('##[group]') ) {
137- if (content.includes('check_bad_commit.py')) {
138- inTargetStep = true;
139- stepDepth = 1;
140- continue;
141- } else if (inTargetStep) {
142- stepDepth++;
143- }
144- }
145-
146- if (!inTargetStep) continue;
147-
148- if (content.includes('##[endgroup]')) {
149- stepDepth--;
150- if (stepDepth <= 0) break; // exited the step
151- inEnvBlock = false;
175+
176+ if (content.includes('##[group]') && content.includes('check_bad_commit.py')) {
177+ inTargetStep = true;
152178 continue;
153179 }
154-
180+
181+ if (!inTargetStep) continue;
182+
183+ if (content.includes('##[endgroup]')) break;
184+
155185 if (content.trim() === 'env:') {
156186 inEnvBlock = true;
157187 continue;
158188 }
159-
189+
160190 if (inEnvBlock) {
161191 const match = content.match(/^\s+END_SHA:\s*(.+)/);
162192 if (match) {
163193 endSha = match[1].trim();
164194 break;
165195 }
166- // stop if we've left the env block (next non-indented line)
167196 if (content.trim() && !content.startsWith(' ')) {
168197 inEnvBlock = false;
169198 }
@@ -172,12 +201,11 @@ jobs:
172201
173202 if (endSha) {
174203 console.log(`END_SHA: ${endSha}`);
175- core.setOutput('END_SHA ', endSha);
204+ core.setOutput('end_sha ', endSha);
176205 } else {
177- core.warning('Could not find END_SHA in the "Check failed tests" step env block.');
206+ core.warning('Could not find END_SHA in the "Check failed tests" step env block. END_SHA will be computed automatically. ');
178207 }
179208
180-
181209 check_new_failures :
182210 name : Check new failures
183211 needs : prepare
@@ -191,6 +219,7 @@ jobs:
191219 commit_sha : ${{ needs.prepare.outputs.commit_sha }}
192220 pr_number : ${{ needs.prepare.outputs.pr_number }}
193221 max_num_runners : ${{ fromJSON(needs.prepare.outputs.max_num_runners) }}
194- source_workflow_run_id : ${{ needs.prepare.outputs.source_workflow_run_id }}
222+ source_run_id : ${{ needs.prepare.outputs.source_workflow_run_id }}
223+ end_sha : ${{ needs.prepare.outputs.end_sha }}
195224 only_process_job : ${{ fromJSON(needs.prepare.outputs.only_process_job) }}
196225 secrets : inherit
0 commit comments