'How do I run a github action only on the head commit of a branch for a pull request?

Is there a way to run a check during a pull request only on the head commit of a feature branch?

For example, if my branch looks like this:

  • TICKET-123: Doing some work
  • fix
  • fix
  • unit test

I want this GitHub action to only run on TICKET-123: Doing some work

Currently, I have

name: 'Pull Request Commit Linter'
on: 
- pull_request

jobs:
  commitlint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - uses: wagoid/commitlint-github-action@v4

I tried playing with fetch-depth, using 1 and 2, but that did not work. Any advice?



Solution 1:[1]

You should remove fetch-depth: 0 definition because I looked up the https://github.com/wagoid/commitlint-github-action repo and I found below sentence:

It's necessary that you specify the fetch-depth argument to actions/checkout@v2 step. By default they fetch only latest commit of the branch, but we need more commits since we validate a range of commit messages.

If you fetch the latest commit only, your problem will be solved.

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 ridvanaltun