Skip to content

Check only the most recent commit message #53

Closed

Description

@bbchase

I would like to be able to check for a pattern only in the most-recent commit message. Our use case is checking for the result of a test that I want to make sure has passed before a PR can be merged. e.g., Does the commit message contain "Test Successful"?

Some commits in a PR may not contain a test result or may contain an invalid test result, but I only care that the test was run and succeeds as of the latest commit.

I don't want to put the test result in the PR description because a commit made while the PR is open could cause my test to fail, but the GHA check would still pass because of the old message in the PR description.

Activity

  1. gilbertsoft commented on Feb 24, 2022

    @gilbertsoft
    Member

    In the first place I'd suggest to create a dedicated test action instead. For me it looks you mix up various jobs here which I really would not suggest to do.

    Have a look at my workflows here, there is a clear separation of CI and pull request handling https://github.com/GsTYPO3/core-patches/tree/main/.github/workflows

    PR related action: https://github.com/GsTYPO3/core-patches/actions/runs/1818090001
    CI related action: https://github.com/GsTYPO3/core-patches/actions/runs/1818090153

  2. bbchase commented on Feb 28, 2022

    @bbchase
    Author

    The test I'm referring to is run in local dev environment and devs paste the result into their commit. We want to use this check to make sure that the most-recent commit has passed this test before approving the PR.

  3. gilbertsoft commented on Mar 2, 2022

    @gilbertsoft
    Member

    @bbchase You should try it by set excludeDescription, excludeTitle and checkAllCommitMessages to true. This should work for your case I'd say. Then check the end of the message.

    See also https://github.com/GsActions/commit-message-checker#configuration.

  4. bbchase commented on Mar 2, 2022

    @bbchase
    Author

    I have tried that. In that case, all commits associated with a PR are checked and if any commit does not contain the test message for whatever reason, the check will fail. I really only care that the latest commit contains this message.

    Here's the contents of the yml file if it helps:

    name: 'Commit Message Check'
    on:
      pull_request:
        types:
          - opened
          - edited
          - reopened
          - synchronize
      pull_request_target:
        types:
          - opened
          - edited
          - reopened
          - synchronize
      push:
        branches:
          - main
    
    jobs:
      check-commit-message:
        name: Look for Test Suite message
        runs-on: ubuntu-latest
        steps:
          - name: Check Commit Type
            uses: gsactions/commit-message-checker@v1
            with:
              pattern: '^Successful Full Test Suite Run at \d\d\d\d+-\d\d-\d\d \d\d:\d\d:\d\d UTC$'
              error: 'The commit message must include a successful full test suite run.'
              excludeTitle: true
              excludeDescription: true
              checkAllCommitMessages: true
              accessToken: ${{ secrets.GITHUB_TOKEN }}
  5. gilbertsoft commented on Mar 6, 2022

    @gilbertsoft
    Member

    The problem here is your pattern, which tests for the start. Try this one Successful Full Test Suite Run at \d\d\d\d+-\d\d-\d\d \d\d:\d\d:\d\d UTC$ which will only take care about the end.

    If this does still not work, enable debugging see https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging. Then you will see the message which is built and you can use tools like https://regexr.com/ afterwards to find a working pattern.

    And if you enforce pull request, it does not make much sense to run the action for the main branch btw.

  6. changed the title [-][Feature Request] Option to check only the most recent commit message[/-] [+]Check only the most recent commit message[/+] on Mar 6, 2022
  7. locked and limited conversation to collaborators on Mar 6, 2022
  8. converted this issue into a discussion #61 on Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions