-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (48 loc) · 1.62 KB
/
auto-rerun-pr-workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Auto Re-run PR Workflows on master Push
on:
push:
branches:
- master
permissions:
pull-requests: write
contents: read
jobs:
re-run-pr-checks:
runs-on: ubuntu-latest
steps:
- name: Install GitHub CLI
run: |
sudo apt update
sudo apt install gh -y jq
- name: Ensure GitHub CLI Authentication
run: gh auth status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Find Open PRs targeting master
id: find-prs
run: |
prs=$(gh pr list --state open --base master --json number,headRefName --jq '.[] | {number: .number, branch: .headRefName}')
if [[ -z "$prs" ]]; then
echo "No open PRs found for master."
exit 0
fi
echo "prs=$(echo $prs | base64)" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Re-trigger workflow for open PRs
run: |
prs=$(echo "${{ env.prs }}" | base64 --decode)
if [[ -z "$prs" ]]; then
echo "No PRs to process."
exit 0
fi
for row in $(echo "$prs" | jq -c '.'); do
pr_number=$(echo $row | jq -r '.number')
pr_branch=$(echo $row | jq -r '.branch')
echo "🔄 Re-triggering workflow for PR #$pr_number (Branch: $pr_branch)..."
if ! gh workflow run pr-check.yml --repo ${{ github.repository }} --ref $pr_branch; then
echo "⚠️ Failed to trigger workflow for PR #$pr_number ($pr_branch)"
fi
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}