From c6a8edb935f730556856f16d1737caabe48c5352 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Ikebe Date: Tue, 14 May 2024 23:04:27 +0900 Subject: [PATCH] ci: fix ref if main (#54) * ci: fix ref * ci: add TEST-TIMEOUT-MIN env variable * ci: remove env variable * ci: fix syntax error * ci: test rerun * ci: test rerun * ci: remove commentout * ci: fix ref if main * ci: fix ref * ci: add gh run cancel --- .github/workflows/rerun.yml | 13 +++++++++++-- .github/workflows/test.yml | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rerun.yml b/.github/workflows/rerun.yml index 8695551..3aaf47f 100644 --- a/.github/workflows/rerun.yml +++ b/.github/workflows/rerun.yml @@ -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) \ No newline at end of file + 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8825177..8d251d9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,7 +60,7 @@ jobs: async function run() { const { owner, repo } = context.repo; const workflow_id = 'rerun.yml'; - const ref = '${{ github.head_ref }}'; + const ref = ('${{ github.head_ref }}' === 'main') ? 'main' : '${{ github.head_ref }}'; const run_id = context.runId; try {