-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[No QA] Improve workflow failure notifier #41124
Changes from 5 commits
37999e8
23c48b2
7e4c70d
c1eeff7
47adcd9
aa13921
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 | ||||
---|---|---|---|---|---|---|
|
@@ -27,19 +27,52 @@ jobs: | |||||
}); | ||||||
return jobsData.data; | ||||||
|
||||||
- name: Fetch Previous Workflow Run | ||||||
id: previous-workflow-run | ||||||
uses: actions/github-script@v7 | ||||||
with: | ||||||
script: | | ||||||
const runId = ${{ github.event.workflow_run.id }}; | ||||||
const allRuns = await github.rest.actions.listWorkflowRuns({ | ||||||
owner: context.repo.owner, | ||||||
repo: context.repo.repo, | ||||||
workflow_id: 'preDeploy.yml', | ||||||
}); | ||||||
const run = allRuns.data.workflow_runs.find(run => run.id === runId); | ||||||
const run_number = run.run_number; | ||||||
const previousRun = allRuns.data.workflow_runs.find(run => run.run_number === run_number - 1); | ||||||
if (previousRun.actor.login === 'OSBotify') { | ||||||
return allRuns.data.workflow_runs.find(run => run.run_number === run_number - 2); | ||||||
} | ||||||
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. I don't think this will work if multiple runs are from |
||||||
return previousRun; | ||||||
|
||||||
- name: Fetch Previous Workflow Run Jobs | ||||||
id: previous-workflow-jobs | ||||||
uses: actions/github-script@v7 | ||||||
with: | ||||||
script: | | ||||||
const previousRun = ${{ steps.previous-workflow-run.outputs.result }}; | ||||||
const runId = previousRun.id; | ||||||
const jobsData = await github.rest.actions.listJobsForWorkflowRun({ | ||||||
owner: context.repo.owner, | ||||||
repo: context.repo.repo, | ||||||
run_id: runId, | ||||||
}); | ||||||
return jobsData.data; | ||||||
|
||||||
- name: Process Each Failed Job | ||||||
uses: actions/github-script@v7 | ||||||
with: | ||||||
script: | | ||||||
const jobs = ${{ steps.fetch-workflow-jobs.outputs.result }}; | ||||||
|
||||||
const previousRun = ${{ steps.previous-workflow-run.outputs.result }}; | ||||||
const previousRunJobs = ${{ steps.previous-workflow-jobs.outputs.result }}; | ||||||
const headCommit = "${{ github.event.workflow_run.head_commit.id }}"; | ||||||
const prData = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||||||
owner: context.repo.owner, | ||||||
repo: context.repo.repo, | ||||||
commit_sha: headCommit, | ||||||
}); | ||||||
|
||||||
const pr = prData.data[0]; | ||||||
const prLink = pr.html_url; | ||||||
const prAuthor = pr.user.login; | ||||||
|
@@ -50,14 +83,9 @@ jobs: | |||||
if (jobs.jobs[i].conclusion == 'failure') { | ||||||
const jobName = jobs.jobs[i].name; | ||||||
const jobLink = jobs.jobs[i].html_url; | ||||||
const issues = await github.rest.issues.listForRepo({ | ||||||
owner: context.repo.owner, | ||||||
repo: context.repo.repo, | ||||||
labels: failureLabel, | ||||||
state: 'open' | ||||||
}); | ||||||
const existingIssue = issues.data.find(issue => issue.title.includes(jobName)); | ||||||
if (!existingIssue) { | ||||||
const previousJob = previousRunJobs.jobs.find(job => job.name === jobName); | ||||||
previousJobSucceeded = previousJob.conclusion === 'success'; | ||||||
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.
Suggested change
I guess it's possible that |
||||||
if (previousJobSucceeded) { | ||||||
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.
Suggested change
I don't think there's much benefit to having |
||||||
const annotations = await github.rest.checks.listAnnotations({ | ||||||
owner: context.repo.owner, | ||||||
repo: context.repo.repo, | ||||||
|
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.
I guess
run_number
is always consecutive? I wonder if it's safer to usefindIndex
to get the current run and then select the previous run using the index?