Accessing commit message in pull_request event


Feaure request: Make head_commit available with pull_request’s synchronize action.

I’ve a workflow which triggers on pull_request’s default types/actions. I want to run a job when there are new commits pushed to a PR, but I wanted to run the job only if commit message included specific keywords. So, I tried to access <font face="courier new,courier">github.event.head_commit.message</font>, as suggested on various forums.

But unfortunately, head_commit is not available during pull_request’s synchronize action. Following is a relevant bit from github context dump:

  "event_name": "pull_request",
  "event": {
     "action": "synchronize",

Yes, currently you can’t see commit message in pull_request‘s synchronize event. But you can get the commit id in github.event.after.

after commit.png

Then you can run a git command to get the commit message : git log --format=%B -n 1 <commit>

Please set this commit message as the value of an environment variable using set-env command.

Then you can add if condition in all your next steps, to judge if commit message included specific keywords

Please see my example:

name: filter commit nessage
on: pull_request

    runs-on: ubuntu-latest
      - uses: actions/checkout@v1

      - name : GITHUB CONTEXT
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"

      - name: get commit message
        run: |
           echo ::set-env name=commitmsg::$(git log --format=%B -n 1 ${{ github.event.after }})
      - name: show commit message
        run : echo $commitmsg

      - name: step1
        if: contains( env.commitmsg , 'try' )
        run: echo hello

filter commit message.png


This workaround is available only under “steps”. Would be great if it was available in github context and we could skip a “job”.

I did a similar workaround, which is pretty repetitive:

      - uses: actions/checkout@v1
      - id: log
        run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)"
      - if: "!contains(steps.log.outputs.message, 'ci skip')"
        uses: actions/setup-node@v1
          node-version: 10
      - if: "!contains(steps.log.outputs.message, 'ci skip')"
        run: npm install

This just bit me and I was about to post about it.

In my opinion, something like this should work for any commit-driven trigger, whether via pull_request or push:

    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"

Did GitHub remove


I don’t see it anywhere in my context dump.

1 Like

Any new on that feature ? Would be really helpfull

The workaround to avoid duplicate in every steps is:

  • create preBuild job with isCI step (to check message)
  • map output of isCI to preBuild
  • Use needs.preBuild.outputs.isCI in if condition of build job

Check docs here