-
Notifications
You must be signed in to change notification settings - Fork 3.7k
48 lines (41 loc) · 1.67 KB
/
sync_release_pr.yml
File metadata and controls
48 lines (41 loc) · 1.67 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
name: "Sync Release to Main"
on:
push:
branches:
# As packages opt into batched releases, they need to be added here
- 'release-go_router-*'
jobs:
create_sync_pr:
runs-on: ubuntu-latest
permissions:
# The create-pull-request action needs both content and pull-requests permissions.
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0 # Fetch history to allow branch comparison
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.FLUTTERGITHUBBOT_TOKEN }}
run: |
# 1. Fetch main so the runner can see the difference
git fetch origin main
# 2. Verify there are actually new commits to sync
# This prevents the "GraphQL: No commits between main..." error
COMMITS_COUNT=$(git rev-list --count origin/main..HEAD)
if [ "$COMMITS_COUNT" -eq "0" ]; then
echo "No new commits found on ${{ github.ref_name }} compared to main. Nothing to sync."
exit 0
fi
# 3. Extract release name without version for label
BRANCH_NAME="${{ github.ref_name }}"
RELEASE_NAME="${BRANCH_NAME%-*}"
# 4. Create the PR directly
gh pr create \
--base "main" \
--head "${{ github.ref_name }}" \
--title "Sync ${{ github.ref_name }} to main" \
--body "This automated PR syncs the changes from the release branch ${{ github.ref_name }} back to the main branch." \
--label "override: post-${RELEASE_NAME}"