Skip to content

Commit c73cdef

Browse files
committed
.github/workflows: use plumbing workflow definitions.
Let's share code 🙃. Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
1 parent 7f70c7d commit c73cdef

File tree

2 files changed

+16
-107
lines changed

2 files changed

+16
-107
lines changed
Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,14 @@
1-
# The _chatops_retest workflow reruns failed GHA for a PR
2-
#
3-
# This workflow is triggered by leaving a "/retest" comment on
4-
# a pull request. If the required preconditions are met, it will
5-
# rerun failed GitHub actions checks on that PR
6-
#
7-
# Condition for the "/retest" command are:
8-
# - either the issuer is a maintainer
9-
# - or the issuer is the owner the PR
10-
111
name: Rerun Failed Actions
2+
3+
permissions:
4+
contents: read
5+
126
on:
137
repository_dispatch:
148
types: [retest-command]
159

1610
jobs:
1711
retest:
1812
name: Rerun Failed Actions
19-
runs-on: ubuntu-latest
20-
steps:
21-
- name: Show Environment Variables
22-
run: env
23-
- name: Show Github Object
24-
run: |
25-
cat <<'EOF'
26-
${{ toJson(github) }}
27-
EOF
28-
- name: Show Github Event Path Json
29-
run: 'cat $GITHUB_EVENT_PATH || true'
30-
- name: Rerun Failed Actions
31-
run: |
32-
echo '::group:: Get the PR commit sha'
33-
# Get the sha of the HEAD commit in the PR
34-
GITHUB_COMMIT_SHA=$(gh api $(echo ${GITHUB_PULL_URL#https://api.github.com/}) | \
35-
jq -r .head.sha)
36-
echo GITHUB_COMMIT_SHA=${GITHUB_COMMIT_SHA}
37-
echo '::endgroup::'
38-
39-
echo '::group:: Get the list of run IDs'
40-
# Get a list of run IDs
41-
RUN_IDS=$(gh api repos/${GITHUB_REPO}/commits/${GITHUB_COMMIT_SHA}/check-runs | \
42-
jq -r '.check_runs[] | select(.name != "Rerun Failed Actions") | .html_url | capture("/runs/(?<number>[0-9]+)/job") | .number' | \
43-
sort -u)
44-
echo RUN_IDS=${RUN_IDS}
45-
echo '::endgroup::'
46-
47-
echo '::group:: Rerun failed runs'
48-
# For each run, retrigger faild jobs
49-
for runid in ${RUN_IDS}; do
50-
echo Restarting run ${runid} for commit ${GITHUB_COMMIT_SHA}
51-
gh run \
52-
--repo ${GITHUB_REPO} \
53-
rerun ${runid} \
54-
--failed || true
55-
done
56-
echo '::endgroup::'
57-
env:
58-
GITHUB_TOKEN: ${{ secrets.CHATOPS_TOKEN }}
59-
GITHUB_REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
60-
GITHUB_PULL_URL: ${{ github.event.client_payload.github.payload.issue.pull_request.url }}
61-
62-
- name: Create comment
63-
if: ${{ failure() && steps.landStack.outcome == 'failure' }}
64-
uses: peter-evans/create-or-update-comment@v4
65-
with:
66-
token: ${{ secrets.CHATOPS_TOKEN }}
67-
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
68-
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
69-
body: |
70-
Something went wrong with your `/${{ github.event.client_payload.slash_command.command }}` command: [please check the logs][1].
71-
72-
[1]: ${{ steps.vars.outputs.run-url }}
73-
74-
- name: Add reaction
75-
if: ${{ success() }}
76-
uses: peter-evans/create-or-update-comment@v4
77-
with:
78-
token: ${{ secrets.CHATOPS_TOKEN }}
79-
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
80-
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
81-
reactions: hooray
13+
uses: tektoncd/plumbing/.github/workflows/_chatops_retest.yml@8441d6ffad5bf64f631ed0e67e46192fdedaca47
14+
secrets: inherit

.github/workflows/slash.yml

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
1-
# The slash workflow handles slash commands
2-
#
3-
# Slash commands are given through comments on pull requests
4-
# and may be used only by individuals with "write" access to
5-
# the repository (i.e. maintainers).
6-
#
7-
# Slash commands must be placed at the very beginning of the
8-
# first line of a comment. More details are available in the
9-
# action docs: https://github.com/peter-evans/slash-command-dispatch/tree/main?tab=readme-ov-file#how-comments-are-parsed-for-slash-commands
10-
#
11-
# The workflow looks for and dispatches to another workflow
12-
# named <command>-command which must exist in the repository.
13-
#
14-
# Supported commands:
15-
# - /land: invokes the land-command workflow, to land (merge) PRs
16-
# stacked through ghstack
17-
#
18-
# When a command is recognised, the rocket and eyes emojis are added
19-
201
name: Slash Command Routing
2+
3+
permissions:
4+
contents: read
5+
216
on:
227
issue_comment:
238
types: [created]
249

2510
jobs:
2611
check_comments:
27-
runs-on: ubuntu-latest
28-
steps:
29-
- name: route-land
30-
uses: peter-evans/slash-command-dispatch@v4
31-
with:
32-
token: ${{ secrets.CHATOPS_TOKEN }}
33-
config: >
34-
[
35-
{
36-
"command": "retest",
37-
"permission": "write",
38-
"issue_type": "pull-request",
39-
"repository": "tektoncd/pipeline"
40-
}
41-
]
12+
if: ${{ github.event.issue.pull_request }}
13+
permissions:
14+
issues: write # for peter-evans/slash-command-dispatch to create issue reaction
15+
pull-requests: write # for peter-evans/slash-command-dispatch to create PR reaction
16+
uses: tektoncd/plumbing/.github/workflows/_slash.yml@8441d6ffad5bf64f631ed0e67e46192fdedaca47
17+
secrets: inherit

0 commit comments

Comments
 (0)