Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ runs:
env:
input_message: ${{ inputs.message }}
commit_message: ${{ github.event.head_commit.message }}
status: ${{ inputs.status }}
repository: ${{ inputs.repository }}
event_pusher_name: ${{ github.event.pusher.name }}
event_sender_login: ${{ github.event.sender.login }}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other scribd org repos typically use all caps for env variables, however this repo already uses lowercase so I decided to match what was already here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see an argument for changing it, since I think its a lot easier to parse capitalized variables out of strings eg: message="https://github.com/$repository/commit/$github_sha|$commit_message" vs message="https://github.com/$REPOSITORY/commit/$GITHUB_SHA|$COMMIT_MESSAGE"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to fix that and capitalize the environment variable names to follow the standard naming conventions (https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap08.html).

shell: bash
if: always()
id: fields
run: |
if [ "${{ inputs.status }}" = "success" ]; then
if [ "$status" = "success" ]; then
echo "emoji=large_green_square" >> $GITHUB_OUTPUT
echo "color=good" >> $GITHUB_OUTPUT
elif [ "${{ inputs.status }}" = "failure" ]; then
elif [ "$status" = "failure" ]; then
echo "emoji=large_red_square" >> $GITHUB_OUTPUT
echo "color=danger" >> $GITHUB_OUTPUT
else
Expand All @@ -47,23 +51,23 @@ runs:
fi

if [ ! -z "$input_message" ]; then
message=$input_message
message="$input_message"
elif [ ! -z "$commit_message" ]; then
# get commit message from `push` trigger
commit_message=$(echo "$commit_message" | head -n 1)
message="<https://github.com/${{ inputs.repository }}/commit/${{ github.sha }}|$commit_message>"
elif git rev-parse --is-inside-git-dir > /dev/null 2>&1; then
message="<https://github.com/$repository/commit/$GITHUB_SHA|$commit_message>"
elif git rev-parse --is-inside-git-dir > /dev/null 2>&1; then
# get commit message from the current git directory to support `workflow_dispatch` trigger
commit_message=$(git log --format=%B -n 1 | head -n 1)
message="<https://github.com/${{ inputs.repository }}/commit/${{ github.sha }}|$commit_message>"
message="<https://github.com/$repository/commit/$GITHUB_SHA|$commit_message>"
else
commit_message="Link to the latest commit in the repository"
message="<https://github.com/${{ inputs.repository }}/commit/${{ github.sha }}|$commit_message>"
message="<https://github.com/$repository/commit/$GITHUB_SHA|$commit_message>"
fi
echo "message=$message" >> $GITHUB_OUTPUT

author=${{ github.event.pusher.name }} # context from `push` trigger
author=${author:-${{ github.event.sender.login }}} # context from `workflow_dispatch` trigger
author="$event_pusher_name" # context from `push` trigger
author="${author:-$event_sender_login}" # context from `workflow_dispatch` trigger
echo "author=$author" >> $GITHUB_OUTPUT

- name: Send notification
Expand Down
Loading