From a65a3a47cd4c9fa264a8fea19d9e0619ae450c16 Mon Sep 17 00:00:00 2001 From: gomorizsolt Date: Thu, 31 Oct 2019 09:02:56 +0100 Subject: [PATCH 01/15] Support commit options, update README.md accordingly --- README.md | 3 +++ actions.yml | 3 +++ entrypoint.sh | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b655d1..f8802a8 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Add the following step at the end of your job. commit_message: Apply automatic changes branch: ${{ github.head_ref }} + # Optional git params + commit_options: '--no-verify --signoff' + # Optional glob pattern of files which should be added to the commit file_pattern: src/\*.js env: diff --git a/actions.yml b/actions.yml index b58171f..6ef6985 100644 --- a/actions.yml +++ b/actions.yml @@ -7,6 +7,9 @@ inputs: commit_message: description: Commit message required: true + commit_options: + description: Commit options + required: false branch: description: Branch where changes should be pushed too required: true diff --git a/entrypoint.sh b/entrypoint.sh index 609e9b7..da2f1a2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -38,7 +38,7 @@ then git add $INPUT_FILE_PATTERN fi - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" $INPUT_COMMIT_OPTIONS git push --set-upstream origin "HEAD:$INPUT_BRANCH" else From b6dcf9430301384c5a3c21ecab67567cc18307e1 Mon Sep 17 00:00:00 2001 From: gomorizsolt Date: Thu, 31 Oct 2019 11:18:48 +0100 Subject: [PATCH 02/15] Add is_defined and get_value to improve on code's reusability --- actions.yml | 1 - entrypoint.sh | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/actions.yml b/actions.yml index 6ef6985..880a21b 100644 --- a/actions.yml +++ b/actions.yml @@ -16,7 +16,6 @@ inputs: file_pattern: description: File pattern used for "git add" required: false - default: '.' runs: using: 'docker' diff --git a/entrypoint.sh b/entrypoint.sh index da2f1a2..4c012cb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -18,6 +18,18 @@ EOF git config --global user.name "GitHub Actions" } +is_defined() { + [ ! -z "${1}" ] +} + +get_value() { + if is_defined "${1}"; then + return "${1}" + fi + + return "${2}" +} + # This section only runs if there have been file changes echo "Checking for uncommitted changes in the git working tree." @@ -30,15 +42,10 @@ then # Switch to branch from current Workflow run git checkout $INPUT_BRANCH - if [ -z ${INPUT_FILE_PATTERN+x} ]; - then - git add . - else - echo "INPUT_FILE_PATTERN value: $INPUT_FILE_PATTERN"; - git add $INPUT_FILE_PATTERN - fi + git add get_value "${INPUT_FILE_PATTERN}" '.' + + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" get_value "${INPUT_COMMIT_OPTIONS}" '' - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" $INPUT_COMMIT_OPTIONS git push --set-upstream origin "HEAD:$INPUT_BRANCH" else From 677efa2969c497c875fa950da30db29930438d0a Mon Sep 17 00:00:00 2001 From: gomorizsolt Date: Thu, 31 Oct 2019 11:25:08 +0100 Subject: [PATCH 03/15] Remove blank line --- entrypoint.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4c012cb..e52ca6d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -46,7 +46,6 @@ then git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" get_value "${INPUT_COMMIT_OPTIONS}" '' - git push --set-upstream origin "HEAD:$INPUT_BRANCH" else echo "Working tree clean. Nothing to commit." From af33cfbb5c0bf40935a020edf5479b5586e95417 Mon Sep 17 00:00:00 2001 From: gomorizsolt Date: Thu, 31 Oct 2019 14:49:38 +0100 Subject: [PATCH 04/15] Replace get_value with is_defined altogether --- entrypoint.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index e52ca6d..a51941b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,15 +22,6 @@ is_defined() { [ ! -z "${1}" ] } -get_value() { - if is_defined "${1}"; then - return "${1}" - fi - - return "${2}" -} - - # This section only runs if there have been file changes echo "Checking for uncommitted changes in the git working tree." if ! git diff --quiet @@ -42,9 +33,21 @@ then # Switch to branch from current Workflow run git checkout $INPUT_BRANCH - git add get_value "${INPUT_FILE_PATTERN}" '.' + if is_defined "${INPUT_FILE_PATTERN}"; then + echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}" - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" get_value "${INPUT_COMMIT_OPTIONS}" '' + git add get_value "${INPUT_FILE_PATTERN}" + else + git add . + fi + + if is_defined "${INPUT_COMMIT_OPTIONS}"; then + echo "INPUT_FILE_PATTERN: ${INPUT_COMMIT_OPTIONS}" + + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" "${INPUT_COMMIT_OPTIONS}" + else + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" + fi git push --set-upstream origin "HEAD:$INPUT_BRANCH" else From fa043bd47477b60691c792693caaa1b63485c3d5 Mon Sep 17 00:00:00 2001 From: gomorizsolt Date: Thu, 31 Oct 2019 15:13:27 +0100 Subject: [PATCH 05/15] Remove junk code --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a51941b..78638d3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -36,7 +36,7 @@ then if is_defined "${INPUT_FILE_PATTERN}"; then echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}" - git add get_value "${INPUT_FILE_PATTERN}" + git add "${INPUT_FILE_PATTERN}" else git add . fi From 1ad5315ba755cc61fad7498275da51798656c425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 09:51:19 +0100 Subject: [PATCH 06/15] Fix log statement --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 78638d3..247dd85 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -42,7 +42,7 @@ then fi if is_defined "${INPUT_COMMIT_OPTIONS}"; then - echo "INPUT_FILE_PATTERN: ${INPUT_COMMIT_OPTIONS}" + echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}" git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" "${INPUT_COMMIT_OPTIONS}" else From 3889fd6a6ccfb431e7c86e2a4a9c7e4df9d28357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 09:51:54 +0100 Subject: [PATCH 07/15] Add args entry to actions.yml --- actions.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actions.yml b/actions.yml index 880a21b..f114ac2 100644 --- a/actions.yml +++ b/actions.yml @@ -20,6 +20,11 @@ inputs: runs: using: 'docker' image: 'Dockerfile' + args: + - ${{ inputs.commit_message }} + - ${{ inputs.commit_options }} + - ${{ inputs.branch }} + - ${{ inputs.file_pattern }} branding: icon: 'git-commit' From eecee2898e9d467dd1a7c21a4e60bb9444c3aabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 10:04:42 +0100 Subject: [PATCH 08/15] Follow GH Action's naming restrictions --- actions.yml => action.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename actions.yml => action.yml (100%) diff --git a/actions.yml b/action.yml similarity index 100% rename from actions.yml rename to action.yml From 69d0349561280e00a1fe589d27c3a48107b0a120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 10:10:52 +0100 Subject: [PATCH 09/15] Log input params beforehand --- entrypoint.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 247dd85..49fbd0d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,10 @@ #!/bin/sh + +echo "${INPUT_COMMIT_MESSAGE}" +echo "${INPUT_COMMIT_OPTIONS}" +echo "${INPUT_BRANCH}" +echo "${INPUT_FILE_PATTERN}" + set -eu # Set up .netrc file with GitHub credentials From 760c9be2dc59f2b400ead1032ae165afa61207b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 10:15:22 +0100 Subject: [PATCH 10/15] Define default value for file_pattern --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index f114ac2..9ce27e3 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,7 @@ inputs: file_pattern: description: File pattern used for "git add" required: false + default: '.' runs: using: 'docker' From ddcd35eaa810eee5dc23db2c4569c4115b7aa826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 10:19:20 +0100 Subject: [PATCH 11/15] Remove is_defined() approach --- entrypoint.sh | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 49fbd0d..a788fa1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -24,10 +24,6 @@ EOF git config --global user.name "GitHub Actions" } -is_defined() { - [ ! -z "${1}" ] -} - # This section only runs if there have been file changes echo "Checking for uncommitted changes in the git working tree." if ! git diff --quiet @@ -39,21 +35,13 @@ then # Switch to branch from current Workflow run git checkout $INPUT_BRANCH - if is_defined "${INPUT_FILE_PATTERN}"; then - echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}" + echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}" - git add "${INPUT_FILE_PATTERN}" - else - git add . - fi + git add "${INPUT_FILE_PATTERN}" - if is_defined "${INPUT_COMMIT_OPTIONS}"; then - echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}" + echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}" - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" "${INPUT_COMMIT_OPTIONS}" - else - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" - fi + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" "${INPUT_COMMIT_OPTIONS}" git push --set-upstream origin "HEAD:$INPUT_BRANCH" else From bdc88aff2c41c95898038f8f6e59f0884b3c23ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 10:44:09 +0100 Subject: [PATCH 12/15] Re-add is_defined() to eliminate empty string in git commit --- entrypoint.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a788fa1..5756e36 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -24,6 +24,10 @@ EOF git config --global user.name "GitHub Actions" } +is_defined() { + [ ! -z "${1}" ] +} + # This section only runs if there have been file changes echo "Checking for uncommitted changes in the git working tree." if ! git diff --quiet @@ -41,7 +45,7 @@ then echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}" - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" "${INPUT_COMMIT_OPTIONS}" + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" is_defined "${INPUT_COMMIT_OPTIONS}" && "${INPUT_COMMIT_OPTIONS}" git push --set-upstream origin "HEAD:$INPUT_BRANCH" else From 2d23a29775fb922009b31eb0455f0acefa09ef77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 10:53:56 +0100 Subject: [PATCH 13/15] Use one-line if statement --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5756e36..673e044 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,7 +45,7 @@ then echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}" - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" is_defined "${INPUT_COMMIT_OPTIONS}" && "${INPUT_COMMIT_OPTIONS}" + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" if is_defined "${INPUT_COMMIT_OPTIONS}"; then "${INPUT_COMMIT_OPTIONS}"; fi git push --set-upstream origin "HEAD:$INPUT_BRANCH" else From 908446c00209926a299d9f4b8afb00fc5c61fd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 11:03:23 +0100 Subject: [PATCH 14/15] Use :+ to avoid empty string --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 673e044..37d53d4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,7 +45,7 @@ then echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}" - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" if is_defined "${INPUT_COMMIT_OPTIONS}"; then "${INPUT_COMMIT_OPTIONS}"; fi + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} git push --set-upstream origin "HEAD:$INPUT_BRANCH" else From 2fb839c669a15422d8bb81f4e8a08239bdee7849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6m=C3=B6ri=20Zsolt?= Date: Fri, 1 Nov 2019 11:11:19 +0100 Subject: [PATCH 15/15] Remove is_defined() --- entrypoint.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 37d53d4..50526fb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,5 @@ #!/bin/sh -echo "${INPUT_COMMIT_MESSAGE}" -echo "${INPUT_COMMIT_OPTIONS}" -echo "${INPUT_BRANCH}" -echo "${INPUT_FILE_PATTERN}" - set -eu # Set up .netrc file with GitHub credentials @@ -24,10 +19,6 @@ EOF git config --global user.name "GitHub Actions" } -is_defined() { - [ ! -z "${1}" ] -} - # This section only runs if there have been file changes echo "Checking for uncommitted changes in the git working tree." if ! git diff --quiet