diff --git a/.github/workflows/fork-cherry-pick.yml b/.github/workflows/fork-cherry-pick.yml index 1a684d5999..ff9bb9e207 100644 --- a/.github/workflows/fork-cherry-pick.yml +++ b/.github/workflows/fork-cherry-pick.yml @@ -1,7 +1,9 @@ -#This CI is disabled on main and meant to be enabled on forks as an easy way to cherry pick fork commits into main. +# This CI is disabled on main and meant to be enabled on forks as an easy way to cherry pick fork commits into main. +# In order to submit a PR to main, you must add the PR_BOT_PAT secret (personal access token) for the GitHub Action. +# The PR will be submitted from that user. Note, the PR_BOT_PAT user must have write access to the repo. name: Cherry pick PR to Cosmos SDK on: - #Set to trigger on every merge to main, not just a closed PR. + # Set to trigger on every merge to main, not just a closed PR. workflow_dispatch: pull_request_target: branches: @@ -10,39 +12,28 @@ on: jobs: cherry_pick: + permissions: write-all runs-on: ubuntu-latest name: Cherry pick into main if: github.event.pull_request.merged == true steps: - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 1 + uses: actions/checkout@v3 - name: Create PR Patch Branch shell: bash - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + env: + PR_NAME: pr-patch-${{ github.sha }} run: | - git config --global user.name "${GITHUB_ACTOR}" #Configs have to be set for pushing the cherry-picked changes onto fork pr-patch branch. - git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git remote add upstream https://github.com/cosmos/cosmos-sdk.git - git fetch --all # Get the latest code - git checkout -b pr-patch upstream/main # Create new branch based on main branch - git cherry-pick ${{github.event.pull_request.head.sha}} # Cherry pick the latest commit of PR - git push -u origin pr-patch-${{github.event.pull_request.head.sha}} # Push your changes to the remote branch + git config --global user.name "${{ github.actor }}" # Config have to be set for pushing the cherry-picked changes onto fork pr-patch branch. + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + git remote add upstream https://github.com/cosmos/cosmos-sdk.git + git fetch --all # Get the latest code + git checkout -b $PR_NAME upstream/main # Create new branch based on main branch + git cherry-pick -X theirs ${{ github.sha }} # Cherry pick the latest commit of PR + git push -u origin $PR_NAME # Push your changes to the remote branch - name: Autocreate PR shell: bash - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + env: + GH_TOKEN: ${{ secrets.PR_BOT_PAT }} run: | - curl --request POST \ - --url https://api.github.com/repos/cosmos/cosmos-sdk/pulls \ - --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ - --header 'content-type: application/json' \ - --data '{ - "title": "Automated PR for commit: ${{github.event.pull_request.head.sha}}", - "body":"Please merge these awesome changes in!", - "head":"${{github.event.pull_request.user.login}}:pr-patch-${{github.event.pull_request.head.sha}}", - "base":"main" - }' \ - --fail + gh pr create --repo cosmos/cosmos-sdk --base main --head "${{ github.event.repository.owner.login }}:pr-patch-${{ github.sha }}" --title "${{ github.event.pull_request.title }}" --body "Automated PR for commit: ${{ github.sha }} from ${{ github.repository }}"