[gnome-contacts/feature/style-checks] ci: Do some basic style checks
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts/feature/style-checks] ci: Do some basic style checks
- Date: Thu, 3 Dec 2020 21:15:22 +0000 (UTC)
commit b1f89f91156a2b61fc02ac119b054fc89b649412
Author: Niels De Graef <nielsdegraef gmail com>
Date: Thu Dec 3 22:04:14 2020 +0100
ci: Do some basic style checks
.gitlab-ci.yml | 17 ++++++
{.gitlab-ci => .gitlab/ci}/meson-junit-report.py | 0
{.gitlab-ci => .gitlab/ci}/run-tests.sh | 0
.gitlab/ci/style-check.sh | 71 ++++++++++++++++++++++++
4 files changed, 88 insertions(+)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d7184820..d4f43db0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,5 +1,22 @@
include: 'https://gitlab.gnome.org/GNOME/citemplates/raw/master/flatpak/flatpak_ci_initiative.yml'
+stages:
+ - review
+ - test
+ - deploy
+
+style-check:
+ stage: review
+ script:
+ - ./.gitlab/ci/style-check.sh
+ artifacts:
+ expire_in: 1 week
+ paths:
+ - style-check-junit-report.xml
+ reports:
+ junit: style-check-junit-report.xml
+
+
flatpak:
image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master
variables:
diff --git a/.gitlab-ci/meson-junit-report.py b/.gitlab/ci/meson-junit-report.py
similarity index 100%
rename from .gitlab-ci/meson-junit-report.py
rename to .gitlab/ci/meson-junit-report.py
diff --git a/.gitlab-ci/run-tests.sh b/.gitlab/ci/run-tests.sh
similarity index 100%
rename from .gitlab-ci/run-tests.sh
rename to .gitlab/ci/run-tests.sh
diff --git a/.gitlab/ci/style-check.sh b/.gitlab/ci/style-check.sh
new file mode 100755
index 00000000..3752ec1c
--- /dev/null
+++ b/.gitlab/ci/style-check.sh
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+
+###############################################################################
+# JUNIT HELPERS
+###############################################################################
+
+JUNIT_REPORT_TESTS_FILE=$(mktemp)
+
+function append_failed_test_case() {
+ test_name="$1"
+ test_message="$2"
+
+ echo "<testcase name=\"$test_name:\"><failure message=\"$test_message\"/></testcase>" >>
$JUNIT_REPORT_TESTS_FILE
+ echo &>2 "Test '$test_name' failed: $test_message"
+}
+
+function append_passed_test_case() {
+ test_name="$1"
+ commit="$2"
+
+ echo "<testcase name=\"$test_name\"></testcase>" >> $JUNIT_REPORT_TESTS_FILE
+}
+
+function generate_junit_report() {
+ junit_report_file="$1"
+ num_tests=$(cat "$JUNIT_REPORT_TESTS_FILE" | wc -l)
+ num_failures=$(grep '<failure' "$JUNIT_REPORT_TESTS_FILE" | wc -l )
+
+ echo Generating JUnit report \"$(pwd)/$junit_report_file\" with $num_tests tests and $num_failures
failures.
+
+ cat > $junit_report_file << __EOF__
+<?xml version="1.0" encoding="utf-8"?>
+<testsuites tests="$num_tests" errors="0" failures="$num_failures">
+<testsuite name="style-review" tests="$num_tests" errors="0" failures="$num_failures" skipped="0">
+$(< $JUNIT_REPORT_TESTS_FILE)
+</testsuite>
+</testsuites>
+__EOF__
+}
+
+
+###############################################################################
+# STYLE CHECKS
+###############################################################################
+
+TESTNAME="NoTabs"
+tabs_occurrences="$(fgrep -nR $'\t' src data)"
+if [[ -z "$tabs_occurrences" ]]; then
+ append_passed_test_case "$TESTNAME"
+else
+ append_failed_test_case "$TESTNAME" \
+ "Please remove the tabs found at the following places:\nc\n$tabs_occcurrences"
+fi
+
+
+TESTNAME="NoTrailingWhitespace"
+trailing_ws_occurrences="$(grep -nri '[[:blank:]]$' src data)"
+if [[ -z "$trailing_ws_occurrences" ]]; then
+ append_passed_test_case "$TESTNAME"
+else
+ append_failed_test_case "$TESTNAME" \
+ "Please remove the trailing whitespace at the following places:\nc\n$trailing_ws_occcurrences"
+fi
+
+
+# Generate the report
+# and fail this step if any failure occurred
+generate_junit_report style-check-junit-report.xml
+
+! grep -q '<failure' style-check-junit-report.xml
+exit $?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]