Skip to content

Commit

Permalink
Merge pull request stefanzweifel#172 from webignition/issue-171
Browse files Browse the repository at this point in the history
Output hash of created commit
  • Loading branch information
stefanzweifel authored Sep 10, 2021
2 parents 0426839 + 05aea7e commit 216b25a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/
You can use these outputs to trigger other Actions in your Workflow run based on the result of `git-auto-commit-action`.

- `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.

### Example

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ inputs:
outputs:
changes_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:
description: Full hash of the created commit. Only present if the "changes_detected" output is "true".

runs:
using: 'node12'
Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ _local_commit() {
commit -m "$INPUT_COMMIT_MESSAGE" \
--author="$INPUT_COMMIT_AUTHOR" \
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};

echo "::set-output name=commit_hash::$(git rev-parse HEAD)";
}

_tag_commit() {
Expand Down
7 changes: 5 additions & 2 deletions tests/git-auto-commit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ git_auto_commit() {

assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
Expand All @@ -106,6 +107,7 @@ git_auto_commit() {

assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
Expand All @@ -128,6 +130,7 @@ git_auto_commit() {

assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "Working tree clean. Nothing to commit."
}

Expand All @@ -138,6 +141,7 @@ git_auto_commit() {

assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "Working tree clean. Nothing to commit."
}

Expand All @@ -150,8 +154,7 @@ git_auto_commit() {

assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"

assert_line "::set-output name=changes_detected::true"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
Expand Down

0 comments on commit 216b25a

Please sign in to comment.