github-actions

How to get the commit message in GitHub Actions


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.


Solution

  • You can get this in the github context for the action, as described here.

    The event key will give you the webhook content, for example as defined in the push event.

    ${{ github.event.head_commit.message }}
    

    Note that different event types have different information available, and their information might be in a different sub-path. For example, in the workflow_run event, the commit message is available at:

    ${{ github.event.workflow_run.head_commit.message }}