'GitHub Action Get Commit Message
So I am building an action that does a build for a project that will go to Netlify. In the action I can pass a deploy message. In that deploy message, I want to pass in the commit message of the commit that triggered the build. I was looking at documentation but could not find if this is possible. Thanks
Solution 1:[1]
You can get this in the github
context for the action, as described here.
The event key will give you the webhook content, as defined here.
So, for your action, you can use something like:
${{ github.event.head_commit.message }}
Solution 2:[2]
You can get the concrete commit message with the following command:
github.event.head_commit.message
Or it is possible to get the commit messages with the git log
command if you use bash:
git log -1 --pretty=format:"%s"
Update: With regard to the documentation, the payload and thus also the call of the commit message has changed. The message can be fetched with the following line in the GitHub action:
github.event.commits[0].message
Solution 3:[3]
There is a small difference between the two:
${{ github.event.commits[0].message }}
When the github push event contains several commits, commit[0]
contains the oldest commit. I have seen this after a merge.
${{ github.event.head_commit.message }}
On the other hand, the head_commit
contains the youngest commit.
Solution 4:[4]
The commit-message
is available on the following keys:
${{ github.event.commits[0].message }}
${{ github.event.head_commit.message }}
There is quite a lot of other information available on events. For ex; the following workflow will give you all that information:
# .github/workflows/logger.yaml
name: Event Loggger
on: push
jobs:
log-github-event-goodies:
name: "LOG Everything on GitHub Event"
runs-on: ubuntu-latest
steps:
- name: Logging
run: |
echo "${{toJSON(github.event)}}"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DᴀʀᴛʜVᴀᴅᴇʀ |
Solution 2 | |
Solution 3 | Alexander R. |
Solution 4 | Dharman |