Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Mar 26, 2024
2 parents 334a4f8 + 1b26d93 commit 04fd02c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/rerun-flaky-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Rerun Flaky Live Tests
on:
workflow_run:
workflows: [CI Pipeline]
types:
- completed
jobs:
rerun_flaky_tests:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.run_attempt == 1 }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Rerun flaky tests
uses: actions/github-script@v6
with:
script: |
const { rerunFlakyTests } = await import('${{ github.workspace }}/.github/workflows/scripts/rerunFlakyTests.js')
await rerunFlakyTests({ github, context })
49 changes: 49 additions & 0 deletions .github/workflows/scripts/rerunFlakyTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Only check jobs that start with these.
// Helps make sure we don't restart something like which is not known to be flaky.
const CONSIDERED_JOBS = [
"Windows Live Tests",
"Linux Live Tests",
];

async function getFailedJobsForRun(github, context, workflowRunId, runAttempt) {
const {
data: { jobs },
} = await github.rest.actions.listJobsForWorkflowRunAttempt({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: workflowRunId,
attempt_number: runAttempt,
});

return jobs
.filter((job) => job.conclusion === "failure")
.filter((job) =>
CONSIDERED_JOBS.some((title) => job.name.startsWith(title))
);
}

export async function rerunFlakyTests({ github, context }) {
const failingJobs = await getFailedJobsForRun(
github,
context,
context.payload.workflow_run.id,
context.payload.workflow_run.run_attempt
);

if (failingJobs.length > 1) {
console.log("Multiple jobs failing. PROBABLY not flaky, not rerunning.");
return;
}

if (failingJobs.length === 0) {
throw new Error(
"rerunFlakyTests should not have run on a run with no failing jobs"
);
}

github.rest.actions.reRunWorkflowFailedJobs({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
}
10 changes: 5 additions & 5 deletions .github/workflows/stable-merge.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: 'Master Merge'

on:
push:
branches:
- master
workflow_run:
workflows: [CI Pipeline]
types:
- completed

jobs:
master-merge:

runs-on: ubuntu-latest

if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down

0 comments on commit 04fd02c

Please sign in to comment.