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.

In addition, it checks for the Signed-off-by tag. This simplifies to
detect missing signatures even before creating a PR when being executed
locally.

Please note:
 - gitlint 0.15.1 is required to detect the tags created by Git.
 - Using the gitlint-ignore tag in a commit message allows to suppress
   gitlint findings for a specific commit.

Signed-off-by: Reto Schneider <code@reto-schneider.ch>
  • Loading branch information
rettichschnidi committed Apr 21, 2021
1 parent 9862691 commit 2cb9156
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/compliance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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: |
tools/ci/run_ci.sh --branch-source origin/${{ github.head_ref }} --branch-target origin/${{ github.base_ref }} --run-gitlint
2 changes: 2 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[general]
contrib=contrib-body-requires-signed-off-by,CC1
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 2cb9156

Please sign in to comment.