Skip to content

Commit

Permalink
feat: expose sha and short sha data
Browse files Browse the repository at this point in the history
  • Loading branch information
rlespinasse committed Jan 1, 2022
1 parent e4973be commit 55e2409
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/git-commit-data-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- uses: ./
- name: Output
run: |
echo "Get commit info"
echo " - ${{ env.GIT_COMMIT_SHA }}"
echo " - ${{ env.GIT_COMMIT_SHORT_SHA }}"
echo "Get author info"
echo " - ${{ env.GIT_COMMIT_AUTHOR }}"
echo " - ${{ env.GIT_COMMIT_AUTHOR_NAME }}"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This action exposes git commit data.

- **GIT_COMMIT_SHA** expose `commit hash`
- **GIT_COMMIT_SHORT_SHA** expose `abbreviated commit hash`
- **GIT_COMMIT_AUTHOR** expose `Author name <[email protected]>`
- **GIT_COMMIT_AUTHOR_NAME** expose `Author name`
- **GIT_COMMIT_AUTHOR_EMAIL** expose `[email protected]`
Expand All @@ -20,6 +22,9 @@ This action exposes git commit data.

- name: Print git commit data
run: |
echo "Get commit info"
echo " - ${{ env.GIT_COMMIT_SHA }}"
echo " - ${{ env.GIT_COMMIT_SHORT_SHA }}"
echo "Get author info"
echo " - ${{ env.GIT_COMMIT_AUTHOR }}"
echo " - ${{ env.GIT_COMMIT_AUTHOR_NAME }}"
Expand Down
6 changes: 6 additions & 0 deletions git-commit-data.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

TEMPLATE_SHA_FORMAT="%H"
TEMPLATE_SHORT_SHA_FORMAT="%h"

TEMPLATE_AUTHOR_FORMAT="%an <%ae>"
TEMPLATE_AUTHOR_NAME_FORMAT="%an"
TEMPLATE_AUTHOR_EMAIL_FORMAT="%ae"
Expand All @@ -20,6 +23,9 @@ git_log_format() {

echo "+ GIT_COMMIT_* environment variables"
{
echo "GIT_COMMIT_SHA=$(git_log_format "${TEMPLATE_SHA_FORMAT}" "HEAD")"
echo "GIT_COMMIT_SHORT_SHA=$(git_log_format "${TEMPLATE_SHORT_SHA_FORMAT}" "HEAD")"

echo "GIT_COMMIT_AUTHOR=$(git_log_format "${TEMPLATE_AUTHOR_FORMAT}" "HEAD")"
echo "GIT_COMMIT_AUTHOR_NAME=$(git_log_format "${TEMPLATE_AUTHOR_NAME_FORMAT}" "HEAD")"
echo "GIT_COMMIT_AUTHOR_EMAIL=$(git_log_format "${TEMPLATE_AUTHOR_EMAIL_FORMAT}" "HEAD")"
Expand Down
10 changes: 9 additions & 1 deletion tests/git_log_format.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

apk add --no-cache git > /dev/null

TEST_COMMIT_SHA=f554bec
TEST_COMMIT_SHA=f554bec660038601b8882c1e0cc5d0d8fcebf221

# Load git_log_format function
source git-commit-data.sh > /dev/null 2>&1

@test "git_log_format: sha" {
test_git_log_format "$TEMPLATE_SHA_FORMAT" "f554bec660038601b8882c1e0cc5d0d8fcebf221"
}

@test "git_log_format: short sha" {
test_git_log_format "$TEMPLATE_SHORT_SHA_FORMAT" "f554bec"
}

@test "git_log_format: author" {
test_git_log_format "$TEMPLATE_AUTHOR_FORMAT" "rlespinasse <[email protected]>"
}
Expand Down

0 comments on commit 55e2409

Please sign in to comment.