| name: "Sync Release to Main" | |
| on: | |
| push: | |
| branches: | |
| # As packages opt into batched releases, they need to be added here | |
| - 'release-go_router-*' | |
| - 'release-cupertino_ui-*' | |
| - 'release-material_ui-*' | |
| 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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 | |
| with: | |
| fetch-depth: 0 # Fetch history to allow branch comparison | |
| persist-credentials: false | |
| - name: Create Pull Request | |
| env: | |
| GH_TOKEN: ${{ secrets.FLUTTERGITHUBBOT_TOKEN }} | |
| run: | | |
| gh auth setup-git | |
| # 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 package name for label | |
| BRANCH_NAME="${GITHUB_REF_NAME}" | |
| TEMP="${BRANCH_NAME#release-}" | |
| PACKAGE_NAME="${TEMP%-*}" | |
| # 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: batch-${PACKAGE_NAME}" |