-
Notifications
You must be signed in to change notification settings - Fork 24
Update CI to label-driven testing #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
d319d44
3ab6711
591fb7c
9e1db70
b3a515e
e757f41
54d72b8
46b1eac
3bb9723
fee2a13
b5095ca
182fb13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # Copyright (c) 2024-2026, Advanced Micro Devices, Inc. All rights reserved. | ||
| # | ||
| # See LICENSE for license information. | ||
|
|
||
| name: PR Automatic CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - 'dev' | ||
| - 'release_v2.*_rocm' | ||
| types: [ labeled, synchronize, reopened ] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: write | ||
|
|
||
| jobs: | ||
| determine_level: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| test_level: ${{ steps.set_level.outputs.test_level }} | ||
| steps: | ||
| - name: Determine CI dispatch from labels | ||
| id: set_level | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const parseLevelLabel = (labelName) => { | ||
| const label = (labelName || '').toLowerCase(); | ||
| if (label === 'ci-level 3') return 3; | ||
| if (label === 'ci-level 2') return 2; | ||
| if (label === 'ci-level 1') return 1; | ||
| return 0; | ||
| }; | ||
|
|
||
| const labels = (context.payload.pull_request.labels || []) | ||
| .map(label => parseLevelLabel(label.name)); | ||
| const action = context.payload.action; | ||
| const currentLevel = labels.length ? Math.max(...labels) : 0; | ||
|
|
||
| // Determine if a CI level label was added, and what level it was. | ||
| const addedLevel = action === 'labeled' ? parseLevelLabel(context.payload.label?.name) : 0; | ||
| if(addedLevel > 0){ | ||
| core.info(`Dispatch debug: action=${action}, addedLabel=${context.payload.label.name}, addedLevel=${addedLevel}, currentLevel=${currentLevel}, labels=[${labels.join(',')}]`); | ||
| } | ||
|
|
||
| let requiresDispatch = false; | ||
| if (action === 'labeled') { | ||
| // Only dispatch when the added CI-level label is now the highest level. | ||
| // Adding a lower-level label should not trigger a new run. | ||
| requiresDispatch = addedLevel > 0 && addedLevel === currentLevel; | ||
| core.info(`Dispatch debug: initial labeled decision requiresDispatch=${requiresDispatch}`); | ||
|
|
||
| // If an existing run for this PR/commit already satisfies the newly | ||
| // added level (same or higher), reuse it and do not dispatch again. | ||
| if (requiresDispatch) { | ||
| const prNumber = context.payload.pull_request.number; | ||
| const headSha = context.payload.pull_request.head.sha; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
|
|
||
| core.info(`Dispatch debug: checking existing runs for PR #${prNumber}, headSha=${headSha}`); | ||
|
|
||
| const runs = await github.paginate(github.rest.actions.listWorkflowRuns, { | ||
| owner, | ||
| repo, | ||
| workflow_id: 'rocm-ci-dispatch.yml', | ||
| per_page: 100, | ||
| head_sha: headSha, | ||
| }); | ||
|
|
||
| core.info(`Dispatch debug: total workflow runs fetched=${runs.length}`); | ||
|
|
||
| const candidateRuns = runs.filter(run => { | ||
| const prMatch = (run.pull_requests || []).some(pr => pr.number === prNumber); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to documentation this list contains all PR's with matching head_sha or head_branch so it does not help to associate the PR. IMHO the most precise matching is branch query parameter to match the PR target branch and head_sha and head_branch for the run both match the PR too.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you help me understand what scenario might this fail in specifically? I've updated it to only rely on the PR match + head sha. Is there a situation where that wouldn't be precise enough?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One scenario is base branch change for PR. And the other is target branch update - they do not directly affect PR code, so head_sha remains the same but test results may differ. |
||
| const completedNotSuccess = run.status === 'completed' && run.conclusion !== 'success'; | ||
| return prMatch && !completedNotSuccess; | ||
| }); | ||
|
|
||
| core.info(`Dispatch debug: candidate runs matching PR+sha=${candidateRuns.length}`); | ||
|
|
||
| let satisfiesAddedLevel = false; | ||
| for (const run of candidateRuns) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't run-name (CI Level) appear in github.rest.actions.listWorkflowRuns? |
||
| let detectedLevel = 0; | ||
|
|
||
| // Inspect called-workflow job names, which include level. | ||
| const jobsResp = await github.rest.actions.listJobsForWorkflowRun({ | ||
| owner, | ||
| repo, | ||
| run_id: run.id, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| for (const job of jobsResp.data.jobs || []) { | ||
| const m = (job.name || '').match(/(?:CI\s+)?Level\s*(\d+)/i); | ||
ipanfilo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (m) { | ||
| detectedLevel = Number(m[1]); | ||
| core.info(`Dispatch debug: run_id=${run.id}, job_id=${job.id}, job_name=${job.name}, detectedLevel=${detectedLevel}, threshold=${addedLevel}`); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (detectedLevel >= addedLevel) { | ||
| satisfiesAddedLevel = true; | ||
| core.info(`Dispatch debug: run_id=${run.id} satisfies added level; skipping new dispatch`); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (satisfiesAddedLevel) { | ||
| requiresDispatch = false; | ||
| } | ||
| core.info(`Dispatch debug: post-existing-run check requiresDispatch=${requiresDispatch}`); | ||
| } | ||
| } else if (action === 'synchronize' || action === 'reopened') { | ||
| requiresDispatch = currentLevel > 0; | ||
| } | ||
| core.info(`Dispatch debug: final requiresDispatch=${requiresDispatch}, output test_level=${requiresDispatch ? String(currentLevel) : ''}`); | ||
| core.setOutput('test_level', requiresDispatch ? String(currentLevel) : ''); | ||
|
|
||
| dispatch: | ||
| # Run this job if there is a valid level to test, which requires | ||
| # that any of the following are true: | ||
| # - A ci-level label higher than any existing ci-level label(s) was added | ||
| # - A commit was pushed with existing ci-level label(s) | ||
| # - The PR was reopened with existing ci-level label(s) | ||
| if: ${{ needs.determine_level.outputs.test_level != '' }} | ||
| needs: determine_level | ||
| name: CI Level ${{ needs.determine_level.outputs.test_level }} | ||
| uses: ./.github/workflows/rocm-ci.yml | ||
| with: | ||
| test_level: ${{ needs.determine_level.outputs.test_level }} | ||
Uh oh!
There was an error while loading. Please reload this page.