Skip to content

Commit

Permalink
[eclipse-wakaamaGH-585] ci: Add initial gitlint usage
Browse files Browse the repository at this point in the history
This is a fairly default configuration, which, among other stuff,
checks for the subject line being 72 or less characters as required by
the Eclipse project handbook.

Additional rules:
- Enforce at least 20 characters in the commit body
- Disallow the word "fixup" in the title messages. Intended to prevent
  accidents like d31d026.

Please note:
 - Using the gitlint-ignore tag in a commit message allows to suppress
   gitlint findings for a specific commit.
  • Loading branch information
rettichschnidi committed Apr 21, 2021
1 parent b846bf2 commit 037109d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/compliance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Compliance

on: pull_request

jobs:
check-gitlint:
name: Run gitlint
runs-on: ubuntu-20.04

steps:
- name: Checkout code including full history
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install gitlint
run: |
pip3 install gitlint
- name: Check commits with checkpatch
run: |
git branch -a
tools/ci/run_ci.sh --branch-target origin/${{ github.base_ref }} --run-gitlint
12 changes: 12 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[general]
ignore-fixup-commits=false

[title-must-not-contain-word]
words=wip,fixup

# Enforce at least 20 characters (default value) in every commit body
[body-min-length]

# Tags do not count towards the body length
[ignore-body-lines]
regex=^Signed-off-by
34 changes: 34 additions & 0 deletions tools/ci/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ readonly REPO_ROOT_DIR="${PWD}"
readonly SCRIPT_NAME="$(basename "$0")"

CMAKE_ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo"
OPT_BRANCH_SOURCE=
OPT_BRANCH_TARGET=master
OPT_C_EXTENSIONS=""
OPT_C_STANDARD=""
OPT_SANITIZER=""
Expand All @@ -30,13 +32,18 @@ OPT_VERBOSE=0
OPT_WRAPPER_CMD=""
RUN_BUILD=0
RUN_CLEAN=0
RUN_GITLINT=0
RUN_TESTS=0

HELP_MSG="usage: ${SCRIPT_NAME} <OPTIONS>...
Runs build and test steps in CI.
Select steps to execute with --run- options
Options:
--branch-source BRANCH Source branch for MRs
(default: current branch)
--branch-target BRANCH Target branch for MRs
(default: $OPT_BRANCH_TARGET)
--c-extensions ENABLE Whether to allow compiler extensions. Defaults to
ON.
(ENABLE: ON or OFF)
Expand All @@ -56,6 +63,7 @@ Options:
-h, --help Display this help and exit
Available steps (executed by --all):
--run-gitlint Check git commits with gitlint
--run-clean Remove all build artifacts
--run-build Build all targets
--run-tests Build and execute tests
Expand All @@ -72,6 +80,12 @@ function run_clean() {
rm -rf build-wakaama
}

function run_gitlint() {
commits="${OPT_BRANCH_TARGET}...${OPT_BRANCH_SOURCE}"

gitlint --commits "${commits}"
}

function run_build() {
# Existing directory needed by SonarQube build-wrapper
mkdir -p build-wakaama
Expand Down Expand Up @@ -135,11 +149,14 @@ fi

if ! PARSED_OPTS=$(getopt -o vah \
-l all \
-l branch-source: \
-l branch-target: \
-l c-extensions: \
-l c-standard: \
-l help \
-l run-build \
-l run-clean \
-l run-gitlint \
-l run-tests \
-l sanitizer: \
-l scan-build: \
Expand All @@ -155,6 +172,14 @@ eval set -- "${PARSED_OPTS}"

while true; do
case "$1" in
--branch-source)
OPT_BRANCH_SOURCE=$2
shift 2
;;
--branch-target)
OPT_BRANCH_TARGET=$2
shift 2
;;
--c-extensions)
OPT_C_EXTENSIONS=$2
shift 2
Expand All @@ -171,6 +196,10 @@ while true; do
RUN_BUILD=1
shift 1
;;
--run-gitlint)
RUN_GITLINT=1
shift
;;
--run-tests)
RUN_TESTS=1
shift
Expand Down Expand Up @@ -205,6 +234,7 @@ while true; do
;;
-a|--all)
RUN_CLEAN=1
RUN_GITLINT=1
RUN_BUILD=1
RUN_TESTS=1
shift
Expand Down Expand Up @@ -262,6 +292,10 @@ fi

# Run Steps

if [[ $RUN_GITLINT == 1 ]]; then
run_gitlint
fi

if [ "${RUN_CLEAN}" -eq 1 ]; then
run_clean
fi
Expand Down

0 comments on commit 037109d

Please sign in to comment.