Skip to content

Commit

Permalink
ci: create gh action to create cherry-pick PRs for releases (#7621)
Browse files Browse the repository at this point in the history
## **Description**

This PR adds a GItHub action that makes it easy to provide the:
- Base Branch (generally a release branch)
- Commit Hash (hash to be cherry picked)
- PR Number Associated with Commit 

This enables developers, QA and release support staff an easy way to
create cherry picked PRs for releases.

## **Related issues**

NA

## **Manual testing steps**

1. Pull the PR down
2. Run the `scripts/create-cherry-pick-pr.sh` with the correct args
3. The PR will be created

## **Screenshots/Recordings**

NA

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [x] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **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.

---------

Co-authored-by: Cal Leung <cleun007@gmail.com>
  • Loading branch information
sethkfman and Cal-L authored Oct 31, 2023
1 parent b76e9b4 commit 7e68812
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
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@v2

- 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 }}
32 changes: 32 additions & 0 deletions 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 metamaskbot
git config user.email metamaskbot@users.noreply.github.com

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}"

0 comments on commit 7e68812

Please sign in to comment.