@@ -6,20 +6,34 @@ if "$INPUT_DISABLE_GLOBBING"; then
66 set -o noglob;
77fi
88
9+ _set_github_output () {
10+ local name=${1}
11+ local value=${2}
12+
13+ # Check if $GITHUB_OUTPUT is available
14+ # (Feature detection will be removed in spring 2023)
15+ if [ -z ${GITHUB_OUTPUT+x} ]; then
16+ echo " ::set-output name=$name ::$value " ;
17+ else
18+ echo " $name =$value " >> $GITHUB_OUTPUT ;
19+ fi
20+ }
21+
22+ _log () {
23+ local level=${1}
24+ local message=${2}
25+
26+ echo " ::$level ::$message " ;
27+ }
28+
929_main () {
1030 _check_if_git_is_available
1131
1232 _switch_to_repository
1333
1434 if _git_is_dirty || " $INPUT_SKIP_DIRTY_CHECK " ; then
1535
16- # Check if $GITHUB_OUTPUT is available
17- # (Feature detection will be removed in late December 2022)
18- if [ -z ${GITHUB_OUTPUT+x} ]; then
19- echo " ::set-output name=changes_detected::true" ;
20- else
21- echo " changes_detected=true" >> $GITHUB_OUTPUT ;
22- fi
36+ _set_github_output " changes_detected" " true"
2337
2438 _switch_to_branch
2539
@@ -36,36 +50,22 @@ _main() {
3650
3751 _push_to_github
3852 else
39-
40- # Check if $GITHUB_OUTPUT is available
41- # (Feature detection will be removed in late December 2022)
42- if [ -z ${GITHUB_OUTPUT+x} ]; then
43- echo " ::set-output name=changes_detected::false" ;
44- else
45- echo " changes_detected=false" >> $GITHUB_OUTPUT ;
46- fi
53+ _set_github_output " changes_detected" " false"
4754
4855 echo " Working tree clean. Nothing to commit." ;
4956 fi
5057 else
51-
52- # Check if $GITHUB_OUTPUT is available
53- # (Feature detection will be removed in late December 2022)
54- if [ -z ${GITHUB_OUTPUT+x} ]; then
55- echo " ::set-output name=changes_detected::false" ;
56- else
57- echo " changes_detected=false" >> $GITHUB_OUTPUT ;
58- fi
58+ _set_github_output " changes_detected" " false"
5959
6060 echo " Working tree clean. Nothing to commit." ;
6161 fi
6262}
6363
6464_check_if_git_is_available () {
6565 if hash -- " $INPUT_INTERNAL_GIT_BINARY " 2> /dev/null; then
66- echo " :: debug:: git binary found." ;
66+ _log " debug" " git binary found." ;
6767 else
68- echo " :: error :: git-auto-commit could not find git binary. Please make sure git is available."
68+ _log " error" " git-auto-commit could not find git binary. Please make sure git is available."
6969 exit 1;
7070 fi
7171}
@@ -77,7 +77,7 @@ _switch_to_repository() {
7777
7878_git_is_dirty () {
7979 echo " INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS} " ;
80- echo " :: debug:: Apply status options ${INPUT_STATUS_OPTIONS} " ;
80+ _log " debug" " Apply status options ${INPUT_STATUS_OPTIONS} " ;
8181
8282 echo " INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN} " ;
8383 read -r -a INPUT_FILE_PATTERN_EXPANDED <<< " $INPUT_FILE_PATTERN" ;
@@ -91,14 +91,14 @@ _switch_to_branch() {
9191
9292 # Fetch remote to make sure that repo can be switched to the right branch.
9393 if " $INPUT_SKIP_FETCH " ; then
94- echo " :: debug:: git-fetch has not been executed" ;
94+ _log " debug" " git-fetch will not be executed. " ;
9595 else
9696 git fetch --depth=1;
9797 fi
9898
9999 # If `skip_checkout`-input is true, skip the entire checkout step.
100100 if " $INPUT_SKIP_CHECKOUT " ; then
101- echo " :: debug:: git-checkout has not been executed" ;
101+ _log " debug" " git-checkout will not be executed. " ;
102102 else
103103 # Create new local branch if `create_branch`-input is true
104104 if " $INPUT_CREATE_BRANCH " ; then
@@ -114,7 +114,7 @@ _switch_to_branch() {
114114
115115_add_files () {
116116 echo " INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS} " ;
117- echo " :: debug:: Apply add options ${INPUT_ADD_OPTIONS} " ;
117+ _log " debug" " Apply add options ${INPUT_ADD_OPTIONS} " ;
118118
119119 echo " INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN} " ;
120120 read -r -a INPUT_FILE_PATTERN_EXPANDED <<< " $INPUT_FILE_PATTERN" ;
@@ -125,7 +125,7 @@ _add_files() {
125125
126126_local_commit () {
127127 echo " INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS} " ;
128- echo " :: debug:: Apply commit options ${INPUT_COMMIT_OPTIONS} " ;
128+ _log " debug" " Apply commit options ${INPUT_COMMIT_OPTIONS} " ;
129129
130130 # shellcheck disable=SC2206
131131 INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS );
@@ -140,22 +140,15 @@ _local_commit() {
140140 --author=" $INPUT_COMMIT_AUTHOR " \
141141 ${INPUT_COMMIT_OPTIONS: +" ${INPUT_COMMIT_OPTIONS_ARRAY[@]} " } ;
142142
143-
144- # Check if $GITHUB_OUTPUT is available
145- # (Feature detection will be removed in late December 2022)
146- if [ -z ${GITHUB_OUTPUT+x} ]; then
147- echo " ::set-output name=commit_hash::$( git rev-parse HEAD) " ;
148- else
149- echo " commit_hash=$( git rev-parse HEAD) " >> $GITHUB_OUTPUT ;
150- fi
143+ _set_github_output " commit_hash" $( git rev-parse HEAD)
151144}
152145
153146_tag_commit () {
154147 echo " INPUT_TAGGING_MESSAGE: ${INPUT_TAGGING_MESSAGE} "
155148
156149 if [ -n " $INPUT_TAGGING_MESSAGE " ]
157150 then
158- echo " :: debug:: Create tag $INPUT_TAGGING_MESSAGE " ;
151+ _log " debug" " Create tag $INPUT_TAGGING_MESSAGE " ;
159152 git -c user.name=" $INPUT_COMMIT_USER_NAME " -c user.email=" $INPUT_COMMIT_USER_EMAIL " tag -a " $INPUT_TAGGING_MESSAGE " -m " $INPUT_TAGGING_MESSAGE " ;
160153 else
161154 echo " No tagging message supplied. No tag will be added." ;
@@ -165,7 +158,7 @@ _tag_commit() {
165158_push_to_github () {
166159
167160 echo " INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS} " ;
168- echo " :: debug:: Apply push options ${INPUT_PUSH_OPTIONS} " ;
161+ _log " debug" " Apply push options ${INPUT_PUSH_OPTIONS} " ;
169162
170163 # shellcheck disable=SC2206
171164 INPUT_PUSH_OPTIONS_ARRAY=( $INPUT_PUSH_OPTIONS );
@@ -175,15 +168,15 @@ _push_to_github() {
175168 # Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
176169 if [ -n " $INPUT_TAGGING_MESSAGE " ]
177170 then
178- echo " :: debug:: git push origin --tags" ;
171+ _log " debug" " git push origin --tags" ;
179172 git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS: +" ${INPUT_PUSH_OPTIONS_ARRAY[@]} " } ;
180173 else
181- echo " :: debug:: git push origin" ;
174+ _log " debug" " git push origin" ;
182175 git push origin ${INPUT_PUSH_OPTIONS: +" ${INPUT_PUSH_OPTIONS_ARRAY[@]} " } ;
183176 fi
184177
185178 else
186- echo " :: debug:: Push commit to remote branch $INPUT_BRANCH " ;
179+ _log " debug" " Push commit to remote branch $INPUT_BRANCH " ;
187180 git push --set-upstream origin " HEAD:$INPUT_BRANCH " --follow-tags --atomic ${INPUT_PUSH_OPTIONS: +" ${INPUT_PUSH_OPTIONS_ARRAY[@]} " } ;
188181 fi
189182}
0 commit comments