From f32c463e11d35e2bf56c29401a5a80572be1fccf Mon Sep 17 00:00:00 2001 From: Devin Nemec Date: Fri, 7 Aug 2020 15:49:54 -0500 Subject: [PATCH 1/7] allow separate author and destination repository --- README.md | 3 +++ action.yml | 4 ++++ entrypoint.sh | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a8deabb..5236c5c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ For the repository `https://github.com/cpina/push-to-another-repository-output` ### `user-email` (argument) 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`. + ### `API_TOKEN_GITHUB` (environment) E.g.: `API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}` diff --git a/action.yml b/action.yml index 5f639b8..99e77be 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: user-email: description: 'Email for the git commit' required: true + destination-repository-username: + description: '[Optional] Username/organization for the destination repository' + required: false runs: using: 'docker' image: 'Dockerfile' @@ -21,6 +24,7 @@ runs: - ${{ inputs.destination-github-username }} - ${{ inputs.destination-repository-name }} - ${{ inputs.user-email }} + - ${{ inputs.destination-repository-username }} branding: icon: 'git-commit' color: 'green' diff --git a/entrypoint.sh b/entrypoint.sh index cdbb5d7..a9b559a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,13 +5,18 @@ FOLDER="$1" GITHUB_USERNAME="$2" GITHUB_REPO="$3" USER_EMAIL="$4" +REPO_USERNAME="$5" + +if [ -z "$REPO_USERNAME" ] then + REPO_USERNAME= $GITHUB_USERNAME +fi CLONE_DIR=$(mktemp -d) # Setup git git config --global user.email "$USER_EMAIL" git config --global user.name "$GITHUB_USERNAME" -git clone "https://$API_TOKEN_GITHUB@github.com/$GITHUB_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" +git clone "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" ls -la "$CLONE_DIR" From a69edf2ee53d3672710410c7f01194df09710371 Mon Sep 17 00:00:00 2001 From: Devin Nemec Date: Mon, 10 Aug 2020 08:06:59 -0500 Subject: [PATCH 2/7] remove space --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a9b559a..e0986bd 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,7 +8,7 @@ USER_EMAIL="$4" REPO_USERNAME="$5" if [ -z "$REPO_USERNAME" ] then - REPO_USERNAME= $GITHUB_USERNAME + REPO_USERNAME=$GITHUB_USERNAME fi CLONE_DIR=$(mktemp -d) From b174d4c1a3045de9c11aab483040aa2bfa9ec78a Mon Sep 17 00:00:00 2001 From: Devin Nemec Date: Mon, 10 Aug 2020 08:31:08 -0500 Subject: [PATCH 3/7] fix if statement --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e0986bd..f8521a3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,7 +7,8 @@ GITHUB_REPO="$3" USER_EMAIL="$4" REPO_USERNAME="$5" -if [ -z "$REPO_USERNAME" ] then +if [ -z "$REPO_USERNAME" ] +then REPO_USERNAME=$GITHUB_USERNAME fi From b511d6418a66d9fd4c9d90e44db35744ae8db27a Mon Sep 17 00:00:00 2001 From: Devin Nemec Date: Mon, 10 Aug 2020 09:02:28 -0500 Subject: [PATCH 4/7] adding context and setting upstream --- entrypoint.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f8521a3..fba64f4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,22 +14,27 @@ fi CLONE_DIR=$(mktemp -d) +echo "Cloning destination git repository" # Setup git git config --global user.email "$USER_EMAIL" git config --global user.name "$GITHUB_USERNAME" git clone "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" - ls -la "$CLONE_DIR" +echo "Cleaning destination repository of old files" # Copy files into the git and deletes all git find "$CLONE_DIR" | grep -v "^$CLONE_DIR/\.git" | grep -v "^$CLONE_DIR$" | xargs rm -rf # delete all files (to handle deletions) - ls -la "$CLONE_DIR" +echo "Copying contents to to git repo" cp -r "$FOLDER"/* "$CLONE_DIR" - cd "$CLONE_DIR" +ls -la +echo "Adding git commit" git add . +git status git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" -git push origin master + +echo "Pushing git commit" +git push -u rigin master From dc3ca8455d54efe2056f3eabcbc4e5ed61a39fa6 Mon Sep 17 00:00:00 2001 From: Devin Nemec Date: Mon, 10 Aug 2020 09:03:53 -0500 Subject: [PATCH 5/7] fix typo --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index fba64f4..83b3ae9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,4 +37,4 @@ git status git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" echo "Pushing git commit" -git push -u rigin master +git push -u origin master From a76c6fd84a706ded64f23e2af11b4accb4fe3ef2 Mon Sep 17 00:00:00 2001 From: Devin Nemec Date: Mon, 10 Aug 2020 09:13:52 -0500 Subject: [PATCH 6/7] explicitly clone and use master branch --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 83b3ae9..4bef9f3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -18,7 +18,7 @@ echo "Cloning destination git repository" # Setup git git config --global user.email "$USER_EMAIL" git config --global user.name "$GITHUB_USERNAME" -git clone "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" +git clone --single-branch --branch master "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" ls -la "$CLONE_DIR" echo "Cleaning destination repository of old files" From 4b313f1b76a0d52cb8beedc417270e22b2a977b6 Mon Sep 17 00:00:00 2001 From: Devin Nemec Date: Mon, 10 Aug 2020 09:14:18 -0500 Subject: [PATCH 7/7] unset upstream (not needed) --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4bef9f3..0c4fe0f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,4 +37,4 @@ git status git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" echo "Pushing git commit" -git push -u origin master +git push origin master