forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (74 loc) · 3.33 KB
/
rerun-workflows.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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@v3
with:
node-version: lts/Hydrogen # 18.x.x
- run: npm install @slack/web-api
- name: Trigger a re-run
uses: actions/github-script@v6
with:
script: | # js
const MAX_ATTEMPTS = 2;
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 {
// 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:`
}
},
]
}]
});
}