Skip to content

Commit b863ae1

Browse files
Merge pull request #367 from stefanzweifel/stefanzweifel/git_tag_only_changes
Add Test for create_git_tag_only feature
2 parents 11a6e5f + adb37b5 commit b863ae1

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ The following is an extended example with all available options.
5858
```yaml
5959
- uses: stefanzweifel/git-auto-commit-action@v5
6060
with:
61-
# Perform a clean git tag and push, without commiting anything
62-
# Default to false
63-
git_tag_only: false
64-
6561
# Optional. Commit message for the created commit.
6662
# Defaults to "Apply automatic changes"
6763
commit_message: Automated Change
@@ -122,6 +118,10 @@ The following is an extended example with all available options.
122118

123119
# Optional. Create given branch name in local and remote repository.
124120
create_branch: true
121+
122+
# Optional. Creates a new tag and pushes it to remote without creating a commit.
123+
# Skips dirty check and changed files. Must be used with `tagging_message`.
124+
create_git_tag_only: false
125125
```
126126
127127
Please note that the Action depends on `bash`. If you're using the Action in a job in combination with a custom Docker container, make sure that `bash` is installed.
@@ -173,6 +173,7 @@ You can use these outputs to trigger other Actions in your Workflow run based on
173173

174174
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
175175
- `commit_hash`: Returns the full hash of the commit if one was created.
176+
- `create_git_tag_only`: Returns either "true" or "false" if a tag was created, when `create_git_tag_only` was used.
176177

177178
**⚠️ When using outputs, the step needs to be given an id. See example below.**
178179

action.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ description: 'Automatically commits files which have been changed during the wor
44
author: Stefan Zweifel <stefan@stefanzweifel.dev>
55

66
inputs:
7-
git_tag_only:
8-
description: Perform a clean git tag and push, without commiting anything
9-
required: false
10-
default: false
117
commit_message:
128
description: Commit message
139
required: false
@@ -74,6 +70,10 @@ inputs:
7470
create_branch:
7571
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
7672
default: false
73+
create_git_tag_only:
74+
description: Perform a clean git tag and push, without commiting anything
75+
required: false
76+
default: false
7777
internal_git_binary:
7878
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
7979
default: git
@@ -83,6 +83,8 @@ outputs:
8383
description: Value is "true", if the repository was dirty and file changes have been detected. Value is "false", if no changes have been detected.
8484
commit_hash:
8585
description: Full hash of the created commit. Only present if the "changes_detected" output is "true".
86+
create_git_tag_only:
87+
description: Value is "true", if a git tag was created using the `create_git_tag_only`-input.
8688

8789
runs:
8890
using: 'node20'

entrypoint.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ _main() {
3030
_check_if_git_is_available
3131

3232
_switch_to_repository
33-
if "$INPUT_GIT_TAG_ONLY"; then
34-
_log "debug" "git tag only.";
35-
_set_github_output "git_tag_only" "true"
33+
if "$INPUT_CREATE_GIT_TAG_ONLY"; then
34+
_log "debug" "Create git tag only";
35+
_set_github_output "create_git_tag_only" "true"
3636
_tag_commit
3737
_push_to_github
3838
elif _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then

tests/git-auto-commit.bats

+52-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ setup() {
2121
export FAKE_DEFAULT_BRANCH=$(git config init.defaultBranch)
2222

2323
# Set default INPUT variables used by the GitHub Action
24-
export INPUT_GIT_TAG_ONLY=false
24+
export INPUT_CREATE_GIT_TAG_ONLY=false
2525
export INPUT_REPOSITORY="${FAKE_LOCAL_REPOSITORY}"
2626
export INPUT_COMMIT_MESSAGE="Commit Message"
2727
export INPUT_BRANCH="${FAKE_DEFAULT_BRANCH}"
@@ -1126,3 +1126,54 @@ END
11261126
assert_failure;
11271127
assert_line "::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
11281128
}
1129+
1130+
@test "it creates a tag if create_git_tag_only is set to true and a message has been supplied" {
1131+
INPUT_CREATE_GIT_TAG_ONLY=true
1132+
INPUT_TAGGING_MESSAGE=v1.0.0
1133+
1134+
run git_auto_commit
1135+
1136+
assert_success
1137+
1138+
assert_line "::debug::Create git tag only"
1139+
1140+
assert_line "::debug::Create tag v1.0.0"
1141+
refute_line "No tagging message supplied. No tag will be added."
1142+
1143+
assert_line "::debug::Apply push options "
1144+
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
1145+
1146+
run cat_github_output
1147+
assert_line "create_git_tag_only=true"
1148+
refute_line "changes_detected=false"
1149+
refute_line -e "commit_hash=[0-9a-f]{40}$"
1150+
1151+
# Assert a tag v1.0.0 has been created
1152+
run git tag
1153+
assert_output v1.0.0
1154+
1155+
run git ls-remote --tags --refs
1156+
assert_output --partial refs/tags/v1.0.0
1157+
}
1158+
1159+
@test "it output no tagging message supplied if no tagging message is set but create_git_tag_only is set to true" {
1160+
INPUT_CREATE_GIT_TAG_ONLY=true
1161+
INPUT_TAGGING_MESSAGE=""
1162+
1163+
run git_auto_commit
1164+
1165+
assert_success
1166+
1167+
assert_line "INPUT_TAGGING_MESSAGE: "
1168+
assert_line "No tagging message supplied. No tag will be added."
1169+
assert_line "::debug::Create git tag only"
1170+
1171+
run cat_github_output
1172+
assert_line "create_git_tag_only=true"
1173+
refute_line "changes_detected=false"
1174+
refute_line -e "commit_hash=[0-9a-f]{40}$"
1175+
1176+
# Assert no tag has been created
1177+
run git tag
1178+
assert_output ""
1179+
}

0 commit comments

Comments
 (0)