-
Notifications
You must be signed in to change notification settings - Fork 93
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
Fix failed run count logic for alerting test failures #7554
Open
youngbupark
wants to merge
13
commits into
radius-project:main
Choose a base branch
from
youngbupark:youngp/fix-condition
base: main
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.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fc095c6
do not count in_process run
youngbupark 2ea0a81
wip
youngbupark 012d724
wip
youngbupark 54582c7
revert
youngbupark d6ee198
use composite pattern
youngbupark d0cdf40
wip
youngbupark b147b9c
wip
youngbupark 79c1000
wip
youngbupark 7e2a07a
wip
youngbupark 7cfc2d0
wip
youngbupark 4c4ee62
test
youngbupark 98852b2
fix all
youngbupark e9b3484
revert
youngbupark 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 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,65 @@ | ||
name: "Count completed failed runs" | ||
description: This actions counts the number of consecutive failed runs for a given workflow. | ||
inputs: | ||
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. This is validated by this workflow run - https://github.com/radius-project/radius/actions/runs/8865909289/job/24342699250 |
||
workflow_id: | ||
description: 'Workflow ID to use for counting failed runs' | ||
required: true | ||
workflow_event: | ||
description: 'Maximum number of workflow runs to check' | ||
default: 'schedule' | ||
required: false | ||
per_page: | ||
description: 'Number of workflow runs to check for failures' | ||
default: '10' | ||
required: false | ||
outputs: | ||
total_runs: | ||
value: ${{ steps.count_failures.outputs.result }} | ||
description: The number of consecutive failed runs | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Count recently failed tests | ||
id: count_failures | ||
uses: actions/github-script@v7 | ||
env: | ||
WORKFLOWID: ${{ inputs.workflow_id }} | ||
PERPAGE: ${{ inputs.per_page }} | ||
WORKFLOWEVENT: ${{ inputs.workflow_event }} | ||
with: | ||
script: | | ||
workflowid = process.env.WORKFLOWID; | ||
perpage = parseInt(process.env.PERPAGE, 10); | ||
workflowevent = process.env.WORKFLOWEVENT; | ||
|
||
console.log("workflow ID: " + workflowid + ", event: " + workflowevent + ", per_page " + perpage) | ||
|
||
// Fetch actions runs to scan the recent failure conclusion runs. | ||
response = await github.rest.actions.listWorkflowRuns({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
workflow_id: workflowid, | ||
event: workflowevent, | ||
status: 'completed', | ||
per_page: perpage | ||
}); | ||
|
||
// Scan `failure` conclusion runs to find the consecutive failures while | ||
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. @ytimocin I added the comment why it scans the workflow run payloads |
||
// skipping the other conclusions, such as 'cancelled`. | ||
failureCount = 0; | ||
for (const run of response.data.workflow_runs) { | ||
console.log(`Validating the workflow run - ID: ${run.id}, Conclusion: ${run.conclusion}.`); | ||
|
||
if (run.conclusion === 'failure') { | ||
failureCount++; | ||
} else if (run.conclusion === 'success') { | ||
// If we find a successful run, we can stop scanning. | ||
break; | ||
} else { | ||
// Skipping the other conclusions such as 'cancelled'. | ||
console.log(`Skipping run ${run.id} with conclusion ${run.conclusion}.`) | ||
} | ||
} | ||
|
||
console.log(`Found ${failureCount} failed runs in a row.`); | ||
return failureCount; |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ytimocin I created the composite action to be shared in two workflows.