Skip to content

Commit

Permalink
ci: add create-cherry-pick-pr github action (#24074)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
This PR adds a github action for creating cherry pick commits, similarly
as Mobile does. With this action we can pass the following arguments:
- target branch to merge the cherry-pick
- commit to cherry-pick
- PR # associated with the cherry-pick



Reference: this PR is based on Seth's PR for Mobile
MetaMask/metamask-mobile@7e68812

You can see how this works in Mobile:

1. Go to
https://github.com/MetaMask/metamask-mobile/actions/workflows/create-cherry-pick-pr.yml
2. Click Run Workflow
3. Add the target RC branch, the commit to cherry-pick and the PR number
4. You'll get a new branch with the cherry-pick (example of cherry-pick
from the github action
[here](MetaMask/metamask-mobile#9265))


## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**
Once this is merged, we'll be able to trigger the Cherry Pick Commit
action:

![Screenshot from 2024-04-17
10-17-16](https://github.com/MetaMask/metamask-extension/assets/54408225/16d048d5-63a3-4f5e-a37c-f425b5c35bd5)


## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
seaona authored Apr 18, 2024
1 parent e6428f8 commit c45bc6b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .circleci/scripts/create-cherry-pick-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

# Takes in 3 args
# - 1 - Base PR Branch Name
# - 2 - Commit Hash
# - 3 - PR Number

BASE_PR_BRANCH_NAME="${1}"
COMMIT_HASH_TO_CHERRY_PICK="${2}"
PR_BRANCH_NAME="chore/cherry-pick-${3}"
PR_TITLE="chore: cherry-pick #${3}"
PR_BODY="This PR cherry-picks #${3}"

git config user.name "MetaMask Bot"
git config user.email "[email protected]"

git checkout "${BASE_PR_BRANCH_NAME}"
git pull
git checkout -b "${PR_BRANCH_NAME}"
git cherry-pick "${COMMIT_HASH_TO_CHERRY_PICK}"

git push --set-upstream origin "${PR_BRANCH_NAME}"

gh pr create \
--draft \
--title "${PR_TITLE}" \
--body "${PR_BODY}" \
--head "${BASE_PR_BRANCH_NAME}"
31 changes: 31 additions & 0 deletions .github/workflows/create-cherry-pick-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Cherry Pick Commit

on:
workflow_dispatch:
inputs:
branch_name:
description: 'Branch name you want the cherry-pick branch to be based from'
required: true
commit_hash:
description: 'Commit Hash'
required: true
PR_number:
description: 'PR # Associated with Cherry Pick'
required: true


jobs:
cherry-pick:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create Cherry Pick PR
id: create-cherry-pick-pr
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./scripts/create-cherry-pick-pr.sh ${{ github.event.inputs.branch_name }} ${{ github.event.inputs.commit_hash }} ${{ github.event.inputs.PR_number }}

0 comments on commit c45bc6b

Please sign in to comment.