Skip to content

Commit f526a67

Browse files
fix: apply code build script
1 parent 169184c commit f526a67

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

dist/entrypoint.sh

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,13 @@ _log() {
2727
}
2828

2929
_main() {
30-
if "$INPUT_SKIP_FETCH"; then
31-
_log "warning" "git-auto-commit: skip_fetch has been removed in v6. It does not have any effect anymore.";
32-
fi
33-
34-
if "$INPUT_SKIP_CHECKOUT"; then
35-
_log "warning" "git-auto-commit: skip_checkout has been removed in v6. It does not have any effect anymore.";
36-
fi
37-
38-
if "$INPUT_CREATE_BRANCH"; then
39-
_log "warning" "git-auto-commit: create_branch has been removed in v6. It does not have any effect anymore.";
40-
fi
41-
4230
_check_if_git_is_available
4331

4432
_switch_to_repository
4533

4634
_check_if_is_git_repository
4735

48-
# _check_if_repository_is_in_detached_state
36+
_check_if_repository_is_in_detached_state
4937

5038
if "$INPUT_CREATE_GIT_TAG_ONLY"; then
5139
_log "debug" "Create git tag only";
@@ -56,6 +44,8 @@ _main() {
5644

5745
_set_github_output "changes_detected" "true"
5846

47+
_switch_to_branch
48+
5949
_add_files
6050

6151
# Check dirty state of repo again using git-diff.
@@ -120,13 +110,40 @@ _check_if_is_git_repository() {
120110
_check_if_repository_is_in_detached_state() {
121111
if [ -z "$(git symbolic-ref HEAD)" ]
122112
then
123-
_log "error" "Repository is in detached HEAD state. Please make sure you check out a branch. Adjust the `ref` input accordingly.";
124-
exit 1;
113+
_log "warning" "Repository is in a detached HEAD state. git-auto-commit will likely handle this automatically. To avoid it, check out a branch using the ref option in actions/checkout.";
125114
else
126115
_log "debug" "Repository is on a branch.";
127116
fi
128117
}
129118
119+
_switch_to_branch() {
120+
echo "INPUT_BRANCH value: $INPUT_BRANCH";
121+
122+
# Fetch remote to make sure that repo can be switched to the right branch.
123+
if "$INPUT_SKIP_FETCH"; then
124+
_log "debug" "git-fetch will not be executed.";
125+
else
126+
_log "debug" "git-fetch will be executed.";
127+
git fetch --depth=1;
128+
fi
129+
130+
# If `skip_checkout`-input is true, skip the entire checkout step.
131+
if "$INPUT_SKIP_CHECKOUT"; then
132+
_log "debug" "git-checkout will not be executed.";
133+
else
134+
_log "debug" "git-checkout will be executed.";
135+
# Create new local branch if `create_branch`-input is true
136+
if "$INPUT_CREATE_BRANCH"; then
137+
# shellcheck disable=SC2086
138+
git checkout -B $INPUT_BRANCH --;
139+
else
140+
# Switch to branch from current Workflow run
141+
# shellcheck disable=SC2086
142+
git checkout $INPUT_BRANCH --;
143+
fi
144+
fi
145+
}
146+
130147
_add_files() {
131148
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
132149
_log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";
@@ -159,14 +176,17 @@ _local_commit() {
159176
}
160177
161178
_tag_commit() {
179+
echo "INPUT_TAG_NAME: ${INPUT_TAG_NAME}"
162180
echo "INPUT_TAGGING_MESSAGE: ${INPUT_TAGGING_MESSAGE}"
163181
164-
if [ -n "$INPUT_TAGGING_MESSAGE" ]
165-
then
166-
_log "debug" "Create tag $INPUT_TAGGING_MESSAGE";
167-
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE";
182+
if [ -n "$INPUT_TAG_NAME" ] || [ -n "$INPUT_TAGGING_MESSAGE" ]; then
183+
INTERNAL_TAG=${INPUT_TAG_NAME:-$INPUT_TAGGING_MESSAGE}
184+
INTERNAL_TAGGING_MESSAGE=${INPUT_TAGGING_MESSAGE:-$INPUT_TAG_NAME}
185+
186+
_log "debug" "Create tag $INTERNAL_TAG: $INTERNAL_TAGGING_MESSAGE"
187+
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INTERNAL_TAG" -m "$INTERNAL_TAGGING_MESSAGE"
168188
else
169-
echo "No tagging message supplied. No tag will be added.";
189+
echo "Neither tag nor tag message is set. No tag will be added.";
170190
fi
171191
}
172192
@@ -182,8 +202,8 @@ _push_to_github() {
182202
183203
if [ -z "$INPUT_BRANCH" ]
184204
then
185-
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
186-
if [ -n "$INPUT_TAGGING_MESSAGE" ]
205+
# Only add `--tags` option, if `$INPUT_TAG_NAME` or `$INPUT_TAGGING_MESSAGE` is set
206+
if [ -n "$INPUT_TAG_NAME" ] || [ -n "$INPUT_TAGGING_MESSAGE" ]
187207
then
188208
_log "debug" "git push origin --tags";
189209
git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};

0 commit comments

Comments
 (0)