57 lines
2.5 KiB
YAML
57 lines
2.5 KiB
YAML
# This action retrieves the latest commit message from a push or pull_request event
|
|
# and makes it available as an output variable named 'msg'.
|
|
name: 'Get commit message'
|
|
outputs:
|
|
msg:
|
|
value: ${{ steps.action_output.outputs.msg }}
|
|
hash:
|
|
value: ${{ steps.action_output.outputs.hash }}
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Find commit message (on push)
|
|
if: github.event_name == 'push'
|
|
shell: bash
|
|
env:
|
|
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
|
run: |
|
|
AUTHOR_NAME="${{ github.event.head_commit.author.name }}"
|
|
AUTHOR_EMAIL="${{ github.event.head_commit.author.email }}"
|
|
TSTAMP="${{ github.event.head_commit.timestamp }}"
|
|
HASH="${{ github.event.head_commit.id }}"
|
|
echo "commit $HASH" >> /tmp/commit_msg.txt
|
|
echo "Author: ${AUTHOR_NAME}<${AUTHOR_EMAIL}>" >> /tmp/commit_msg.txt
|
|
echo "Date: ${TSTAMP}" >> /tmp/commit_msg.txt
|
|
echo "" >> /tmp/commit_msg.txt
|
|
echo "$COMMIT_MESSAGE" >> /tmp/commit_msg.txt
|
|
echo "$HASH" > /tmp/commit_hash.txt
|
|
- name: Find commit message (PR)
|
|
shell: bash
|
|
if: github.event_name == 'pull_request'
|
|
run: |
|
|
PR_NUMBER="${{ github.event.pull_request.number }}"
|
|
# Fetch the head of the PR explicitly to handle forks. Depth 50 ensures we can traverse past recent merge commits.
|
|
git fetch --depth=50 origin "pull/$PR_NUMBER/head:pr-head"
|
|
|
|
COMMIT_HASH=$(git log -1 --no-merges pr-head --format=%H)
|
|
AUTHOR_NAME=$(git log -1 --no-merges pr-head --format=%an)
|
|
AUTHOR_EMAIL=$(git log -1 --no-merges pr-head --format=%ae)
|
|
TSTAMP=$(git log -1 --no-merges pr-head --format=%aI)
|
|
COMMIT_MESSAGE=$(git log -1 --no-merges pr-head --format=%B)
|
|
|
|
echo "commit $COMMIT_HASH" > /tmp/commit_msg.txt
|
|
echo "Author: ${AUTHOR_NAME}<${AUTHOR_EMAIL}>" >> /tmp/commit_msg.txt
|
|
echo "Date: ${TSTAMP}" >> /tmp/commit_msg.txt
|
|
echo "" >> /tmp/commit_msg.txt
|
|
echo "$COMMIT_MESSAGE" >> /tmp/commit_msg.txt
|
|
echo "$COMMIT_HASH" > /tmp/commit_hash.txt
|
|
- shell: bash
|
|
id: action_output
|
|
run: |
|
|
# Get the commit message
|
|
DELIMITER="EOF_FILE_CONTENT_$(date +%s)" # Using timestamp to make it more unique
|
|
echo "msg<<$DELIMITER" >> "$GITHUB_OUTPUT"
|
|
cat /tmp/commit_msg.txt >> "$GITHUB_OUTPUT"
|
|
echo "$DELIMITER" >> "$GITHUB_OUTPUT"
|
|
# Get the commit hash
|
|
echo "hash=$(cat /tmp/commit_hash.txt)" >> "$GITHUB_OUTPUT" |