Cherry-pick Labeled PR to Release Branch #90
This file contains 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
name: Cherry-pick Labeled PR to Release Branch | |
on: | |
workflow_dispatch | |
# on: | |
# pull_request_target: | |
# 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 | |
echo "CHANNEL=beta" >> $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 -n "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 | |
# echo "COMMIT_SHA=7d9010c3578338bc850d66c315bd6086f3d3dc9a" >> $GITHUB_ENV | |
echo "COMMIT_SHA=126606f9f30fb589835797b205c38244d71efd53" >> $GITHUB_ENV | |
# - name: Clone Flutter Repo | |
# run: | | |
# git clone --single-branch --branch master https://github.com/XilaiZhang/flutter.git | |
- name: Checkout Flutter Repo | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
repository: XilaiZhang/flutter | |
# token: ${{ secrets.PAT }} | |
path: flutter | |
ref: master | |
persist-credentials: false | |
# 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 --version | |
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-6 --track upstream/$RELEASE_BRANCH | |
git cherry-pick $COMMIT_SHA | |
- 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 | |
# fatal: unable to access 'https://github.com/flutter/flutter/': The requested URL returned error: 403 | |
- name: Create PR on CP success | |
if: ${{ steps.attempt-cp.conclusion == 'success' }} | |
working-directory: ./flutter | |
id: create-pr | |
run: | | |
git push -u https://${{ env.GITHUB_TOKEN }}@github.com/XilaiZhang/flutter cp-6 | |
{ | |
echo 'PR_URL<<EOF' | |
gh pr create --title "[cp-${CHANNEL}]${PR_TITLE}" --body-file ../PULL_REQUEST_CP_TEMPLATE.md --base ${RELEASE_BRANCH} --label "cp: review" --repo flutter/flutter --head XilaiZhang:cp-6 | |
echo EOF | |
} >> "$GITHUB_ENV" | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
PR_TITLE: 'some random title' | |
- name: Leave Comment on CP success | |
if: ${{ steps.create-pr.conclusion == 'success' }} | |
run: | | |
echo $PR_URL | |
NEW_PR_NUMBER="${PR_URL##*/}" | |
SUCCESS_MSG="Hello @${{ github.actor }}! Looks like you attached the cp label and successfully created a cherry pick pr.<br>" | |
SUCCESS_MSG+="Please fill in the information in PR description above, and a release engineer will review this request." | |
gh pr comment $NEW_PR_NUMBER -R flutter/flutter -b "${SUCCESS_MSG}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
- 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 3305 -R flutter/cocoon -b "${FAILURE_MSG}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |