Skip to content

Commit aafbc95

Browse files
Elias BoulhartsElias Boulharts
authored andcommitted
feature: allow using custom tag message
Signed-off-by: Elias Boulharts
1 parent 01d77ca commit aafbc95

4 files changed

Lines changed: 119 additions & 36 deletions

File tree

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ The following is an extended example with all available options.
8585
commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]"
8686
commit_user_email: my-github-actions-bot@example.org # defaults to "41898282+github-actions[bot]@users.noreply.github.com"
8787
commit_author: Author <actions@github.com> # defaults to "username <numeric_id+username@users.noreply.github.com>", where "numeric_id" and "username" belong to the author of the commit that triggered the run
88+
89+
# Optional. Tag name to be created in the local repository and
90+
# pushed to the remote repository on the defined branch.
91+
# If only one of `tag` or `tagging_message` is provided, the value of the provided field will be used for both tag name and message.
92+
tag: 'v1.0.0'
93+
94+
# Optional. Message to annotate the created tag with.
95+
# If only one of `tag` or `tagging_message` is provided, the value of the provided field will be used for both tag name and message.
96+
tagging_message: 'MyProduct v1.0.0'
8897

89-
# Optional. Tag name being created in the local repository and
90-
# pushed to remote repository and defined branch.
91-
tagging_message: 'v1.0.0'
9298

9399
# Optional. Option used by `git-status` to determine if the repository is
94100
# dirty. See https://git-scm.com/docs/git-status#_options

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ inputs:
4444
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
4545
required: false
4646
default: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
47+
tag:
48+
description: New git tag with the commit. Keep this empty, if no tag should be created.
49+
required: false
50+
default: ''
4751
tagging_message:
48-
description: Message used to create a new git tag with the commit. Keep this empty, if no tag should be created.
52+
description: Message used to create a new git tag with the commit.
4953
required: false
5054
default: ''
5155
push_options:

entrypoint.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,17 @@ _local_commit() {
159159
}
160160
161161
_tag_commit() {
162+
echo "INPUT_TAG: ${INPUT_TAG}"
162163
echo "INPUT_TAGGING_MESSAGE: ${INPUT_TAGGING_MESSAGE}"
163164
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";
165+
if [ -n "$INPUT_TAG" ] || [ -n "$INPUT_TAGGING_MESSAGE" ]; then
166+
TAG=${INPUT_TAG:-$INPUT_TAGGING_MESSAGE}
167+
MESSAGE=${INPUT_TAGGING_MESSAGE:-$INPUT_TAG}
168+
169+
_log "debug" "Create tag $TAG: $MESSAGE"
170+
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$TAG" -m "$MESSAGE"
168171
else
169-
echo "No tagging message supplied. No tag will be added.";
172+
echo "Neither INPUT_TAG nor INPUT_TAGGING_MESSAGE is set. No tag will be added."
170173
fi
171174
}
172175
@@ -182,8 +185,8 @@ _push_to_github() {
182185
183186
if [ -z "$INPUT_BRANCH" ]
184187
then
185-
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
186-
if [ -n "$INPUT_TAGGING_MESSAGE" ]
188+
# Only add `--tags` option, if `$INPUT_TAG` or `$INPUT_TAGGING_MESSAGE` is set
189+
if [ -n "$INPUT_TAG" ] || [ -n "$INPUT_TAGGING_MESSAGE" ]; then
187190
then
188191
_log "debug" "git push origin --tags";
189192
git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};

tests/git-auto-commit.bats

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ setup() {
3232
export INPUT_COMMIT_USER_NAME="Test Suite"
3333
export INPUT_COMMIT_USER_EMAIL="test@github.com"
3434
export INPUT_COMMIT_AUTHOR="Test Suite <test@users.noreply.github.com>"
35-
export INPUT_TAGGING_MESSAGE=""
35+
export INPUT_TAG=""
3636
export INPUT_PUSH_OPTIONS=""
3737
export INPUT_SKIP_DIRTY_CHECK=false
3838
export INPUT_DISABLE_GLOBBING=false
@@ -123,7 +123,7 @@ cat_github_output() {
123123
assert_line "INPUT_FILE_PATTERN: ."
124124
assert_line "INPUT_COMMIT_OPTIONS: "
125125
assert_line "::debug::Apply commit options "
126-
assert_line "INPUT_TAGGING_MESSAGE: "
126+
assert_line "INPUT_TAG: "
127127
assert_line "No tagging message supplied. No tag will be added."
128128
assert_line "INPUT_PUSH_OPTIONS: "
129129
assert_line "::debug::Apply push options "
@@ -146,7 +146,7 @@ cat_github_output() {
146146
assert_line "INPUT_FILE_PATTERN: ."
147147
assert_line "INPUT_COMMIT_OPTIONS: "
148148
assert_line "::debug::Apply commit options "
149-
assert_line "INPUT_TAGGING_MESSAGE: "
149+
assert_line "INPUT_TAG: "
150150
assert_line "No tagging message supplied. No tag will be added."
151151
assert_line "INPUT_PUSH_OPTIONS: "
152152
assert_line "::debug::Apply push options "
@@ -293,21 +293,24 @@ cat_github_output() {
293293
}
294294

295295
@test "It creates a tag with the commit" {
296-
INPUT_TAGGING_MESSAGE="v1.0.0"
296+
INPUT_TAG="v1.0.0"
297+
INPUT_TAGGING_MESSAGE="MyProduct v1.0.0"
297298

298299
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
299300

300301
run git_auto_commit
301302

302303
assert_success
303304

304-
assert_line "INPUT_TAGGING_MESSAGE: v1.0.0"
305-
assert_line "::debug::Create tag v1.0.0"
305+
assert_line "INPUT_TAG: v1.0.0"
306+
assert_line "INPUT_TAGGING_MESSAGE: MyProduct v1.0.0"
307+
308+
assert_line "::debug::Create tag v1.0.0: MyProduct v1.0.0"
306309
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
307310

308311
# Assert a tag v1.0.0 has been created
309-
run git tag
310-
assert_output v1.0.0
312+
run git tag -n
313+
assert_output v1.0.0 MyProduct v1.0.0
311314

312315
run git ls-remote --tags --refs
313316
assert_output --partial refs/tags/v1.0.0
@@ -388,18 +391,20 @@ cat_github_output() {
388391
assert_equal $current_sha $remote_sha
389392
}
390393

391-
@test "It uses existing branch when INPUT_BRANCH is empty and INPUT_TAGGING_MESSAGE is set" {
394+
@test "It uses existing branch when INPUT_BRANCH is empty and INPUT_TAG is set" {
392395
INPUT_BRANCH=""
393-
INPUT_TAGGING_MESSAGE="v2.0.0"
396+
INPUT_TAG="v2.0.0"
397+
INPUT_TAGGING_MESSAGE="MyPoduct v2.0.0"
398+
394399

395400
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
396401

397402
run git_auto_commit
398403

399404
assert_success
400405

401-
assert_line "INPUT_TAGGING_MESSAGE: v2.0.0"
402-
assert_line "::debug::Create tag v2.0.0"
406+
assert_line "INPUT_TAG: v2.0.0"
407+
assert_line "::debug::Create tag v2.0.0: MyProduct v2.0.0"
403408
assert_line "::debug::git push origin --tags"
404409

405410
# Assert a tag v2.0.0 has been created
@@ -413,16 +418,18 @@ cat_github_output() {
413418

414419
@test "It pushes generated commit and tag to remote and actually updates the commit shas" {
415420
INPUT_BRANCH=""
416-
INPUT_TAGGING_MESSAGE="v2.0.0"
421+
INPUT_TAG="v2.0.0"
422+
INPUT_TAGGING_MESSAGE="MyPoduct v2.0.0"
423+
417424

418425
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
419426

420427
run git_auto_commit
421428

422429
assert_success
423430

424-
assert_line "INPUT_TAGGING_MESSAGE: v2.0.0"
425-
assert_line "::debug::Create tag v2.0.0"
431+
assert_line "INPUT_TAG: v2.0.0"
432+
assert_line "::debug::Create tag v2.0.0: MyProduct v2.0.0"
426433
assert_line "::debug::git push origin --tags"
427434

428435
# Assert a tag v2.0.0 has been created
@@ -442,16 +449,18 @@ cat_github_output() {
442449

443450
@test "It pushes generated commit and tag to remote branch and updates commit sha" {
444451
INPUT_BRANCH="a-new-branch"
445-
INPUT_TAGGING_MESSAGE="v2.0.0"
452+
INPUT_TAG="v2.0.0"
453+
INPUT_TAGGING_MESSAGE="MyPoduct v2.0.0"
454+
446455

447456
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
448457

449458
run git_auto_commit
450459

451460
assert_success
452461

453-
assert_line "INPUT_TAGGING_MESSAGE: v2.0.0"
454-
assert_line "::debug::Create tag v2.0.0"
462+
assert_line "INPUT_TAG: v2.0.0"
463+
assert_line "::debug::Create tag v2.0.0: MyProduct v2.0.0"
455464
assert_line "::debug::Push commit to remote branch a-new-branch"
456465

457466
# Assert a tag v2.0.0 has been created
@@ -598,7 +607,7 @@ cat_github_output() {
598607
assert_line "INPUT_FILE_PATTERN: ."
599608
assert_line "INPUT_COMMIT_OPTIONS: "
600609
assert_line "::debug::Apply commit options "
601-
assert_line "INPUT_TAGGING_MESSAGE: "
610+
assert_line "INPUT_TAG: "
602611
assert_line "No tagging message supplied. No tag will be added."
603612
assert_line "INPUT_PUSH_OPTIONS: "
604613
assert_line "::debug::Apply push options "
@@ -641,7 +650,7 @@ cat_github_output() {
641650
assert_line "INPUT_FILE_PATTERN: ."
642651
assert_line "INPUT_COMMIT_OPTIONS: "
643652
assert_line "::debug::Apply commit options "
644-
assert_line "INPUT_TAGGING_MESSAGE: "
653+
assert_line "INPUT_TAG: "
645654
assert_line "No tagging message supplied. No tag will be added."
646655
assert_line "INPUT_PUSH_OPTIONS: "
647656
assert_line "::debug::Apply push options "
@@ -700,7 +709,7 @@ cat_github_output() {
700709
assert_line "INPUT_FILE_PATTERN: ."
701710
assert_line "INPUT_COMMIT_OPTIONS: "
702711
assert_line "::debug::Apply commit options "
703-
assert_line "INPUT_TAGGING_MESSAGE: "
712+
assert_line "INPUT_TAG: "
704713
assert_line "No tagging message supplied. No tag will be added."
705714
assert_line "INPUT_PUSH_OPTIONS: "
706715
assert_line "::debug::Apply push options "
@@ -1031,7 +1040,7 @@ cat_github_output() {
10311040
assert_line "INPUT_FILE_PATTERN: ."
10321041
assert_line "INPUT_COMMIT_OPTIONS: "
10331042
assert_line "::debug::Apply commit options "
1034-
assert_line "INPUT_TAGGING_MESSAGE: "
1043+
assert_line "INPUT_TAG: "
10351044
assert_line "No tagging message supplied. No tag will be added."
10361045
assert_line "INPUT_PUSH_OPTIONS: "
10371046
assert_line "::debug::Apply push options "
@@ -1120,14 +1129,15 @@ END
11201129
@test "it creates a tag if create_git_tag_only is set to true and a message has been supplied" {
11211130
INPUT_CREATE_GIT_TAG_ONLY=true
11221131
INPUT_TAGGING_MESSAGE=v1.0.0
1132+
INPUT_TAGGING_MESSAGE="MyPoduct v1.0.0"
11231133

11241134
run git_auto_commit
11251135

11261136
assert_success
11271137

11281138
assert_line "::debug::Create git tag only"
11291139

1130-
assert_line "::debug::Create tag v1.0.0"
1140+
assert_line "::debug::Create tag v1.0.0: MyPoduct v1.0.0"
11311141
refute_line "No tagging message supplied. No tag will be added."
11321142

11331143
assert_line "::debug::Apply push options "
@@ -1148,13 +1158,13 @@ END
11481158

11491159
@test "it output no tagging message supplied if no tagging message is set but create_git_tag_only is set to true" {
11501160
INPUT_CREATE_GIT_TAG_ONLY=true
1151-
INPUT_TAGGING_MESSAGE=""
1161+
INPUT_TAG=""
11521162

11531163
run git_auto_commit
11541164

11551165
assert_success
11561166

1157-
assert_line "INPUT_TAGGING_MESSAGE: "
1167+
assert_line "INPUT_TAG: "
11581168
assert_line "No tagging message supplied. No tag will be added."
11591169
assert_line "::debug::Create git tag only"
11601170

@@ -1181,3 +1191,63 @@ END
11811191
assert_line "::warning::git-auto-commit: skip_checkout has been removed in v6. It does not have any effect anymore."
11821192
assert_line "::warning::git-auto-commit: create_branch has been removed in v6. It does not have any effect anymore."
11831193
}
1194+
1195+
@test "Set a tag message only" {
1196+
INPUT_TAGGING_MESSAGE="v1.0.0"
1197+
1198+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
1199+
1200+
run git_auto_commit
1201+
1202+
assert_success
1203+
1204+
assert_line "INPUT_TAG: "
1205+
assert_line "INPUT_TAGGING_MESSAGE: v1.0.0"
1206+
1207+
assert_line "::debug::Create tag v1.0.0: v1.0.0"
1208+
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
1209+
1210+
# Assert a tag v1.0.0 has been created
1211+
run git tag -n
1212+
assert_output v1.0.0 v1.0.0
1213+
1214+
run git ls-remote --tags --refs
1215+
assert_output --partial refs/tags/v1.0.0
1216+
1217+
# Assert that the commit has been pushed with --force and
1218+
# sha values are equal on local and remote
1219+
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
1220+
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
1221+
1222+
assert_equal $current_sha $remote_sha
1223+
}
1224+
1225+
@test "Set a tag only" {
1226+
INPUT_TAG="v1.0.0"
1227+
1228+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
1229+
1230+
run git_auto_commit
1231+
1232+
assert_success
1233+
1234+
assert_line "INPUT_TAG: v1.0.0"
1235+
assert_line "INPUT_TAGGING_MESSAGE: "
1236+
1237+
assert_line "::debug::Create tag v1.0.0: v1.0.0"
1238+
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
1239+
1240+
# Assert a tag v1.0.0 has been created
1241+
run git tag -n
1242+
assert_output v1.0.0 v1.0.0
1243+
1244+
run git ls-remote --tags --refs
1245+
assert_output --partial refs/tags/v1.0.0
1246+
1247+
# Assert that the commit has been pushed with --force and
1248+
# sha values are equal on local and remote
1249+
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
1250+
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
1251+
1252+
assert_equal $current_sha $remote_sha
1253+
}

0 commit comments

Comments
 (0)