-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (124 loc) · 4.12 KB
/
auto-pr.yml
File metadata and controls
147 lines (124 loc) · 4.12 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Auto PR (beta → master)
# Creates or updates the release PR from beta to master.
# Enables auto-merge so GitHub merges the PR when all checks pass.
on:
push:
branches: [beta]
permissions:
contents: read
pull-requests: write
concurrency:
group: auto-pr-beta
cancel-in-progress: true
jobs:
auto-pr:
runs-on: ubuntu-latest
timeout-minutes: 5
# Skip [skip-ci] commits (e.g. sync-beta back-merges) to prevent loops
if: "!contains(github.event.head_commit.message, '[skip-ci]')"
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Validate PAT exists
run: |
if [ -z "${{ secrets.FIELDTRACK_PAT }}" ]; then
echo "::error::FIELDTRACK_PAT secret is not set"
exit 1
fi
- name: Check for existing PR
id: pr
env:
GH_TOKEN: ${{ secrets.FIELDTRACK_PAT }}
run: |
PR_NUMBER=$(gh pr list \
--base master \
--head beta \
--state open \
--json number \
--jq '.[0].number // ""')
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Generate commit summary
id: summary
run: |
git fetch origin master
COMMITS=$(git log origin/master..HEAD \
--no-merges \
--pretty=format:"- %s" \
| awk '!seen[$0]++' \
| head -20)
if [ -z "$COMMITS" ]; then
echo "empty=true" >> $GITHUB_OUTPUT
exit 0
fi
echo "empty=false" >> $GITHUB_OUTPUT
printf "%s\n" "$COMMITS" > commits.txt
- name: Create PR
if: steps.pr.outputs.pr_number == '' && steps.summary.outputs.empty != 'true'
env:
GH_TOKEN: ${{ secrets.FIELDTRACK_PAT }}
run: |
{
echo "## 🚀 Automated Release PR"
echo ""
echo "This PR contains all changes from beta to master."
echo ""
echo "---"
echo ""
echo "## 📦 Latest Changes"
echo ""
echo "<!-- AUTO-GENERATED:START -->"
cat commits.txt
echo "<!-- AUTO-GENERATED:END -->"
echo ""
echo "---"
echo ""
echo "## 🧠 Notes"
echo "- Auto-managed PR"
echo "- Do not edit manually"
} > body.txt
gh pr create \
--base master \
--head beta \
--title "🚀 Release: beta → master" \
--body-file body.txt
echo "✓ PR created"
- name: Update PR body
if: steps.pr.outputs.pr_number != '' && steps.summary.outputs.empty != 'true'
env:
GH_TOKEN: ${{ secrets.FIELDTRACK_PAT }}
run: |
PR="${{ steps.pr.outputs.pr_number }}"
gh pr view "$PR" --json body -q .body > old_body.txt
awk '/<!-- AUTO-GENERATED:START -->/{exit} {print}' old_body.txt > before.txt
awk 'f;/<!-- AUTO-GENERATED:END -->/{f=1}' old_body.txt | tail -n +2 > after.txt
echo "<!-- AUTO-GENERATED:START -->" > block.txt
cat commits.txt >> block.txt
echo "<!-- AUTO-GENERATED:END -->" >> block.txt
cat before.txt block.txt after.txt > final_body.txt
if ! diff -q old_body.txt final_body.txt > /dev/null 2>&1; then
gh pr edit "$PR" --body-file final_body.txt
echo "✓ PR #$PR body updated"
else
echo "No changes in PR body"
fi
- name: Enable auto-merge
env:
GH_TOKEN: ${{ secrets.FIELDTRACK_PAT }}
run: |
PR=$(gh pr list \
--base master \
--head beta \
--state open \
--json number \
--jq '.[0].number // ""')
if [ -z "$PR" ]; then
echo "⚠️ No PR found, auto-merge not enabled"
exit 0
fi
echo "Enabling auto-merge for PR #$PR"
gh pr merge "$PR" \
--auto \
--squash \
--delete-branch=false || true
echo "✓ Auto-merge enabled"