Skip to content

Commit

Permalink
ci: add gh run cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
uhobeike committed May 14, 2024
1 parent 23f9215 commit 47c17a8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/rerun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Rerun workflow
- name: Check and rerun or cancel workflow
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh run rerun $(gh run list -w test.yml | grep -oE '[0-9]{10}' | head -n 1)
STATUS=$(gh run list -w test.yml | awk 'NR==4 {print $1}')
RUN_ID=$(gh run list -w test.yml | grep -oE '[0-9]{10}' | head -n 1)
if [ "$STATUS" == "completed" ]; then
echo "Job is completed, rerunning..."
gh run rerun $RUN_ID
else
echo "Job is not completed, canceling and rerunning..."
gh run cancel $RUN_ID && gh run rerun $RUN_ID
fi

0 comments on commit 47c17a8

Please sign in to comment.