Skip to content

Commit

Permalink
CI: Check commit message compliance
Browse files Browse the repository at this point in the history
This commit adds these checks.
- First word is starting from an upper case letter.
- The title is 50 characters at max excluding module prefix.
- Full description lines are 72 columns max.
  • Loading branch information
norihiro committed Sep 6, 2021
1 parent 920a160 commit 000db7e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/commit-msg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Commit Message Check

on: [push, pull_request]

jobs:
ubuntu64:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Fetch OBS Studio master
run: |
git fetch https://github.com/obsproject/obs-studio.git
- name: Check the log messages
run: |
git log --format=full FETCH_HEAD.. | ./CI/check-log-msg.awk
73 changes: 73 additions & 0 deletions CI/check-log-msg.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#! /bin/awk -f

BEGIN {
ret = 0
}

{
if (/^commit /) {
state = 1
commit = $2
is_merge = 0
}
else if (state==1 && /^$/) state = 2
else if (state==2) state = 3
else if (state==3) state = 4
}

state==1 && $1=="Merge:" {
is_merge = 1
}

function check_module_name(mod) {
if (mod ~ /^(win-capture|rtmp-services|obs-ffmpeg|CI|pipewire):$/)
return
if (mod ~ /^(libobs|deps|docs|UI)(|\/[a-z_-]*):$/)
return
if (mod ~ /^(obs-filters|obs-outputs|win-dshow|cmake|obs-browser):$/)
return
if (mod ~ /^(libobs-opengl|linux-capture|image-source|decklink):$/)
return
if (mod ~ /^(obs-transitions|enc-amf|frontend-tools):$/)
return
print "Warning: not frequently appearing module name: "mod
}

state==3 && !is_merge {
title = gensub(/^ */, "", 1, $0)
if (title ~ /^Revert ".*"$/) {
next
}

if (title ~ /^[A-Za-z0-9./-]*(, ?[A-Za-z0-9/-]*)*: /) {
title1 = gensub(/^[^:]*: /, "", 1, title)
mod = $1
check_module_name(mod)
} else {
title1 = title
mod = ""
}

split(title1, title_a, / /)
if (title_a[1] !~ /^([A-Z][a-z]*|Don't)$/) {
print "Error: commit "commit": first word: "title_a[1]
ret = 1
}

if (length(title1) > 50) {
print "Error: commit "commit": too long title: "title
ret = 1
}
}

state==4 {
line = gensub(/^ */, "", 1, $0)
if (length(line) > 72) {
print "Error: commit "commit": too long description in a line: "line
ret = 2
}
}

END {
exit(ret)
}

0 comments on commit 000db7e

Please sign in to comment.