aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/validate_commit_message.yml
blob: 57124e8b28086b8095ec985d82f61acef5f1e7d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: Validate commit message

on:
  pull_request:
    branches: [ master, google ]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  validate_commit_message:
    runs-on: ubuntu-22.04

    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Validate commit title
        run: |
          # Check that the commit title isn't excessively long.
          commit_title="$(git log -1 --pretty=format:'%s')"
          if [ "${#commit_title}" -gt 120 ]; then
            echo "Error: The title of commit is too long"
            exit 1
          fi

          lowercase_title="$(echo $commit_title | awk '{print tolower($0)}')"
          # Check that the commit title isn't 'internal' (ignore case)
          if [ "$lowercase_title" = "internal" ]; then
            echo "Error: '$commit_title' is not a valid commit title"
            exit 1
          fi

      - name: Validate commit body
        run: |
          # Check that the commit has a body
          commit_body="$(git log -1 --pretty=format:'%b' | grep -v 'PiperOrigin-RevId')"
          if [ -z "$commit_body" ]; then
            echo "Error: The commit message should have a descriptive body"
            exit 1
          fi