diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7f7ecbaf836..422fc7927af 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -45,5 +45,9 @@ jobs: cd nuttx commits="${{ github.event.pull_request.base.sha }}..HEAD" git log --oneline $commits - echo "../nuttx/tools/checkpatch.sh -c -u -m -g $commits" - ../nuttx/tools/checkpatch.sh -c -u -m -g $commits + breaking_opts="" + if echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -e 'any(.[].name; test("breaking change"; "i"))' >/dev/null 2>&1; then + breaking_opts="-b" + fi + echo "../nuttx/tools/checkpatch.sh -c -u -m -g $breaking_opts $commits" + ../nuttx/tools/checkpatch.sh -c -u -m -g $breaking_opts $commits diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index bec4bae7605..f2865aaa0e5 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -60,6 +60,7 @@ usage() { echo "-m Check commit message (coupled with -g)" echo "-b Enforce breaking change format when checking commit message (requires -m -g; use when PR has breaking change label)" echo "-g " + echo " Use --stdin as the only argument with -m -g to read commit message from stdin (message-only check, no patch/diff)." echo "-f " echo "-x format supported files (only .py, requires: pip install black)" echo "- read standard input mainly used by git pre-commit hook as below:" @@ -286,6 +287,7 @@ check_patch() { check_msg() { signedoffby_found=0 num_lines=0 + # Commit subject line length limit (50/72 are common; NuttX uses 80) max_line_len=80 min_num_lines=5 breaking_change_found=0 @@ -420,6 +422,9 @@ while [ ! -z "$1" ]; do -h ) usage 0 ;; + --stdin ) + break + ;; -p ) check=check_patch ;; @@ -437,7 +442,12 @@ while [ ! -z "$1" ]; do done for arg in $@; do - $check $arg + if [ "$arg" = "--stdin" ] && [ "$check" = "check_commit" ]; then + msg=$(cat) + check_msg <<< "$msg" + else + $check $arg + fi done if [ $fail == 1 ]; then