Approval rerun #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Display required approvers and check | |
run: | | |
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/repos/$OWNER/$REPO/actions/runs?event=pull_request&per_page=100") | |
echo "$response" | |
run_id=$(echo "$response" | jq -r --arg pr_number "$PR_ID" --arg target_workflow "$TARGET_WORKFLOW_NAME" \ | |
'.workflow_runs[] | select(.head_branch | contains($pr_number) 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 |