Skip to content

Commit

Permalink
feat: expose data as output
Browse files Browse the repository at this point in the history
  • Loading branch information
rlespinasse authored Jun 9, 2023
1 parent bb64c16 commit 2b76766
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 17 deletions.
44 changes: 43 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,50 @@ author: "Romain Lespinasse"
branding:
icon: "settings"
color: "gray-dark"
inputs:
publish-env:
description: "Publish slugs as environment variables"
default: "true"
required: true
outputs:
sha:
description: "commit hash"
value: ${{ steps.commit-data.outputs.sha }}
short-sha:
description: "abbreviated commit hash"
value: ${{ steps.commit-data.outputs.short-sha }}
author:
description: "Author name <[email protected]>"
value: ${{ steps.commit-data.outputs.author }}
author-name:
description: "Author name"
value: ${{ steps.commit-data.outputs.author-name }}
author-email:
description: "[email protected]"
value: ${{ steps.commit-data.outputs.author-email }}
committer:
description: "Committer name <[email protected]>"
value: ${{ steps.commit-data.outputs.committer }}
committer-name:
description: "Committer name"
value: ${{ steps.commit-data.outputs.committer-name }}
committer-email:
description: "[email protected]"
value: ${{ steps.commit-data.outputs.committer-email }}
message-subject:
description: "The first line of the commit message"
value: ${{ steps.commit-data.outputs.message-subject }}
message-subject-sanitized:
description: "the-first-line-of-the-commit-message-in-sanitized-way"
value: ${{ steps.commit-data.outputs.message-subject-sanitized }}
message-body:
description: "The body of the commit message"
value: ${{ steps.commit-data.outputs.message-body }}
runs:
using: "composite"
steps:
- run: $GITHUB_ACTION_PATH/git-commit-data.sh
- id: commit-data
run: $GITHUB_ACTION_PATH/git-commit-data.sh
shell: bash
env:
INPUT_PUBLISH_ENV: ${{ inputs.publish-env }}
86 changes: 70 additions & 16 deletions git-commit-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,76 @@ git_log_format() {
git log -1 --pretty=format:"$pattern" "$reference"
}

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")"
COMMIT_SHA=$(git_log_format "${TEMPLATE_SHA_FORMAT}" "HEAD")
COMMIT_SHORT_SHA=$(git_log_format "${TEMPLATE_SHORT_SHA_FORMAT}" "HEAD")
COMMIT_AUTHOR=$(git_log_format "${TEMPLATE_AUTHOR_FORMAT}" "HEAD")
COMMIT_AUTHOR_NAME=$(git_log_format "${TEMPLATE_AUTHOR_NAME_FORMAT}" "HEAD")
COMMIT_AUTHOR_EMAIL=$(git_log_format "${TEMPLATE_AUTHOR_EMAIL_FORMAT}" "HEAD")
COMMIT_COMMITTER=$(git_log_format "${TEMPLATE_COMMITTER_FORMAT}" "HEAD")
COMMIT_COMMITTER_NAME=$(git_log_format "${TEMPLATE_COMMITTER_NAME_FORMAT}" "HEAD")
COMMIT_COMMITTER_EMAIL=$(git_log_format "${TEMPLATE_COMMITTER_EMAIL_FORMAT}" "HEAD")
COMMIT_MESSAGE_SUBJECT=$(git_log_format "${TEMPLATE_COMMIT_MESSAGE_SUBJECT_FORMAT}" "HEAD")
COMMIT_MESSAGE_SUBJECT_SANITIZED=$(git_log_format "${TEMPLATE_COMMIT_MESSAGE_SUBJECT_SANITIZED_FORMAT}" "HEAD")
COMMIT_MESSAGE_BODY=$(git_log_format "${TEMPLATE_COMMIT_MESSAGE_BODY_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")"

echo "GIT_COMMIT_COMMITTER=$(git_log_format "${TEMPLATE_COMMITTER_FORMAT}" "HEAD")"
echo "GIT_COMMIT_COMMITTER_NAME=$(git_log_format "${TEMPLATE_COMMITTER_NAME_FORMAT}" "HEAD")"
echo "GIT_COMMIT_COMMITTER_EMAIL=$(git_log_format "${TEMPLATE_COMMITTER_EMAIL_FORMAT}" "HEAD")"

echo "GIT_COMMIT_MESSAGE_SUBJECT=$(git_log_format "${TEMPLATE_COMMIT_MESSAGE_SUBJECT_FORMAT}" "HEAD")"
echo "GIT_COMMIT_MESSAGE_SUBJECT_SANITIZED=$(git_log_format "${TEMPLATE_COMMIT_MESSAGE_SUBJECT_SANITIZED_FORMAT}" "HEAD")"
echo "GIT_COMMIT_SHA=${COMMIT_SHA}"
echo "GIT_COMMIT_SHORT_SHA=${COMMIT_SHORT_SHA}"
echo "GIT_COMMIT_AUTHOR=${COMMIT_AUTHOR}"
echo "GIT_COMMIT_AUTHOR_NAME=${COMMIT_AUTHOR_NAME}"
echo "GIT_COMMIT_AUTHOR_EMAIL=${COMMIT_AUTHOR_EMAIL}"
echo "GIT_COMMIT_COMMITTER=${COMMIT_COMMITTER}"
echo "GIT_COMMIT_COMMITTER_NAME=${COMMIT_COMMITTER_NAME}"
echo "GIT_COMMIT_COMMITTER_EMAIL=${COMMIT_COMMITTER_EMAIL}"
echo "GIT_COMMIT_MESSAGE_SUBJECT=${COMMIT_MESSAGE_SUBJECT}"
echo "GIT_COMMIT_MESSAGE_SUBJECT_SANITIZED=${COMMIT_MESSAGE_SUBJECT_SANITIZED}"
echo 'GIT_COMMIT_MESSAGE_BODY<<GIT_COMMIT_MESSAGE_BODY_EOF'
echo "$(git_log_format "${TEMPLATE_COMMIT_MESSAGE_BODY_FORMAT}" "HEAD")"
echo "${COMMIT_MESSAGE_BODY}"
echo 'GIT_COMMIT_MESSAGE_BODY_EOF'
} | tee "$GITHUB_ENV"


if [ -f "$GITHUB_OUTPUT" ]; then
{
echo "sha=${COMMIT_SHA}"
echo "short-sha=${COMMIT_SHORT_SHA}"
echo "author=${COMMIT_AUTHOR}"
echo "author-name=${COMMIT_AUTHOR_NAME}"
echo "author-email=${COMMIT_AUTHOR_EMAIL}"
echo "committer=${COMMIT_COMMITTER}"
echo "committer_NAME=${COMMIT_COMMITTER_NAME}"
echo "committer_EMAIL=${COMMIT_COMMITTER_EMAIL}"
echo "message-subject=${COMMIT_MESSAGE_SUBJECT}"
echo "message-subject-sanitized=${COMMIT_MESSAGE_SUBJECT_SANITIZED}"
echo 'message-body<<GIT_COMMIT_MESSAGE_BODY_EOF'
echo "${COMMIT_MESSAGE_BODY}"
echo 'GIT_COMMIT_MESSAGE_BODY_EOF'
} >> "$GITHUB_OUTPUT"
else
echo "::set-output name=sha::${COMMIT_SHA}"
echo "::set-output name=short-sha::${COMMIT_SHORT_SHA}"
echo "::set-output name=author::${COMMIT_AUTHOR}"
echo "::set-output name=author-name::${COMMIT_AUTHOR_NAME}"
echo "::set-output name=author-email::${COMMIT_AUTHOR_EMAIL}"
echo "::set-output name=committer::${COMMIT_COMMITTER}"
echo "::set-output name=committer_NAME::${COMMIT_COMMITTER_NAME}"
echo "::set-output name=committer_EMAIL::${COMMIT_COMMITTER_EMAIL}"
echo "::set-output name=message-subject::${COMMIT_MESSAGE_SUBJECT}"
echo "::set-output name=message-subject-sanitized::${COMMIT_MESSAGE_SUBJECT_SANITIZED}"
fi

if [ "${INPUT_PUBLISH_ENV}" == "true" ]; then
{
echo "GIT_COMMIT_SHA=${COMMIT_SHA}"
echo "GIT_COMMIT_SHORT_SHA=${COMMIT_SHORT_SHA}"
echo "GIT_COMMIT_AUTHOR=${COMMIT_AUTHOR}"
echo "GIT_COMMIT_AUTHOR_NAME=${COMMIT_AUTHOR_NAME}"
echo "GIT_COMMIT_AUTHOR_EMAIL=${COMMIT_AUTHOR_EMAIL}"
echo "GIT_COMMIT_COMMITTER=${COMMIT_COMMITTER}"
echo "GIT_COMMIT_COMMITTER_NAME=${COMMIT_COMMITTER_NAME}"
echo "GIT_COMMIT_COMMITTER_EMAIL=${COMMIT_COMMITTER_EMAIL}"
echo "GIT_COMMIT_MESSAGE_SUBJECT=${COMMIT_MESSAGE_SUBJECT}"
echo "GIT_COMMIT_MESSAGE_SUBJECT_SANITIZED=${COMMIT_MESSAGE_SUBJECT_SANITIZED}"
echo 'GIT_COMMIT_MESSAGE_BODY<<GIT_COMMIT_MESSAGE_BODY_EOF'
echo "${COMMIT_MESSAGE_BODY}"
echo 'GIT_COMMIT_MESSAGE_BODY_EOF'
} >>"$GITHUB_ENV"
fi

0 comments on commit 2b76766

Please sign in to comment.