mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-04-20 08:49:42 +08:00
Merge pull request #367 from stefanzweifel/stefanzweifel/git_tag_only_changes
Add Test for create_git_tag_only feature
This commit is contained in:
commit
b863ae1933
@ -58,10 +58,6 @@ The following is an extended example with all available options.
|
|||||||
```yaml
|
```yaml
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v5
|
- uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
# Perform a clean git tag and push, without commiting anything
|
|
||||||
# Default to false
|
|
||||||
git_tag_only: false
|
|
||||||
|
|
||||||
# Optional. Commit message for the created commit.
|
# Optional. Commit message for the created commit.
|
||||||
# Defaults to "Apply automatic changes"
|
# Defaults to "Apply automatic changes"
|
||||||
commit_message: Automated Change
|
commit_message: Automated Change
|
||||||
@ -122,6 +118,10 @@ The following is an extended example with all available options.
|
|||||||
|
|
||||||
# Optional. Create given branch name in local and remote repository.
|
# Optional. Create given branch name in local and remote repository.
|
||||||
create_branch: true
|
create_branch: true
|
||||||
|
|
||||||
|
# Optional. Creates a new tag and pushes it to remote without creating a commit.
|
||||||
|
# Skips dirty check and changed files. Must be used with `tagging_message`.
|
||||||
|
create_git_tag_only: false
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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
|
|||||||
|
|
||||||
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
|
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
|
||||||
- `commit_hash`: Returns the full hash of the commit if one was created.
|
- `commit_hash`: Returns the full hash of the commit if one was created.
|
||||||
|
- `create_git_tag_only`: Returns either "true" or "false" if a tag was created, when `create_git_tag_only` was used.
|
||||||
|
|
||||||
**⚠️ When using outputs, the step needs to be given an id. See example below.**
|
**⚠️ When using outputs, the step needs to be given an id. See example below.**
|
||||||
|
|
||||||
|
10
action.yml
10
action.yml
@ -4,10 +4,6 @@ description: 'Automatically commits files which have been changed during the wor
|
|||||||
author: Stefan Zweifel <stefan@stefanzweifel.dev>
|
author: Stefan Zweifel <stefan@stefanzweifel.dev>
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
git_tag_only:
|
|
||||||
description: Perform a clean git tag and push, without commiting anything
|
|
||||||
required: false
|
|
||||||
default: false
|
|
||||||
commit_message:
|
commit_message:
|
||||||
description: Commit message
|
description: Commit message
|
||||||
required: false
|
required: false
|
||||||
@ -74,6 +70,10 @@ inputs:
|
|||||||
create_branch:
|
create_branch:
|
||||||
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
|
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
|
||||||
default: false
|
default: false
|
||||||
|
create_git_tag_only:
|
||||||
|
description: Perform a clean git tag and push, without commiting anything
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
internal_git_binary:
|
internal_git_binary:
|
||||||
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
|
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
|
||||||
default: git
|
default: git
|
||||||
@ -83,6 +83,8 @@ outputs:
|
|||||||
description: Value is "true", if the repository was dirty and file changes have been detected. Value is "false", if no changes have been detected.
|
description: Value is "true", if the repository was dirty and file changes have been detected. Value is "false", if no changes have been detected.
|
||||||
commit_hash:
|
commit_hash:
|
||||||
description: Full hash of the created commit. Only present if the "changes_detected" output is "true".
|
description: Full hash of the created commit. Only present if the "changes_detected" output is "true".
|
||||||
|
create_git_tag_only:
|
||||||
|
description: Value is "true", if a git tag was created using the `create_git_tag_only`-input.
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node20'
|
||||||
|
@ -30,9 +30,9 @@ _main() {
|
|||||||
_check_if_git_is_available
|
_check_if_git_is_available
|
||||||
|
|
||||||
_switch_to_repository
|
_switch_to_repository
|
||||||
if "$INPUT_GIT_TAG_ONLY"; then
|
if "$INPUT_CREATE_GIT_TAG_ONLY"; then
|
||||||
_log "debug" "git tag only.";
|
_log "debug" "Create git tag only";
|
||||||
_set_github_output "git_tag_only" "true"
|
_set_github_output "create_git_tag_only" "true"
|
||||||
_tag_commit
|
_tag_commit
|
||||||
_push_to_github
|
_push_to_github
|
||||||
elif _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
|
elif _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
|
||||||
|
@ -21,7 +21,7 @@ setup() {
|
|||||||
export FAKE_DEFAULT_BRANCH=$(git config init.defaultBranch)
|
export FAKE_DEFAULT_BRANCH=$(git config init.defaultBranch)
|
||||||
|
|
||||||
# Set default INPUT variables used by the GitHub Action
|
# Set default INPUT variables used by the GitHub Action
|
||||||
export INPUT_GIT_TAG_ONLY=false
|
export INPUT_CREATE_GIT_TAG_ONLY=false
|
||||||
export INPUT_REPOSITORY="${FAKE_LOCAL_REPOSITORY}"
|
export INPUT_REPOSITORY="${FAKE_LOCAL_REPOSITORY}"
|
||||||
export INPUT_COMMIT_MESSAGE="Commit Message"
|
export INPUT_COMMIT_MESSAGE="Commit Message"
|
||||||
export INPUT_BRANCH="${FAKE_DEFAULT_BRANCH}"
|
export INPUT_BRANCH="${FAKE_DEFAULT_BRANCH}"
|
||||||
@ -1126,3 +1126,54 @@ END
|
|||||||
assert_failure;
|
assert_failure;
|
||||||
assert_line "::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
|
assert_line "::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "it creates a tag if create_git_tag_only is set to true and a message has been supplied" {
|
||||||
|
INPUT_CREATE_GIT_TAG_ONLY=true
|
||||||
|
INPUT_TAGGING_MESSAGE=v1.0.0
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "::debug::Create git tag only"
|
||||||
|
|
||||||
|
assert_line "::debug::Create tag v1.0.0"
|
||||||
|
refute_line "No tagging message supplied. No tag will be added."
|
||||||
|
|
||||||
|
assert_line "::debug::Apply push options "
|
||||||
|
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
|
||||||
|
|
||||||
|
run cat_github_output
|
||||||
|
assert_line "create_git_tag_only=true"
|
||||||
|
refute_line "changes_detected=false"
|
||||||
|
refute_line -e "commit_hash=[0-9a-f]{40}$"
|
||||||
|
|
||||||
|
# Assert a tag v1.0.0 has been created
|
||||||
|
run git tag
|
||||||
|
assert_output v1.0.0
|
||||||
|
|
||||||
|
run git ls-remote --tags --refs
|
||||||
|
assert_output --partial refs/tags/v1.0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "it output no tagging message supplied if no tagging message is set but create_git_tag_only is set to true" {
|
||||||
|
INPUT_CREATE_GIT_TAG_ONLY=true
|
||||||
|
INPUT_TAGGING_MESSAGE=""
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_TAGGING_MESSAGE: "
|
||||||
|
assert_line "No tagging message supplied. No tag will be added."
|
||||||
|
assert_line "::debug::Create git tag only"
|
||||||
|
|
||||||
|
run cat_github_output
|
||||||
|
assert_line "create_git_tag_only=true"
|
||||||
|
refute_line "changes_detected=false"
|
||||||
|
refute_line -e "commit_hash=[0-9a-f]{40}$"
|
||||||
|
|
||||||
|
# Assert no tag has been created
|
||||||
|
run git tag
|
||||||
|
assert_output ""
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user