-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reusable actions to restest GitHub actions #2330
Open
afrittoli
wants to merge
1
commit into
tektoncd:main
Choose a base branch
from
afrittoli:reusable_retest_workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# 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 | ||
# | ||
# To use this in a repo: | ||
# | ||
# name: Rerun Failed Actions | ||
# on: | ||
# repository_dispatch: | ||
# types: [retest-command] | ||
# | ||
# jobs: | ||
# retest: | ||
# name: Rerun Failed Actions | ||
# uses: tektoncd/plumbing/.github/actions/_chatops_retest.yml@main | ||
|
||
name: Rerun Failed Actions | ||
on: | ||
workflow_call: | ||
|
||
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 PR 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 GITHUB_COMMIT_SHA=${GITHUB_COMMIT_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 RUN_IDS=${RUN_IDS} | ||
echo '::endgroup::' | ||
|
||
echo '::group:: Rerun failed runs' | ||
# For each run, retrigger faild jobs | ||
for runid in ${RUN_IDS}; do | ||
echo Restarting run ${runid} for commit ${GITHUB_COMMIT_SHA} | ||
gh run \ | ||
--repo ${GITHUB_REPO} \ | ||
rerun ${runid} \ | ||
--failed || true | ||
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@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 | ||
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@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 | ||
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 }} | ||
reactions: hooray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# The slash workflow handles slash commands | ||
# | ||
# Slash commands are given through comments on pull requests | ||
# and may be used only by individuals with "write" access to | ||
# the repository (i.e. maintainers). | ||
# | ||
# Slash commands must be placed at the very beginning of the | ||
# first line of a comment. More details are available in the | ||
# action docs: https://github.com/peter-evans/slash-command-dispatch/tree/main?tab=readme-ov-file#how-comments-are-parsed-for-slash-commands | ||
# | ||
# The workflow looks for and dispatches to another workflow | ||
# named <command>-command which must exist in the repository. | ||
# | ||
# Supported commands: | ||
# - /retest: re-run failed GitHub actions associated with the | ||
# caller of this workflow | ||
# | ||
# When a command is recognised, the rocket and eyes emojis are added | ||
# | ||
# To use this in a repo: | ||
# | ||
# name: Slash Command Routing | ||
# on: | ||
# issue_comment: | ||
# types: [created] | ||
# | ||
# jobs: | ||
# check_comments: | ||
# uses: tektoncd/plumbing/.github/actions/_slash.yml@main | ||
|
||
name: Slash Command Routing | ||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
check_comments: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: route-chatops | ||
uses: peter-evans/slash-command-dispatch@13bc09769d122a64f75aa5037256f6f2d78be8c4 # v4.0.0 | ||
with: | ||
token: ${{ secrets.CHATOPS_TOKEN }} | ||
config: > | ||
[ | ||
{ | ||
"command": "retest", | ||
"permission": "write", | ||
"issue_type": "pull-request", | ||
"repository": "${{ github.repository }}" | ||
} | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this reference the
Rerun Failed Actions
step instead?