Skip to content
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

rerun: rebuild workflow #180277

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/ci-rerun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Re-run Workflow

on:
workflow_run:
workflows:
- CI
types:
- completed
pull_request_target:
types:
- closed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this? I don't think you do anything about closed PRs below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a leftover from the previous workflow that I started with. I will remove it.

- labeled
- unlabeled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird to run this also on unlabeled events.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another carryover from the previous action. If you removed a label such as ci-syntax-only or ci-skip-install the suite would automatically be re-run as the current CI state would no longer correlate with the applied labels.

schedule:
- cron: '30 */3 * * *' # every 3 hours (30 minutes past the hour)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is run on a schedule, should we also automatically remove some of these labels at some point?

Copy link
Member Author

@bevanjkay bevanjkay Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Historically, ci-retry runs until it is removed or CI passes (I just haven't written the logic to remove the label yet). ci-requeue is removed immediately, but based on the discussion this will likely get removed entirely in lieu of just running using the UI.

workflow_dispatch:

env:
GH_REPO: ${{ github.repository }}

permissions:
contents: read
actions: write

jobs:
scheduled-retry:
if: >
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
Comment on lines +27 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be cleaner to do something like this:

Suggested change
if: >
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
if: contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event.name)

See https://docs.github.com/en/actions/learn-github-actions/expressions#example-matching-an-array-of-strings

runs-on: ubuntu-latest
steps:
- name: Re-run CI workflow
run: |
PR_NUMBERS=$(gh pr list -l 'ci-retry' --json number --jq '.[].number')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to use long flags where they're available for readability.

Suggested change
PR_NUMBERS=$(gh pr list -l 'ci-retry' --json number --jq '.[].number')
PR_NUMBERS=$(gh pr list --label 'ci-retry' --json number --jq '.[].number')

This may need to be done elsewhere too.

for PR_NUMBER in $PR_NUMBERS; do
echo "Processing PR #$PR_NUMBER"
WORKFLOW_RUN_ID=$(gh pr view "$PR_NUMBER" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId --jq '.[].databaseId')
if [ -n "$WORKFLOW_RUN_ID" ]; then
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER"
gh run rerun "$WORKFLOW_RUN_ID"
else
echo "No runs found for PR #$PR_NUMBER"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

scheduled-retry-failed-jobs:
if: >
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
Comment on lines +48 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if: >
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
if: contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event.name)

runs-on: ubuntu-latest
steps:
- name: Re-run CI workflow
run: |
PR_NUMBERS=$(gh pr list -l 'ci-retry-failed-jobs' --json number --jq '.[].number')
for PR_NUMBER in $PR_NUMBERS; do
echo "Processing PR #$PR_NUMBER"
WORKFLOW_RUN_ID=$(gh pr view "$PR_NUMBER" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId --jq '.[].databaseId')
if [ -n "$WORKFLOW_RUN_ID" ]; then
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER"
gh run rerun "$WORKFLOW_RUN_ID" --failed
else
echo "No runs found for PR #$PR_NUMBER"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

trigger-rerun:
if: >
(
github.event.label.name == 'ci-syntax-only' ||
github.event.label.name == 'ci-requeue' ||
github.event.label.name == 'ci-skip-install'
)
Comment on lines +69 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if: >
(
github.event.label.name == 'ci-syntax-only' ||
github.event.label.name == 'ci-requeue' ||
github.event.label.name == 'ci-skip-install'
)
if: contains(fromJSON('["ci-syntax-only", "ci-requeue", "ci-skip-install"]'), github.event.label.name)

runs-on: ubuntu-latest
steps:
- name: Re-run CI workflow
run: |
PR_NUMBER=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName')
WORKFLOW_RUN_ID=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId,status --jq '.[].databaseId')
if [ -n "$WORKFLOW_RUN_ID" ]; then
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER"
gh run rerun "$WORKFLOW_RUN_ID"
else
echo "No runs found for PR #$PR_NUMBER"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Comment on lines +79 to +88
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid interpolating right into a shell script, see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable.

Suggested change
PR_NUMBER=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName')
WORKFLOW_RUN_ID=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId,status --jq '.[].databaseId')
if [ -n "$WORKFLOW_RUN_ID" ]; then
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER"
gh run rerun "$WORKFLOW_RUN_ID"
else
echo "No runs found for PR #$PR_NUMBER"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER=$(gh pr view "$PULL_REQUEST_NUMBER" --json headRefName --jq '.headRefName')
WORKFLOW_RUN_ID=$(gh pr view "$PULL_REQUEST_NUMBER" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId,status --jq '.[].databaseId')
if [ -n "$WORKFLOW_RUN_ID" ]; then
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER"
gh run rerun "$WORKFLOW_RUN_ID"
else
echo "No runs found for PR #$PR_NUMBER"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}

I also don't really follow what's going on with PR_NUMBER and WORKFLOW_RUN_ID. The content of PR_NUMBER won't be a pull request number, will it?


trigger-retry-failed-jobs:
if: github.event.label.name == 'ci-requeue-failed-jobs'
runs-on: ubuntu-latest
steps:
- name: Re-run CI workflow
run: |
PR_NUMBER=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName')
WORKFLOW_RUN_ID=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId --jq '.[].databaseId')
if [ -n "$WORKFLOW_RUN_ID" ]; then
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER"
gh run rerun "$WORKFLOW_RUN_ID" --failed
else
echo "No runs found for PR #$PR_NUMBER"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading