From 80f825a9bce3ecc04f591d76d0f53182f9031886 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 09:27:50 +0200 Subject: [PATCH 01/14] Update how the branch is checked out --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 58fe291..0f19ac9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,7 +26,7 @@ then git_setup # Switch to branch from current Workflow run - git checkout "${GITHUB_REF:11}" + git checkout "$GITHUB_REF" | awk -F / '{ print $3 }' git add . From ea88bd7cdeaa37ebb2c2b82483688f17cfd6408c Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 09:42:26 +0200 Subject: [PATCH 02/14] Try to fix checkout command --- entrypoint.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0f19ac9..3adb9bd 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,8 +25,10 @@ if ! git diff --quiet then git_setup + : ${PUSH_BRANCH:=`echo "$GITHUB_HEAD_REF" | awk -F / '{ print $3 }' `} + # Switch to branch from current Workflow run - git checkout "$GITHUB_REF" | awk -F / '{ print $3 }' + git checkout $PUSH_BRANCH git add . From f4fd59c4d432aa052c3756cd897f43e72b286d78 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 09:49:26 +0200 Subject: [PATCH 03/14] Use $PUSH_BRANCH in git push command --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3adb9bd..47d6a80 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -34,7 +34,7 @@ then git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR_NAME <$INPUT_COMMIT_AUTHOR_EMAIL>" - git push --set-upstream origin "${GITHUB_REF:11}" + git push --set-upstream origin $PUSH_BRANCH else echo "Working tree clean. Nothing to commit." fi From ef8610f6dfb526e2818b28fd3776d5e45805d3c7 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 09:56:20 +0200 Subject: [PATCH 04/14] Fix git push --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 47d6a80..a2b8873 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -34,7 +34,7 @@ then git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR_NAME <$INPUT_COMMIT_AUTHOR_EMAIL>" - git push --set-upstream origin $PUSH_BRANCH + git push --set-upstream origin HEAD:"$PUSH_BRANCH" else echo "Working tree clean. Nothing to commit." fi From 12282205b7d0f5a03003906810d97fd34e55b4df Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:01:27 +0200 Subject: [PATCH 05/14] Try to fix git push --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a2b8873..af3f628 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -34,7 +34,7 @@ then git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR_NAME <$INPUT_COMMIT_AUTHOR_EMAIL>" - git push --set-upstream origin HEAD:"$PUSH_BRANCH" + git push --set-upstream origin "HEAD:$PUSH_BRANCH" else echo "Working tree clean. Nothing to commit." fi From ba1c2a604734b631fe310b20b07b8896c4f41df0 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:08:13 +0200 Subject: [PATCH 06/14] Try to fix that push command --- entrypoint.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index af3f628..9a6c847 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,6 +27,8 @@ then : ${PUSH_BRANCH:=`echo "$GITHUB_HEAD_REF" | awk -F / '{ print $3 }' `} + git switch -c $PUSH_BRANCH + # Switch to branch from current Workflow run git checkout $PUSH_BRANCH @@ -34,7 +36,7 @@ then git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR_NAME <$INPUT_COMMIT_AUTHOR_EMAIL>" - git push --set-upstream origin "HEAD:$PUSH_BRANCH" + git push --set-upstream origin $PUSH_BRANCH else echo "Working tree clean. Nothing to commit." fi From 0b91625aed13f5bc242f8a40af2f456ebec215b0 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:11:50 +0200 Subject: [PATCH 07/14] WIP --- entrypoint.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9a6c847..c0c069e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,10 +27,8 @@ then : ${PUSH_BRANCH:=`echo "$GITHUB_HEAD_REF" | awk -F / '{ print $3 }' `} - git switch -c $PUSH_BRANCH - # Switch to branch from current Workflow run - git checkout $PUSH_BRANCH + git checkout -b $PUSH_BRANCH git add . From ed0ebb9072ae3a98cc962aa3598c0991c42146ba Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:19:29 +0200 Subject: [PATCH 08/14] Log $PUSH_BRANCH value --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index c0c069e..323d820 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,6 +27,8 @@ then : ${PUSH_BRANCH:=`echo "$GITHUB_HEAD_REF" | awk -F / '{ print $3 }' `} + echo "Push Branch Value: $PUSH_BRANCH"; + # Switch to branch from current Workflow run git checkout -b $PUSH_BRANCH From 8cc484cbc554155d09a09f493ad7f6c19ec8b248 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:30:36 +0200 Subject: [PATCH 09/14] Add ref argument --- actions.yml | 4 ++++ entrypoint.sh | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/actions.yml b/actions.yml index 84af776..ca95851 100644 --- a/actions.yml +++ b/actions.yml @@ -14,6 +14,10 @@ inputs: description: 'Email address of the commit author' required: true + ref: + description: Branch to use + required: true + runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 323d820..e3813e0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,13 +30,13 @@ then echo "Push Branch Value: $PUSH_BRANCH"; # Switch to branch from current Workflow run - git checkout -b $PUSH_BRANCH + git checkout -b $INPUT_REF git add . git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR_NAME <$INPUT_COMMIT_AUTHOR_EMAIL>" - git push --set-upstream origin $PUSH_BRANCH + git push --set-upstream origin $INPUT_REF else echo "Working tree clean. Nothing to commit." fi From 72e2d4cb1eb61e378e2fca52d4617f0c45036c44 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:33:12 +0200 Subject: [PATCH 10/14] Fix git checkout --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e3813e0..3cd61e6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,7 +30,7 @@ then echo "Push Branch Value: $PUSH_BRANCH"; # Switch to branch from current Workflow run - git checkout -b $INPUT_REF + git checkout $INPUT_REF git add . From 6f1c9227f5d86984a15d4c2d091df3da0c67cc96 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:37:16 +0200 Subject: [PATCH 11/14] Fix git push command --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3cd61e6..4d326c2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -36,7 +36,7 @@ then git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR_NAME <$INPUT_COMMIT_AUTHOR_EMAIL>" - git push --set-upstream origin $INPUT_REF + git push --set-upstream origin "HEAD:$INPUT_REF" else echo "Working tree clean. Nothing to commit." fi From 6c17ba31a9d8059c68e619ee1a55c7a87c87269f Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:43:15 +0200 Subject: [PATCH 12/14] Output $INPUT_REF --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 4d326c2..e653976 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -29,6 +29,8 @@ then echo "Push Branch Value: $PUSH_BRANCH"; + echo "Input Ref: $INPUT_REF"; + # Switch to branch from current Workflow run git checkout $INPUT_REF From 7fec5eda4ad50b86c33afb938139bff8997d446d Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:46:35 +0200 Subject: [PATCH 13/14] Cleanup --- actions.yml | 9 ++++----- entrypoint.sh | 6 +----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/actions.yml b/actions.yml index ca95851..2afa7bd 100644 --- a/actions.yml +++ b/actions.yml @@ -5,17 +5,16 @@ author: Stefan Zweifel inputs: commit_message: - description: 'Commit message' + description: Commit message required: true commit_author_name: - description: 'Name of the commit author' + description: Name of the commit author required: true commit_author_email: - description: 'Email address of the commit author' + description: Email address of the commit author required: true - ref: - description: Branch to use + description: Branch where changes should be pushed too required: true runs: diff --git a/entrypoint.sh b/entrypoint.sh index e653976..2c7d76d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,11 +25,7 @@ if ! git diff --quiet then git_setup - : ${PUSH_BRANCH:=`echo "$GITHUB_HEAD_REF" | awk -F / '{ print $3 }' `} - - echo "Push Branch Value: $PUSH_BRANCH"; - - echo "Input Ref: $INPUT_REF"; + echo "INPUT_REF value: $INPUT_REF"; # Switch to branch from current Workflow run git checkout $INPUT_REF From 4c6d2819f0c53d9e0951e5a6246dc6653c7f6e4f Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 20 Sep 2019 10:47:19 +0200 Subject: [PATCH 14/14] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 728c5ab..a287fcd 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Add the following step at the end of your job. commit_author_email: john.doe@example.com commit_author_name: John Doe commit_message: Apply automatic changes + ref: ${{ github.head_ref }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` @@ -32,6 +33,7 @@ The following inputs are required - `commit_author_email`: The Commit Authors Email Address - `commit_author_name`: The Commit Authors Name - `commit_message`: The commit message used when changes are available +- `ref`: Branch where changes should be pushed too ### Environment Variables