Skip to content

Re-run Flaky Workflows #47375

Re-run Flaky Workflows

Re-run Flaky Workflows #47375

name: Re-run Flaky Workflows
on:
workflow_run:
workflows: [Backend, Driver Tests, E2E Tests, Frontend]
types: [completed]
branches: [master, 'release-x.**', 'backport-**']
jobs:
rerun-on-failure:
name: 'Re-run ''${{ github.event.workflow_run.name }}'' workflow'
runs-on: ubuntu-22.04
# Do not re-run scheduled workflow runs. That's only Replay.io E2E tests for now.
if: github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event != 'schedule'
env:
BRANCH_NAME: ${{ github.event.workflow_run.head_branch }}
AUTHOR_NAME: ${{ github.event.workflow_run.head_commit.author.name }}
steps:
- name: Generate job summary
run: |
echo "# ${{ github.event.workflow_run.name }} workflow failed! :x:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "View the failed run attempt (#${{ github.event.workflow_run.run_attempt }}) using the following link:" >> $GITHUB_STEP_SUMMARY
echo "${{ github.event.workflow_run.html_url }}" >> $GITHUB_STEP_SUMMARY
- uses: actions/setup-node@v4
with:
node-version: lts/Hydrogen # 18.x.x
- run: npm install @slack/web-api
- name: Trigger a re-run
uses: actions/github-script@v7
with:
script: | # js
const MAX_ATTEMPTS = 1;
const ATTEMPT = "${{ github.event.workflow_run.run_attempt }}";
const FAILED_RUN_URL = "${{ github.event.workflow_run.html_url }}";
const FAILED_RUN_NAME = "${{ github.event.workflow_run.name }}";
const BREAKING_COMMIT = "${{ github.event.workflow_run.head_sha }}";
const AUTHOR = process.env.AUTHOR_NAME;
const BRANCH = process.env.BRANCH_NAME;
if (ATTEMPT <= MAX_ATTEMPTS) {
github.rest.actions.reRunWorkflowFailedJobs({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
} else if (!BRANCH.includes('backport-')) {
// notify slack of repeated failure
const { WebClient } = require('@slack/web-api');
const slack = new WebClient('${{ secrets.SLACK_BOT_TOKEN }}');
await slack.chat.postMessage({
channel: 'engineering-ci',
text: 'Failing tests',
blocks: [
{
"type": "header",
"text": {
"type": "plain_text",
"text": `:warning: CI is failing on ${BRANCH}`,
"emoji": true,
}
},
],
attachments: [{
color: BRANCH === 'master' ? '#f85149' : "#ffce33",
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Commit <https://github.com/metabase/metabase/commit/${BREAKING_COMMIT}|${BREAKING_COMMIT.slice(0,7)}> by ${AUTHOR} has failing <${FAILED_RUN_URL}|${FAILED_RUN_NAME}> tests on the <https://github.com/metabase/metabase/commits/${BRANCH}|\`${BRANCH}\`> branch. :sad-panda:`
}
},
]
}]
});
}