Repository navigation
[ci] Checks unmerged batch release sync back before next release #12868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| name: Reusable Sync To Main | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| branch-name: | ||
| description: 'The release branch to sync back to main.' | ||
| required: true | ||
| type: string | ||
| comment-if-exists: | ||
| description: >- | ||
| If non-empty, this is posted as a comment when the sync PR already | ||
| exists. The comment is only posted once per PR. | ||
| required: false | ||
| default: '' | ||
| type: string | ||
| secrets: | ||
| BOT_TOKEN: | ||
| required: true | ||
| jobs: | ||
| sync_to_main: | ||
| if: github.repository_owner == 'flutter' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| # Need write permission to create PR. | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 | ||
| with: | ||
| ref: ${{ inputs.branch-name }} | ||
| fetch-depth: 0 # Fetch history to allow branch comparison | ||
| persist-credentials: false | ||
|
|
||
| - name: Create Pull Request | ||
| env: | ||
| GH_TOKEN: ${{ secrets.BOT_TOKEN }} | ||
| BRANCH_NAME: ${{ inputs.branch-name }} | ||
| COMMENT: ${{ inputs.comment-if-exists }} | ||
| # Used to avoid posting the same comment on every scheduled run. | ||
| COMMENT_MARKER: '<!-- batch-release-sync-nudge -->' | ||
| run: | | ||
| gh auth setup-git | ||
| # 1. Fetch main so the runner can see the difference | ||
| git fetch origin main | ||
|
|
||
| # 2. Check if PR already exists before creating | ||
| EXISTING_PR=$(gh pr list --head "${BRANCH_NAME}" --base "main" --json number --jq '.[0].number') | ||
| if [ -n "$EXISTING_PR" ]; then | ||
| echo "A pull request for ${BRANCH_NAME} already exists (#${EXISTING_PR})." | ||
| if [ -n "$COMMENT" ]; then | ||
| if gh pr view "$EXISTING_PR" --json comments --jq '.comments[].body' | grep -qF "$COMMENT_MARKER"; then | ||
| echo "Already commented on #${EXISTING_PR}." | ||
| else | ||
| gh pr comment "$EXISTING_PR" --body "${COMMENT} ${COMMENT_MARKER}" | ||
| fi | ||
| fi | ||
| exit 0 | ||
| fi | ||
|
|
||
| # 3. Verify there are actually new commits to sync. | ||
| # This prevents the "GraphQL: No commits between main..." error, and is | ||
| # the expected state when the release PR itself has not landed yet. | ||
| COMMITS_COUNT=$(git rev-list --count origin/main..HEAD) | ||
|
|
||
| if [ "$COMMITS_COUNT" -eq "0" ]; then | ||
| echo "No new commits found on ${BRANCH_NAME} compared to main. Nothing to sync." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # 4. Extract package name for label. Package names can't contain a | ||
| # hyphen, so everything from the first one on is the version. | ||
| TEMP="${BRANCH_NAME#release-}" | ||
| PACKAGE_NAME="${TEMP%%-*}" | ||
|
|
||
| # 5. Create the PR directly | ||
| gh pr create \ | ||
| --base "main" \ | ||
| --head "${BRANCH_NAME}" \ | ||
| --title "Sync ${BRANCH_NAME} to main" \ | ||
| --body "This automated PR syncs the changes from the release branch ${BRANCH_NAME} back to the main branch." \ | ||
| --label "override: batch-${PACKAGE_NAME}" |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a new global permission setting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github action security scan warned that, if no permission set, using default permission can be too excessive.