-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f46d4e
commit 3373c67
Showing
5 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: PR for release branch | ||
on: | ||
push: | ||
branches: | ||
- 0.1.0 | ||
jobs: | ||
release_pull_request: | ||
runs-on: ubuntu-latest | ||
name: release_pull_request | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v1 | ||
- name: Create PR to branch | ||
uses: gorillio/cherry-pick@master | ||
with: | ||
pr_branch: '0.1.x' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITBOT_EMAIL: [email protected] | ||
DRY_RUN: false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# syntax = docker/dockerfile:1.1-experimental | ||
FROM alpine | ||
|
||
RUN apk --update --no-cache add git bash py3-pip | ||
|
||
RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing hub | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,58 @@ | ||
# github-action-cherry-pick | ||
Github Action to cherry-pick commit and create PR on Release Branch | ||
# Cherry-Pick Github Action | ||
|
||
Github Action to Cherry Pick commits from a branch (generally, master) and create a PR | ||
on another branch (Release branch). | ||
|
||
Most of the projects have Release branches and master branch. Master branch is where | ||
developers works on but we want to push the changes to the Release branches too. | ||
|
||
|
||
## Action | ||
|
||
* Push to the monitored branch X | ||
* Get the last commit SHA | ||
* Checkout the other branch, Y | ||
* Create a new pr branch Z on the branch Y | ||
* Cherry Pick the commits from X into Z | ||
* Push the branch and create the PR on base Y | ||
* PR title will be prefixed with `AUTO` | ||
|
||
#### Conditions: | ||
* If base branch commit contains `AUTO`, it wont recreate the PR. | ||
|
||
## Inputs | ||
|
||
#### `pr_branch` | ||
|
||
**Required** The branch name of on which PR should be created from the cherry-pick commit. | ||
|
||
#### `pr_labels` | ||
|
||
Labels to apply on the PR created. Default: `autocreated` | ||
|
||
## Example usage | ||
|
||
In this example, all the merges to the branch `0.1.0` will create a PR on `0.1.X` branch too. | ||
|
||
``` | ||
name: PR for release branch | ||
on: | ||
push: | ||
branches: | ||
- 0.1.0 | ||
jobs: | ||
release_pull_request: | ||
runs-on: ubuntu-latest | ||
name: release_pull_request | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v1 | ||
- name: Create PR to branch | ||
uses: gorillio/cherry-pick@master | ||
with: | ||
pr_branch: '0.1.x' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITBOT_EMAIL: <BOT_EMAIL> | ||
DRY_RUN: false | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: 'Create PR to other branches, on commits to a branch' | ||
description: 'Commits, pushes a new PR branch and creates PR for the commits.' | ||
author: '@himadrisingh' | ||
inputs: | ||
pr_branch: | ||
description: 'Target Branch to create PR' | ||
required: true | ||
pr_labels: | ||
description: 'Labels for the new PR' | ||
required: false | ||
default: 'autocreated' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/sh -l | ||
|
||
git_setup() { | ||
cat <<- EOF > $HOME/.netrc | ||
machine github.com | ||
login $GITHUB_ACTOR | ||
password $GITHUB_TOKEN | ||
machine api.github.com | ||
login $GITHUB_ACTOR | ||
password $GITHUB_TOKEN | ||
EOF | ||
chmod 600 $HOME/.netrc | ||
|
||
git config --global user.email "$GITBOT_EMAIL" | ||
git config --global user.name "$GITHUB_ACTOR" | ||
} | ||
|
||
git_cmd() { | ||
if [[ "${DRY_RUN:-false}" == "true" ]]; then | ||
echo $@ | ||
else | ||
eval $@ | ||
fi | ||
} | ||
|
||
PR_BRANCH="auto-$GITHUB_SHA" | ||
MESSAGE=$(git log -1 --format="%s" $GITHUB_SHA) | ||
|
||
if [[ $MESSAGE =~ "AUTO" ]]; then | ||
echo "Autocommit, NO ACTION" | ||
exit 0 | ||
fi | ||
|
||
git_setup | ||
git_cmd git remote update | ||
git_cmd git fetch --all | ||
git_cmd git checkout -b "${PR_BRANCH}" origin/"${INPUT_PR_BRANCH}" | ||
git_cmd git push -u origin "${PR_BRANCH}" | ||
git_cmd git cherry-pick "${GITHUB_SHA}" | ||
git_cmd git push | ||
git_cmd hub pull-request -b "${INPUT_PR_BRANCH}" -h "${PR_BRANCH}" -l "autocreated" -a "${GITHUB_ACTOR}" -m "\"AUTO: ${MESSAGE}\"" |