-
Notifications
You must be signed in to change notification settings - Fork 1.8k
78 lines (71 loc) · 2.84 KB
/
chatops_retest.yaml
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
# The _chatops_retest workflow reruns failed GHA for a PR
#
# This workflow is triggered by leaving a "/retest" comment on
# a pull request. If the required preconditions are met, it will
# rerun failed GitHub actions checks on that PR
#
# Condition for the "/retest" command are:
# - either the issuer is a maintainer
# - or the issuer is the owner the PR
name: Rerun Failed Actions
on:
repository_dispatch:
types: [retest-command]
jobs:
retest:
name: Rerun Failed Actions
runs-on: ubuntu-latest
steps:
- name: Show Environment Variables
run: env
- name: Show Github Object
run: |
cat <<'EOF'
${{ toJson(github) }}
EOF
- name: Show Github Event Path Json
run: 'cat $GITHUB_EVENT_PATH || true'
- name: Rerun Failed Actions
run: |
echo '::group:: Get the PT commit sha'
# Get the sha of the HEAD commit in the PR
GITHUB_COMMIT_SHA=$(gh api $(echo ${GITHUB_PULL_URL#https://api.github.com/}) | \
| jq -r .head.sha)
echo '::endgroup::'
echo '::group:: Get the list of run IDs'
# Get a list of run IDs
RUN_IDS=$(gh api repos/${GITHUB_REPO}/commits/${GITHUB_COMMIT_SHA}/check-runs | \
jq -r '.check_runs[] | select(.name != "Rerun Failed Actions") | .html_url | capture("/runs/(?<number>[0-9]+)/job") | .number' | \
sort -u)
echo '::endgroup::'
echo '::group:: Rerun failed runs'
# For each run, retrigger faild jobs
for runid in ${RUN_IDS}; do
gh run \
--repo ${GITHUB_REPO} \
rerun ${runid} \
--failed
done
echo '::endgroup::'
env:
GITHUB_TOKEN: ${{ secrets.CHATOPS_TOKEN }}
GITHUB_REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
GITHUB_PULL_URL: ${{ github.event.client_payload.github.payload.issue.pull_request.url }}
- name: Create comment
if: ${{ failure() && steps.landStack.outcome == 'failure' }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.CHATOPS_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
body: |
Something went wrong with your `/${{ github.event.client_payload.slash_command.command }}` command: [please check the logs][1].
[1]: ${{ steps.vars.outputs.run-url }}
- name: Add reaction
if: ${{ success() }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.CHATOPS_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray