Unverified Commit f0e616e2 authored by Xilai Zhang's avatar Xilai Zhang Committed by GitHub

[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)
parent 076cb8a3
......@@ -32,8 +32,8 @@ jobs:
- name: Checkout Flutter Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
repository: flutter/flutter
token: ${{ github.token }}
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
......@@ -45,9 +45,10 @@ jobs:
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 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
......@@ -55,16 +56,13 @@ jobs:
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: ${{ secrets.FLUTTERACTIONSBOT_CP_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
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: |
......@@ -72,4 +70,4 @@ jobs:
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.FLUTTERMIRRORINGBOT_TOKEN }}
GITHUB_TOKEN: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment