1name: Validate commit message 2 3on: 4 pull_request: 5 branches: [ master, google ] 6 7permissions: 8 contents: read 9 10jobs: 11 validate_commit_message: 12 runs-on: ubuntu-22.04 13 14 steps: 15 - uses: actions/checkout@v3 16 with: 17 ref: ${{ github.event.pull_request.head.sha }} 18 19 - name: Validate commit title 20 run: | 21 # Check that the commit title isn't excessively long. 22 commit_title="$(git log -1 --pretty=format:'%s')" 23 if [ "${#commit_title}" -gt 120 ]; then 24 echo "Error: The title of commit is too long" 25 exit 1 26 fi 27 28 lowercase_title="$(echo $commit_title | awk '{print tolower($0)}')" 29 # Check that the commit title isn't 'internal' (ignore case) 30 if [ "$lowercase_title" = "internal" ]; then 31 echo "Error: '$commit_title' is not a valid commit title" 32 exit 1 33 fi 34 35 - name: Validate commit body 36 run: | 37 # Check that the commit has a body 38 commit_body="$(git log -1 --pretty=format:'%b' | grep -v 'PiperOrigin-RevId')" 39 if [ -z "$commit_body" ]; then 40 echo "Error: The commit message should have a descriptive body" 41 exit 1 42 fi 43