Skip to content

Commit

Permalink
[github actions] Automate Flutter Chery Picks (flutter#139524)
Browse files Browse the repository at this point in the history
**design doc: go/easy-cp**
umbrella design doc: go/flutter-actions
umbrella bug: flutter#139604 

**Sample Results**:
1. If cherry pick succeeds, a pull request with cherry pick template and label is created.
flutter#139523
2. If cherry pick fails, a comment is added under the original Pull Request.
flutter/cocoon#3305

In tests, [7d9010](flutter@7d9010c) was used to simulate a clean cherry pick, and [cf71a5](flutter@cf71a55) was used to simulate a merge conflict during cherry pick.

**Implementation Details:**
1. triggered when 'cp: beta' or 'cp:stable' label is added to the original PR
4. parses release channel and gets release candidate branch name
5. get commit sha from event payload
6. checks out framework repo and revision history
7. Attempt a cherry pick without any resolution strategy
8. If cp is successful, uses a PR template to open a pull request. 
9. If cp isn't successful, leave a comment on the original PR.

**PR template**
Since PR template doesn't support web form, the cherry pick PR template we used is https://github.com/XilaiZhang/miscellaneous-side-project/blob/master/.github/workflows/template/cherrypick.md, which is adapted from the [web form cherry pick issue template](https://cs.opensource.google/flutter/flutter/+/master:.github/ISSUE_TEMPLATE/7_cherry_pick.yml).
This PR template should be reviewed and added to be under the .github path in framework repository. 

**Decisions Taken**
1. place of source code
I put the source code under the framework repository. Acknowledges the risk of duplication of code, in favor of not needing to package and publish our own actions to market place.
more details in [open discussions section of design doc](https://docs.google.com/document/d/1EUyJ9NCAltxJq3P3pIzIRVF2ArPUO4cj_eqIUvzl8cw/edit#heading=h.e3zrsz9gwxmp)

2. Resolution strategy
No resolution strategy is applied at all during the cherry pick process. [more details](https://docs.google.com/document/d/1EUyJ9NCAltxJq3P3pIzIRVF2ArPUO4cj_eqIUvzl8cw/edit#heading=h.3za1b9qx6pi2)

**Future Work**
A PAT token is needed for authorization to create branch and add comment. We would need to create a new bot and update its credentials in the secrets section of flutter/flutter repository.
  • Loading branch information
XilaiZhang committed Dec 12, 2023
1 parent 4444bdf commit 32c7c31
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/easy-cp.yml
@@ -0,0 +1,75 @@
# Copyright 2023 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

name: Cherry-pick Labeled PR to Release Branch

on:
pull_request:
branches: master
types: [labeled]

permissions: write-all

jobs:
cherrypick_to_release:
name: cherrypick_to_release
runs-on: ubuntu-latest
if: |
(github.event.label.name == format('cp{0} beta', ':') || github.event.label.name == format('cp{0} stable', ':')) &&
(github.event.pull_request.merged == true)
steps:
- name: Get Release Channel
run: |
echo "CHANNEL=$(echo ${{ github.event.label.name }} | cut -d ':' -f 2 | xargs)" >> $GITHUB_ENV
- name: Get Release Candidate Branch
run: |
RELEASE_BRANCH=$(curl https://raw.githubusercontent.com/flutter/flutter/$CHANNEL/bin/internal/release-candidate-branch.version)
echo "RELEASE_BRANCH=$(echo $RELEASE_BRANCH | tr -d '\n')" >> $GITHUB_ENV
- name: Get Cherry Pick PR
run: |
echo "COMMIT_SHA=$(echo ${{ github.event.pull_request.merge_commit_sha }})" >> $GITHUB_ENV
- name: Checkout Flutter Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
repository: flutter/flutter
token: ${{ github.token }}
path: flutter
ref: master
# Checkout all history commits on master branch, so that the cp commit is a known object
fetch-depth: 0
# use same name when checking out branch, since the marketplace action does a hard reset.
- name: Attempt CP
id: attempt-cp
working-directory: ./flutter
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git fetch origin $RELEASE_BRANCH
git fetch origin master
git checkout -b $RELEASE_BRANCH --track origin/$RELEASE_BRANCH
git cherry-pick $COMMIT_SHA
# TODO(xilaizhang): remove this step once the template is available on release branches.
- name: Get CP Template
run: |
curl -o PULL_REQUEST_CP_TEMPLATE.md https://raw.githubusercontent.com/flutter/flutter/master/.github/PR_TEMPLATE/PULL_REQUEST_CP_TEMPLATE.md
- name: Create PR on CP success
if: ${{ steps.attempt-cp.conclusion == 'success' }}
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
with:
base: ${{ env.RELEASE_BRANCH }}
branch: cp-${{ env.CHANNEL }}-${{ env.COMMIT_SHA }}
path: flutter
token: ${{ github.token}}
labels: |
cp: review
title: '[${{ env.CHANNEL }}-cherrypick] cherrypicks commit ${{ env.COMMIT_SHA }} from PR ${{ github.event.pull_request.title }}'
body-path: PULL_REQUEST_CP_TEMPLATE.md
- name: Leave Comment on CP failure
if: ${{ failure() && steps.attempt-cp.conclusion == 'failure' }}
run: |
FAILURE_MSG="Failed to create CP due to merge conflicts.<br>"
FAILURE_MSG+="You will need to create the PR manually. See [the cherrypick wiki](https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process) for more info."
gh pr comment ${{ github.event.pull_request.number }} -R flutter/flutter -b "${FAILURE_MSG}"
env:
GITHUB_TOKEN: ${{ github.token }}

0 comments on commit 32c7c31

Please sign in to comment.