From f980b48b416daac40ac606b0656e5364923e5eaf Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 21:50:53 -0300 Subject: [PATCH 01/14] update git push to remote action Signed-off-by: GuillaumeFalourd --- action.yml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 47fda29..ddb66cf 100644 --- a/action.yml +++ b/action.yml @@ -52,7 +52,8 @@ outputs: runs: using: "composite" steps: - - name: Git push and commit + - name: Git push and commit origin + if: ${{ inputs.remote_repository }} == 'origin' run: | CURRENT_BRANCH=${GITHUB_REF} case $CURRENT_BRANCH in "refs/heads/"*) @@ -83,7 +84,7 @@ runs: git config --local user.email "${{ inputs.email }}" git config --local user.name "${{ inputs.name }}" - + if [[ `git status --porcelain` ]]; then git add ${{ inputs.files }} -v git commit -m "${{ inputs.commit_message }}" $EMPTY @@ -97,7 +98,76 @@ runs: else echo "WARNING: No changes were detected. git commit push action aborted." fi + shell: bash + - name: Git push and commit remote + if: ${{ inputs.remote_repository }} != 'origin' + run: | + if [ -z "${{ inputs.access_token }}" ]; then + echo "WARNING: The access_token input is mandatory to push files to another repository." + exit 1 + fi + + REGEX="^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+)$" + + if [[ ${{ inputs.remote_repository }} =~ $REGEX ]]; then + PROTOCOL=${BASH_REMATCH[1]} + SEPARATOR=${BASH_REMATCH[2]} + HOSTNAME=${BASH_REMATCH[3]} + DESTINATION_OWNER=${BASH_REMATCH[4]} + DESTINATION_REPOSITORY=${BASH_REMATCH[5]} + DESTINATION_REPOSITORY=${DESTINATION_REPOSITORY//.git/ } + + CLONE_DIRECTORY=$(mktemp -d) + + echo "##### Cloning destination Github repository #####" + # Setup git + git config --global user.email "${{ inputs.email }}" + git config --global user.name "${{ inputs.name }}" + git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all + git clone "https://${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY.git" "$CLONE_DIRECTORY" + ls -la "$CLONE_DIRECTORY" + + echo + echo "##### Copying contents to destination Github repository #####" + if [ -z "${{ inputs.target_dir }}" ]; then + cp -rvf "${{ inputs.source_files }}" "$CLONE_DIRECTORY" + else + mkdir -p "$CLONE_DIRECTORY/${{ inputs.target_dir }}" + cp -rvf "${{ inputs.source_files }}" "$CLONE_DIRECTORY/${{ inputs.target_dir }}" + fi + + cd "$CLONE_DIRECTORY" + + # Create new branch + REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY + git remote set-url origin $REMOTE_URL + git fetch origin + git checkout -b ${{ inputs.target_branch }} + git add . + git status + + # Won't commit if no changes were made + git diff-index --quiet HEAD || git commit --message "${{ inputs.commit_message }}" + + echo + echo "##### Pushing git commit #####" + # --set-upstream: sets the branch when pushing to a branch that does not exist + git push -f -u origin "${{ inputs.target_branch }}" + + else + echo + echo "WARNING: Couldn't read remote_repository URL input." + echo "ACCEPTED FORMAT:" + echo "git://github.com//.git" + echo "or" + echo "git@github.com:/.git" + echo "or" + echo "https://github.com//.git" + echo "or" + echo "https://github.com//" + exit 1 + fi shell: bash branding: From 5f659c1817ae906512f5008c83586947f6dce6c0 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 22:04:04 -0300 Subject: [PATCH 02/14] update git push to remote action Signed-off-by: GuillaumeFalourd --- action.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index ddb66cf..39e9cba 100644 --- a/action.yml +++ b/action.yml @@ -53,8 +53,9 @@ runs: using: "composite" steps: - name: Git push and commit origin - if: ${{ inputs.remote_repository }} == 'origin' + if: ${{ inputs.remote_repository == 'origin' }} run: | + echo "##### Git Push and Commit ORIGIN #####" CURRENT_BRANCH=${GITHUB_REF} case $CURRENT_BRANCH in "refs/heads/"*) CURRENT_BRANCH=$(echo "$CURRENT_BRANCH" | sed "s@refs/heads/@@") @@ -101,8 +102,9 @@ runs: shell: bash - name: Git push and commit remote - if: ${{ inputs.remote_repository }} != 'origin' + if: ${{ inputs.remote_repository != 'origin' }} run: | + echo "##### Git Push and Commit REMOTE #####" if [ -z "${{ inputs.access_token }}" ]; then echo "WARNING: The access_token input is mandatory to push files to another repository." exit 1 From 49269c1e8234427a9b4fff2c0bac478fb13e14de Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 22:08:29 -0300 Subject: [PATCH 03/14] update git push to remote action Signed-off-by: GuillaumeFalourd --- action.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 39e9cba..dcc73c1 100644 --- a/action.yml +++ b/action.yml @@ -132,12 +132,7 @@ runs: echo echo "##### Copying contents to destination Github repository #####" - if [ -z "${{ inputs.target_dir }}" ]; then - cp -rvf "${{ inputs.source_files }}" "$CLONE_DIRECTORY" - else - mkdir -p "$CLONE_DIRECTORY/${{ inputs.target_dir }}" - cp -rvf "${{ inputs.source_files }}" "$CLONE_DIRECTORY/${{ inputs.target_dir }}" - fi + cp -rvf "${{ inputs.files }}" "$CLONE_DIRECTORY" cd "$CLONE_DIRECTORY" From 4f78503c4bfa118f9db7b2bcd6cb0c9291aebdd7 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 22:13:47 -0300 Subject: [PATCH 04/14] update git push to remote action Signed-off-by: GuillaumeFalourd --- action.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/action.yml b/action.yml index dcc73c1..d38f9fe 100644 --- a/action.yml +++ b/action.yml @@ -55,7 +55,6 @@ runs: - name: Git push and commit origin if: ${{ inputs.remote_repository == 'origin' }} run: | - echo "##### Git Push and Commit ORIGIN #####" CURRENT_BRANCH=${GITHUB_REF} case $CURRENT_BRANCH in "refs/heads/"*) CURRENT_BRANCH=$(echo "$CURRENT_BRANCH" | sed "s@refs/heads/@@") @@ -104,7 +103,6 @@ runs: - name: Git push and commit remote if: ${{ inputs.remote_repository != 'origin' }} run: | - echo "##### Git Push and Commit REMOTE #####" if [ -z "${{ inputs.access_token }}" ]; then echo "WARNING: The access_token input is mandatory to push files to another repository." exit 1 @@ -140,7 +138,7 @@ runs: REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY git remote set-url origin $REMOTE_URL git fetch origin - git checkout -b ${{ inputs.target_branch }} + git checkout ${{ inputs.target_branch }} git add . git status From d53ba3b49f796ae458b7bdcd5eca0bddafc5d463 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 22:24:08 -0300 Subject: [PATCH 05/14] update git push to remote action Signed-off-by: GuillaumeFalourd --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index d38f9fe..c858e21 100644 --- a/action.yml +++ b/action.yml @@ -138,6 +138,10 @@ runs: REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY git remote set-url origin $REMOTE_URL git fetch origin + git ls-remote --heads origin ${{ inputs.target_branch }} | wc -l + if [ "$?" != "1" ]; then + git checkout -b ${{ inputs.target_branch }} + fi git checkout ${{ inputs.target_branch }} git add . git status From 865a51b5807c3666695bb4f1d2c0c022211839e9 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 22:30:25 -0300 Subject: [PATCH 06/14] update git push to remote action Signed-off-by: GuillaumeFalourd --- action.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index c858e21..ee33527 100644 --- a/action.yml +++ b/action.yml @@ -138,11 +138,13 @@ runs: REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY git remote set-url origin $REMOTE_URL git fetch origin - git ls-remote --heads origin ${{ inputs.target_branch }} | wc -l - if [ "$?" != "1" ]; then + BE=$(git ls-remote --heads origin ${{ inputs.target_branch }} | wc -l) + if [[ $BE == *"0"* ]]; then + echo "##### Target branch doesn't exist. Creating new branch #####" git checkout -b ${{ inputs.target_branch }} + else + git checkout ${{ inputs.target_branch }} fi - git checkout ${{ inputs.target_branch }} git add . git status From 56985c46b9814e899b6f136969ef48da49ffcfec Mon Sep 17 00:00:00 2001 From: Guillaume Falourd Date: Thu, 6 Jan 2022 22:50:27 -0300 Subject: [PATCH 07/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6aaa628..adfbc45 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ _**Note**: This action is supported on **all runners** operating systems (`ubunt steps: - uses: actions/checkout@v2.3.4 # [...] --> steps with actions or commands updating repository files - - uses: GuillaumeFalourd/git-commit-push@v1.1 + - uses: GuillaumeFalourd/git-commit-push@v1.2 ``` ### `2️⃣ Full`: Commit and Push with `customized` parameters @@ -33,7 +33,7 @@ _**Note**: This action is supported on **all runners** operating systems (`ubunt steps: - uses: actions/checkout@v2.3.4 # [...] --> steps with actions or commands updating repository files - - uses: GuillaumeFalourd/git-commit-push@v1.1 + - uses: GuillaumeFalourd/git-commit-push@v1.2 with: email: ${{ github.actor }}@users.noreply.github.com name: ${{ github.actor }} From 83d479084f67abea08e8541fdd6edd4decd5998b Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Fri, 7 Jan 2022 02:32:59 +0000 Subject: [PATCH 08/14] Commit performed using Push and Commit action --- reports/ubuntu_report_minimal.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reports/ubuntu_report_minimal.txt b/reports/ubuntu_report_minimal.txt index 79751bd..49af995 100644 --- a/reports/ubuntu_report_minimal.txt +++ b/reports/ubuntu_report_minimal.txt @@ -1 +1 @@ -Thu Jan 6 02:32:39 UTC 2022 +Fri Jan 7 02:32:59 UTC 2022 From 92277f3abbdaf566dffb7b9b3ea11b423d766da2 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 23:41:45 -0300 Subject: [PATCH 09/14] update git push to remote action Signed-off-by: GuillaumeFalourd --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ee33527..8b4d6ed 100644 --- a/action.yml +++ b/action.yml @@ -91,7 +91,7 @@ runs: git branch push-and-commit-action-${{ github.run_id }}-${{ github.job }} git fetch "${{ inputs.remote_repository }}" "$CURRENT_BRANCH" git checkout "$CURRENT_BRANCH" - git merge push-and-commit-action-${{ github.run_id }}-${{ github.job }} + git merge -X ours push-and-commit-action-${{ github.run_id }}-${{ github.job }} git branch -d push-and-commit-action-${{ github.run_id }}-${{ github.job }} git push "${{ inputs.remote_repository }}" "$CURRENT_BRANCH:$TARGET_BRANCH" --follow-tags $FORCE $TAGS From e7a4b74c2ae71596a2077f6f74d9be93cc176de4 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 23:45:30 -0300 Subject: [PATCH 10/14] update creating branch section Signed-off-by: GuillaumeFalourd --- action.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 8b4d6ed..c312da4 100644 --- a/action.yml +++ b/action.yml @@ -91,7 +91,7 @@ runs: git branch push-and-commit-action-${{ github.run_id }}-${{ github.job }} git fetch "${{ inputs.remote_repository }}" "$CURRENT_BRANCH" git checkout "$CURRENT_BRANCH" - git merge -X ours push-and-commit-action-${{ github.run_id }}-${{ github.job }} + git merge push-and-commit-action-${{ github.run_id }}-${{ github.job }} git branch -d push-and-commit-action-${{ github.run_id }}-${{ github.job }} git push "${{ inputs.remote_repository }}" "$CURRENT_BRANCH:$TARGET_BRANCH" --follow-tags $FORCE $TAGS @@ -134,10 +134,21 @@ runs: cd "$CLONE_DIRECTORY" - # Create new branch - REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY + REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY git remote set-url origin $REMOTE_URL git fetch origin + + if [ -z "${{ inputs.target_dir }}" ]; then + git add ${{ inputs.source_files }} + else + git add ${{ inputs.target_dir }}/${{ inputs.source_files }} + fi + # Won't commit if no changes were made + git diff-index --quiet HEAD || git commit --message "${{ inputs.commit_message }}" + git status + git branch copy-push-files-action-${{ github.run_id }}-${{ github.job }} + + # Create new branch (if necessary) BE=$(git ls-remote --heads origin ${{ inputs.target_branch }} | wc -l) if [[ $BE == *"0"* ]]; then echo "##### Target branch doesn't exist. Creating new branch #####" @@ -145,15 +156,11 @@ runs: else git checkout ${{ inputs.target_branch }} fi - git add . - git status - - # Won't commit if no changes were made - git diff-index --quiet HEAD || git commit --message "${{ inputs.commit_message }}" + git merge -X theirs copy-push-files-action-${{ github.run_id }}-${{ github.job }} + git branch -d copy-push-files-action-${{ github.run_id }}-${{ github.job }} echo echo "##### Pushing git commit #####" - # --set-upstream: sets the branch when pushing to a branch that does not exist git push -f -u origin "${{ inputs.target_branch }}" else From c80328cf2744d6a89eb7fd42f00f5832cc942de3 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 6 Jan 2022 23:50:46 -0300 Subject: [PATCH 11/14] update creating branch section Signed-off-by: GuillaumeFalourd --- action.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index c312da4..ac06b9f 100644 --- a/action.yml +++ b/action.yml @@ -134,15 +134,12 @@ runs: cd "$CLONE_DIRECTORY" - REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY + REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY git remote set-url origin $REMOTE_URL git fetch origin - if [ -z "${{ inputs.target_dir }}" ]; then - git add ${{ inputs.source_files }} - else - git add ${{ inputs.target_dir }}/${{ inputs.source_files }} - fi + git add ${{ inputs.files }} + # Won't commit if no changes were made git diff-index --quiet HEAD || git commit --message "${{ inputs.commit_message }}" git status From e4b7fab0d4e48eb34c1f4b62b797f6052055afaa Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Fri, 7 Jan 2022 04:17:05 +0000 Subject: [PATCH 12/14] Commit performed using Push and Commit action --- reports/macos_report_minimal.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reports/macos_report_minimal.txt b/reports/macos_report_minimal.txt index 676c933..dd38453 100644 --- a/reports/macos_report_minimal.txt +++ b/reports/macos_report_minimal.txt @@ -1 +1 @@ -Thu Jan 6 04:17:26 UTC 2022 +Fri Jan 7 04:17:05 UTC 2022 From e269c406c678e5f65fe166bc0eba2a45eb576be7 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Fri, 7 Jan 2022 06:23:22 +0000 Subject: [PATCH 13/14] Commit performed using Push and Commit action --- reports/windows_report_minimal.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reports/windows_report_minimal.txt b/reports/windows_report_minimal.txt index 72d2d8d..6c17bba 100644 --- a/reports/windows_report_minimal.txt +++ b/reports/windows_report_minimal.txt @@ -1 +1 @@ -Thu Jan 6 06:23:22 CUT 2022 +Fri Jan 7 06:23:21 CUT 2022 From e4a8382a15a4e406292f50b0c3e12577c9aaf584 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Fri, 7 Jan 2022 09:31:11 -0300 Subject: [PATCH 14/14] update creating branch section Signed-off-by: GuillaumeFalourd --- action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ac06b9f..f81c62f 100644 --- a/action.yml +++ b/action.yml @@ -116,7 +116,9 @@ runs: HOSTNAME=${BASH_REMATCH[3]} DESTINATION_OWNER=${BASH_REMATCH[4]} DESTINATION_REPOSITORY=${BASH_REMATCH[5]} - DESTINATION_REPOSITORY=${DESTINATION_REPOSITORY//.git/ } + if [[ $DESTINATION_REPOSITORY == *'.git'* ]] && [[ $DESTINATION_REPOSITORY != *'.github.io'* ]]; then + DESTINATION_REPOSITORY=${DESTINATION_REPOSITORY//.git/ } + fi CLONE_DIRECTORY=$(mktemp -d)