Xilai Zhang f0e616e2b1
[github actions] refactor and fix cherry pick actions (#140499)
This PR makes the following changes:

1. Remove dependency on [peters/evans package](https://github.com/marketplace/actions/create-pull-request)<br>
The market place action introduces overheads that don't properly consume tokens. e.g. :[failed workflow that says token is not supplied](https://github.com/flutter/flutter/actions/runs/7282529195/job/19845096943)
This PR changes the market place action to git commands that we have full control over, provides better error msg for debug, and properly consumes token.

2. Align usage of tokens:<br>
All tokens in the workflow now uses flutter actions bot PAT token. From experiments, a mixed usage of different tokens in different steps sometimes cause the workflow to fail on authentication.

Tested: Tested with [a similar workflow on my personal repository](https://github.com/XilaiZhang/miscellaneous-side-project/blob/master/.github/workflows/easy-cp.yml), and it produces the [expected cherry pick PR as end result](https://github.com/flutter/flutter/pull/140497)
2024-01-03 23:08:59 +00:00

74 lines
3.4 KiB
YAML

# 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: flutteractionsbot/flutter
token: ${{ secrets.FLUTTERACTIONSBOT_CP_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 remote add upstream https://github.com/flutter/flutter.git
git fetch upstream $RELEASE_BRANCH
git fetch upstream master
git checkout -b cp-${CHANNEL}-${COMMIT_SHA} --track upstream/$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' }}
working-directory: ./flutter
run: |
git push -u origin cp-${CHANNEL}-${COMMIT_SHA}
gh pr create --title "[CP-${CHANNEL}]${PR_TITLE}" --body-file ../PULL_REQUEST_CP_TEMPLATE.md --base ${RELEASE_BRANCH} --label "cp: review" --repo flutter/flutter
env:
GITHUB_TOKEN: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }}
PR_TITLE: ${{ github.event.pull_request.title }}
- 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: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }}