-
Notifications
You must be signed in to change notification settings - Fork 23
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
Open
Micky774
wants to merge
10
commits into
dev
Choose a base branch
from
zain/ci
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+219
−9
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d319d44
Initial commit
Micky774 3ab6711
Disabled lvl 1 flow when lvl 3 is used
Micky774 591fb7c
Made workflows mutually exclusive
Micky774 9e1db70
Updated with general label-driven level system
Micky774 b3a515e
Restore automatic testing on dev/release push
Micky774 e757f41
Added inline comments, updated workflow names
Micky774 54d72b8
Added clarification on dispatch
Micky774 46b1eac
Streamlined cancel script updated build and test name
Micky774 3bb9723
Refactored dispatch to simplify and catch unlabel edge-case
Micky774 fee2a13
Updated to cull dispatch on unlabel when test already run
Micky774 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| # 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, unlabeled, synchronize, reopened ] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: write | ||
|
|
||
| jobs: | ||
| determine_level: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| test_level: ${{ steps.set_level.outputs.test_level }} | ||
| current_level: ${{ steps.set_level.outputs.current_level }} | ||
| should_cancel_others: ${{ steps.set_level.outputs.should_cancel_others }} | ||
| 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 => label.name.toLowerCase()); | ||
| const action = context.payload.action; | ||
|
|
||
| // Determine if a CI level label was removed or added, and what level it was | ||
| const addedLevel = action === 'labeled' ? parseLevelLabel(context.payload.label?.name) : 0; | ||
| const removedLevel = action === 'unlabeled' ? parseLevelLabel(context.payload.label?.name) : 0; | ||
|
|
||
| // Determine the current highest CI level from remaining labels | ||
| let level = ''; | ||
| if (labels.includes('ci-level 3')) level = '3'; | ||
| else if (labels.includes('ci-level 2')) level = '2'; | ||
| else if (labels.includes('ci-level 1')) level = '1'; | ||
|
|
||
| // Check if the removed level was higher than the current level | ||
| const currentLevel = level ? Number(level) : 0; | ||
| const removedWasHighest = removedLevel > currentLevel; | ||
|
|
||
| let requires_dispatch = currentLevel > 0; | ||
| if (action === 'labeled') { | ||
| // Only dispatch when a CI-level label was added. | ||
| requires_dispatch &&= addedLevel > 0; | ||
| } else if (action === 'unlabeled') { | ||
| // Only dispatch downgrade when the removed label was the highest, | ||
| // and the now-highest level (if any) does not have a completed run. | ||
| requires_dispatch &&= removedWasHighest; | ||
| } | ||
| // For unlabeling, only dispatch downgrade if the removed level was highest | ||
| // and the now-highest remaining level is not already satisfied for this commit. | ||
| 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; | ||
|
|
||
| if (action === 'unlabeled' && requires_dispatch) { | ||
| const runs = await github.paginate(github.rest.actions.listWorkflowRuns, { | ||
| owner, | ||
| repo, | ||
| workflow_id: 'rocm-ci-dispatch.yml', | ||
| event: 'pull_request', | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const nextHighestAlreadyCompleted = runs.some(run => { | ||
| const prMatch = (run.pull_requests || []).some(pr => pr.number === prNumber); | ||
| const sameSha = run.head_sha === headSha; | ||
| const completed = run.status === 'completed'; | ||
| const title = run.display_title || ''; | ||
| const match = title.match(/CI Level (\d+)/i); | ||
| const runLevel = match ? Number(match[1]) : 0; | ||
| return prMatch && sameSha && completed && runLevel >= currentLevel; | ||
| }); | ||
|
|
||
| if (nextHighestAlreadyCompleted) { | ||
| requires_dispatch = false; | ||
| } | ||
| } | ||
| let test_level = requires_dispatch ? level : ''; | ||
| core.setOutput('test_level', test_level); | ||
| core.setOutput('current_level', String(currentLevel)); | ||
| const shouldCancelOthers = (test_level !== '') || (action === 'unlabeled' && removedWasHighest); | ||
| core.setOutput('should_cancel_others', shouldCancelOthers ? 'true' : 'false'); | ||
|
|
||
| cancel_others: | ||
| # Run this job if we might need to cancel running workflows, which happens when: | ||
| # - We determined that we need to dispatch a workflow | ||
| # - The highest CI-level label was removed | ||
| if: ${{ needs.determine_level.outputs.should_cancel_others == 'true' }} | ||
| needs: determine_level | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Cancel queued/in-progress runs | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| CURRENT_LEVEL: ${{ needs.determine_level.outputs.current_level }} | ||
| with: | ||
| script: | | ||
| const action = context.payload.action; | ||
| if (action === 'reopened') { | ||
| return; | ||
| } | ||
|
|
||
| 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; | ||
| }; | ||
|
|
||
| // Cancel other runs for the same PR that are queued or | ||
| // in progress and have a lower CI level | ||
| const prNumber = context.payload.pull_request.number; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const currentRunId = context.runId; | ||
| const currentLevel = Number(process.env.CURRENT_LEVEL || 0); | ||
| // If a label was added, determine its level to compare against other runs | ||
| const addedLevel = action === 'labeled' ? parseLevelLabel(context.payload.label?.name) : 0; | ||
| const removedLevel = action === 'unlabeled' ? parseLevelLabel(context.payload.label?.name) : 0; | ||
|
|
||
| // Fetch all workflow runs for this workflow and PR | ||
| const runs = await github.rest.actions.listWorkflowRuns({ | ||
| owner, | ||
| repo, | ||
| workflow_id: 'rocm-ci-dispatch.yml', | ||
| event: 'pull_request', | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| // Filter runs to find those that are for the same PR, | ||
| // are queued or in progress, and have a lower CI level | ||
| const toCancel = runs.data.workflow_runs.filter(run => { | ||
| const prMatch = (run.pull_requests || []).some(pr => pr.number === prNumber); | ||
| const active = run.status === 'queued' || run.status === 'in_progress'; | ||
ipanfilo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // In general, don't cancel yourself or inactive/irrelevant PRs | ||
| if (run.id === currentRunId || !(prMatch && active)) { | ||
| return false; | ||
| } | ||
| // Always cancel others when updating commits | ||
| if (action === 'synchronize') { | ||
|
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. reopened action does not seem handled in this code
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. Now handled as an early-skip |
||
| return true; | ||
| } | ||
| // For labeled/unlabeled actions, compare the CI levels | ||
| const title = run.display_title || ''; | ||
| const match = title.match(/CI Level (\d+)/i); | ||
| const runLevel = match ? Number(match[1]) : 0; | ||
| // If a label was added, cancel runs with a lower level than the added label | ||
| if (action === 'labeled') { | ||
| return runLevel < addedLevel; | ||
| } | ||
| // If last CI label was removed, cancel all active CI-level runs. | ||
| if (action === 'unlabeled' && currentLevel === 0 && removedLevel > 0) { | ||
| return runLevel > 0; | ||
| } | ||
| // If a label was removed, cancel runs with a lower level than the current level | ||
| return runLevel < currentLevel; | ||
| }); | ||
|
|
||
| // Cancel the identified runs | ||
| for (const run of toCancel) { | ||
| core.info(`Canceling dispatch run ${run.id} for PR #${prNumber}`); | ||
| await github.rest.actions.cancelWorkflowRun({ | ||
| owner, | ||
| repo, | ||
| run_id: run.id, | ||
| }); | ||
| } | ||
|
|
||
| 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 was added | ||
| # - A commit was pushed with existing ci-level label(s) | ||
| # - The PR was reopened with existing ci-level label(s) | ||
| # - The highest ci-level label was removed with remaining ci-level label(s) | ||
| if: ${{ needs.determine_level.outputs.test_level != '' }} | ||
| needs: [determine_level, cancel_others] | ||
| name: CI Level ${{ needs.determine_level.outputs.test_level }} | ||
| uses: ./.github/workflows/rocm-ci.yml | ||
| with: | ||
| test_level: ${{ needs.determine_level.outputs.test_level }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.