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.
- Title consists of module name(s) and subject or just subject.
- If there are two or more module names, the module names has to be
  separated by a comma followed by an optional space.
- First word of the subject is starting from an upper case letter and
  remaining characters in the first word are lower case letters.
  "Don't" and a word with hyphen at the middle are also acceptable.
- The title is 72 characters at max including module prefix.
- If the subject exceed 50 characters excluding the module prefix,
  display a warning message.
- Titles for commits of revert and merge are ignored.
- Full description lines are 72 columns max.
  • Loading branch information
norihiro committed Sep 10, 2021
1 parent dda48c9 commit 88ec435
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/commit-msg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Commit Message Check

on: [pull_request]

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

- name: Fetch OBS Studio master
run: |
git fetch https://github.com/obsproject/obs-studio.git
- name: Check the log messages
run: |
git log FETCH_HEAD.. | ./CI/check-log-msg.awk -v GITHUB_EVENT_NAME=${{env.GITHUB_EVENT_NAME}}
79 changes: 79 additions & 0 deletions CI/check-log-msg.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#! /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 "Info: not frequently appearing module name: "mod
}

state==3 && !is_merge {
title = gensub(/^ */, "", 1, $0)
if (title ~ /^Revert ".*"$/) {
next
}
if (title ~ /^Merge [0-9a-f]{40} into [0-9a-f]{40}$/) {
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]*(-[a-z]+)*|Don't)$/) {
print "Error: commit "commit": first word: "title_a[1]
ret = 1
}

if (length(title) > 72) {
print "Error: commit "commit": too long title: "title
ret = 1
}
else if (length(title1) > 50) {
print "Warning: commit "commit": long title excluding module name: "title1
}
}

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 88ec435

Please sign in to comment.