2

I've set up a GitHub Actions workflow that uses commitlint to lint messages for all commits of a pull request, but the problem is that the merge commit is not considered. This action is, in short, as simple as the following:

on: [pull_request]

jobs:
  lint-commit-messages:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v3
        with:
          node-version: 16

      - run: npm install -g @commitlint/{cli,config-conventional}

      - run: commitlint --from ${{ github.event.pull_request.base.sha }}
                        --to ${{ github.event.pull_request.head.sha }}
                        --verbose

What I need is to stop the pull request merge process when commitlint doesn't accept the merge commit message — the one that is usually written through the browser.

The GitHub Actions docs says something about the GITHUB_SHA environment variable, which is a reference to the pull request's "future" merge commit, but I didn't find a way to use it.

Do you know how I can proceed? What I need is possible? Other ideas or approaches are welcome.

2
  • 2
    I don't think you can stop the merge before the merge commit is done. Github actions run over some commit, when you type the merge commit msg there's no commit for a action to run. What you could do is make an action that runs on merge, linting the last commit, if it fails revert/drop the commit from main and reopens the pull request Commented Nov 7, 2022 at 20:54
  • Oh, of course. You're right, @CaioSalgado. Your idea is a good solution, and I will consider it in my project. Thank you very much!
    – Marlon
    Commented Nov 16, 2022 at 12:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.