Skip to content

Commit 94a94b8

Browse files
committed
fix
1 parent 83f2ef5 commit 94a94b8

2 files changed

Lines changed: 66 additions & 28 deletions

File tree

.github/workflows/check_failed_tests.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ on:
3333
required: false
3434
type: string
3535
default: ''
36+
end_sha:
37+
description: "END_SHA to use for git bisect (bypasses automatic computation from PREV_WORKFLOW_RUN_ID)"
38+
required: false
39+
type: string
40+
default: ''
3641
only_process_job:
3742
description: "Skip find-commits jobs and only run the process job, fetching its artifacts from source_workflow_run_id"
3843
required: false
@@ -229,13 +234,17 @@ jobs:
229234
# (This is why we don't need to specify `workflow_id` which would be fetched automatically in the python script.)
230235
- name: Get `END_SHA` from previous CI runs of the same workflow
231236
working-directory: /transformers/utils
232-
if: ${{ inputs.pr_number == '' }}
237+
if: ${{ inputs.pr_number == '' && inputs.end_sha == '' }}
233238
env:
234239
ACCESS_TOKEN: ${{ secrets.ACCESS_REPO_INFO_TOKEN }}
235240
WORKFLOW_ID: ${{ steps.get-workflow-id.outputs.workflow_id }}
236241
run: |
237242
echo "END_SHA=$(TOKEN="$ACCESS_TOKEN" python3 -c 'import os; from get_previous_daily_ci import get_last_daily_ci_run_commit; commit=get_last_daily_ci_run_commit(token=os.environ["TOKEN"], workflow_run_id=os.environ["PREV_WORKFLOW_RUN_ID"], workflow_id=os.environ["WORKFLOW_ID"]); print(commit)')" >> $GITHUB_ENV
238243
244+
- name: Set `END_SHA` from input
245+
if: ${{ inputs.end_sha != '' }}
246+
run: echo "END_SHA=${{ inputs.end_sha }}" >> $GITHUB_ENV
247+
239248
# However, for workflow runs triggered by `issue_comment` (for pull requests), we want to check against the
240249
# parent commit (on `main`) of the `merge_commit` (dynamically created by GitHub). In this case, the goal is to
241250
# see if a reported failing test is actually ONLY failing on the `merge_commit`.

.github/workflows/post_trigger_check_new_failing_tests.yml

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
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

Comments
 (0)