From 5c5eba47f9bc22a3ca1a840355b9d18fdf6d2c0a Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 24 Sep 2024 11:31:34 -0400 Subject: [PATCH 1/5] Update rerun.yml --- .github/workflows/rerun.yml | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rerun.yml b/.github/workflows/rerun.yml index eb060a3828cd..08dad8d4589c 100644 --- a/.github/workflows/rerun.yml +++ b/.github/workflows/rerun.yml @@ -1,20 +1,47 @@ -# from https://github.com/orgs/community/discussions/67654 +# adapted from https://github.com/orgs/community/discussions/67654 +# altered to not rerun if we are not the newest commit in the run's branch on: workflow_dispatch: inputs: run_id: required: true + jobs: rerun: runs-on: ubuntu-latest permissions: - actions: write + actions: write # Needed for 'gh run rerun' steps: - - name: rerun ${{ inputs.run_id }} + - name: Check if the commit is the latest on the branch env: - GH_REPO: ${{ github.repository }} - GH_TOKEN: ${{ github.token }} - GH_DEBUG: api + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + RUN_ID="${{ inputs.run_id }}" + # Get the run details + RUN_INFO=$(gh run view $RUN_ID --json headSha,headBranch,event) + # Extract the commit SHA, branch name, and event type + COMMIT_SHA=$(echo "$RUN_INFO" | jq -r '.headSha') + BRANCH_NAME=$(echo "$RUN_INFO" | jq -r '.headBranch') + EVENT_TYPE=$(echo "$RUN_INFO" | jq -r '.event') + + # Only proceed if the event is a pull_request + if [[ "$EVENT_TYPE" != "pull_request" ]]; then + echo "Event type is $EVENT_TYPE. Skipping rerun." + exit 0 + fi + + # Get the latest commit SHA on the branch + LATEST_COMMIT_SHA=$(gh api repos/${{ github.repository }}/commits/$BRANCH_NAME --jq .sha) + + # Compare the SHAs + if [[ "$COMMIT_SHA" != "$LATEST_COMMIT_SHA" ]]; then + echo "Commit $COMMIT_SHA is not the latest commit on branch $BRANCH_NAME (latest is $LATEST_COMMIT_SHA). Skipping rerun." + exit 0 + else + echo "Commit $COMMIT_SHA is the latest on branch $BRANCH_NAME. Proceeding with rerun." + fi + + - name: Rerun failed jobs run: | gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 gh run rerun ${{ inputs.run_id }} --failed From 4fdabca1a660c1f79c77fcbbaf8a9d0d21294b67 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 24 Sep 2024 11:33:08 -0400 Subject: [PATCH 2/5] Update rerun.yml --- .github/workflows/rerun.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rerun.yml b/.github/workflows/rerun.yml index 08dad8d4589c..e0772c7676a4 100644 --- a/.github/workflows/rerun.yml +++ b/.github/workflows/rerun.yml @@ -12,7 +12,11 @@ jobs: permissions: actions: write # Needed for 'gh run rerun' steps: - - name: Check if the commit is the latest on the branch + - name: Wait for run to finish + run: | + gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 + + - name: Rerun failed jobs if the commit is the latest on the branch env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -36,12 +40,7 @@ jobs: # Compare the SHAs if [[ "$COMMIT_SHA" != "$LATEST_COMMIT_SHA" ]]; then echo "Commit $COMMIT_SHA is not the latest commit on branch $BRANCH_NAME (latest is $LATEST_COMMIT_SHA). Skipping rerun." - exit 0 else echo "Commit $COMMIT_SHA is the latest on branch $BRANCH_NAME. Proceeding with rerun." + gh run rerun ${{ inputs.run_id }} --failed fi - - - name: Rerun failed jobs - run: | - gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 - gh run rerun ${{ inputs.run_id }} --failed From ad5177ecf350f1f75087e8aa69fcb0b503a7bb74 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 24 Sep 2024 11:36:54 -0400 Subject: [PATCH 3/5] Update rerun.yml --- .github/workflows/rerun.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rerun.yml b/.github/workflows/rerun.yml index e0772c7676a4..b3091b61171c 100644 --- a/.github/workflows/rerun.yml +++ b/.github/workflows/rerun.yml @@ -18,7 +18,8 @@ jobs: - name: Rerun failed jobs if the commit is the latest on the branch env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ github.token }} + GH_DEBUG: api run: | RUN_ID="${{ inputs.run_id }}" # Get the run details From 2278dade5d6e2754717d2536abb41741bc50460b Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 24 Sep 2024 11:37:59 -0400 Subject: [PATCH 4/5] Update rerun.yml --- .github/workflows/rerun.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/rerun.yml b/.github/workflows/rerun.yml index b3091b61171c..8778ee01960e 100644 --- a/.github/workflows/rerun.yml +++ b/.github/workflows/rerun.yml @@ -13,6 +13,9 @@ jobs: actions: write # Needed for 'gh run rerun' steps: - name: Wait for run to finish + env: + GH_TOKEN: ${{ github.token }} + GH_DEBUG: api run: | gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 From 9c4b13f7b62b1a2f5e7bab65cd8294162ddc6b45 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 24 Sep 2024 11:41:12 -0400 Subject: [PATCH 5/5] Update rerun.yml --- .github/workflows/rerun.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rerun.yml b/.github/workflows/rerun.yml index 8778ee01960e..9623ad4272ac 100644 --- a/.github/workflows/rerun.yml +++ b/.github/workflows/rerun.yml @@ -14,6 +14,7 @@ jobs: steps: - name: Wait for run to finish env: + GH_REPO: ${{ github.repository }} GH_TOKEN: ${{ github.token }} GH_DEBUG: api run: | @@ -21,6 +22,7 @@ jobs: - name: Rerun failed jobs if the commit is the latest on the branch env: + GH_REPO: ${{ github.repository }} GH_TOKEN: ${{ github.token }} GH_DEBUG: api run: |