Skip to content

Approval rerun

Approval rerun #7

Workflow file for this run

name: Approval rerun
on:
pull_request_review:
types: [submitted]
env:
BRANCH: ${{ github.base_ref }}
PR_ID: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
TARGET_WORKFLOW_NAME: Approval
jobs:
approved-actions:
name: Check approval
if: github.event.review.state == 'approved'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 10
- name: Rerun approval
run: |
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs?event=pull_request&per_page=100")
run_id=$(echo "$response" | jq -r --arg pr_number "$PR_ID" --arg target_workflow "$TARGET_WORKFLOW_NAME" \
'.workflow_runs[] | select(.pull_requests[].number == ($pr_number | tonumber) and .name == $target_workflow) | .id' | head -n 1)
if [ -n "$run_id" ]; then
echo "Found run_id for PR #$PR_ID with target workflow '$TARGET_WORKFLOW_NAME': $run_id"
curl -X POST -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/rerun"
else
echo "No matching workflow run found for PR #$PR_ID with target workflow '$TARGET_WORKFLOW_NAME'."
exit 1
fi