From 26fe0168e26d0fcc47f44021a4af880f557d2f85 Mon Sep 17 00:00:00 2001 From: Taro Matsuzawa Date: Wed, 23 Sep 2020 16:49:12 +0900 Subject: [PATCH 1/2] supports target branch for github-renaming --- README.md | 3 +++ action.yml | 4 ++++ entrypoint.sh | 9 +++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5236c5c..0505312 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ The email that will be used for the commit in the destination-repository-name. ### `destination-repository-username` (argument) [optional] The Username/Organization for the destination repository, if different from `destination-github-username`. For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`. +### `target-branch` (argument) [optional] +The branch name for the destination repository, if different from `master`. + ### `API_TOKEN_GITHUB` (environment) E.g.: `API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}` diff --git a/action.yml b/action.yml index 99e77be..b3e65ef 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,9 @@ inputs: destination-repository-username: description: '[Optional] Username/organization for the destination repository' required: false + target-branch: + description: '[Optional] set target branch name for the destination repository' + required: false runs: using: 'docker' image: 'Dockerfile' @@ -25,6 +28,7 @@ runs: - ${{ inputs.destination-repository-name }} - ${{ inputs.user-email }} - ${{ inputs.destination-repository-username }} + - ${{ inputs.target-branch }} branding: icon: 'git-commit' color: 'green' diff --git a/entrypoint.sh b/entrypoint.sh index 0c4fe0f..ee2b830 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,11 +6,16 @@ GITHUB_USERNAME="$2" GITHUB_REPO="$3" USER_EMAIL="$4" REPO_USERNAME="$5" +TARGET_BRANCH="$6" if [ -z "$REPO_USERNAME" ] then REPO_USERNAME=$GITHUB_USERNAME fi +if [ -z "$TARGET_BRANCH"] +then + TARGET_BRANCH="master" +fi CLONE_DIR=$(mktemp -d) @@ -18,7 +23,7 @@ echo "Cloning destination git repository" # Setup git git config --global user.email "$USER_EMAIL" git config --global user.name "$GITHUB_USERNAME" -git clone --single-branch --branch master "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" +git clone --single-branch --branch $TARGET_BRANCH "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" ls -la "$CLONE_DIR" echo "Cleaning destination repository of old files" @@ -37,4 +42,4 @@ git status git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" echo "Pushing git commit" -git push origin master +git push origin $TARGET_BRANCH From 80a683b9ad7390899a506e8191ee4a41222345fa Mon Sep 17 00:00:00 2001 From: Taro Matsuzawa Date: Wed, 23 Sep 2020 16:53:28 +0900 Subject: [PATCH 2/2] fixes missing ] --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index ee2b830..e328bf3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,7 +12,7 @@ if [ -z "$REPO_USERNAME" ] then REPO_USERNAME=$GITHUB_USERNAME fi -if [ -z "$TARGET_BRANCH"] +if [ -z "$TARGET_BRANCH" ] then TARGET_BRANCH="master" fi