From 09a09dd1023eda797707af3bf327652d9045a4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 6 Nov 2020 18:02:23 +0100 Subject: [PATCH] ci/check-commit-log: Generate JUnit report This means the merge request will see the commit log review issues causing the pipeline to fail without having to dig through CI log files. Part-of: --- .gitlab-ci.yml | 6 +++++ .gitlab-ci/check-commit-log.sh | 47 ++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 581ef2ba0..36dee4008 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,6 +27,12 @@ check_commit_log: - ./.gitlab-ci/check-commit-log.sh only: - merge_requests + artifacts: + expire_in: 1 week + paths: + - commit-message-junit-report.xml + reports: + junit: commit-message-junit-report.xml js_check: image: registry.gitlab.gnome.org/gnome/gnome-shell/extension-ci:v2 diff --git a/.gitlab-ci/check-commit-log.sh b/.gitlab-ci/check-commit-log.sh index 5a469328d..7cc5b289e 100755 --- a/.gitlab-ci/check-commit-log.sh +++ b/.gitlab-ci/check-commit-log.sh @@ -16,6 +16,42 @@ if [ -z "$commits" ]; then exit 1 fi +JUNIT_REPORT_TESTS_FILE=$(mktemp) + +function append_failed_test_case() { + test_name="$1" + commit="$2" + test_message="$3" + commit_short=${commit:0:8} + + echo "" >> $JUNIT_REPORT_TESTS_FILE + echo &>2 "Commit check failed: $commit_short: $test_message" +} + +function append_passed_test_case() { + test_name="$1" + commit="$2" + commit_short=${commit:0:8} + echo "" >> $JUNIT_REPORT_TESTS_FILE +} + +function generate_junit_report() { + junit_report_file="$1" + num_tests=$(cat "$JUNIT_REPORT_TESTS_FILE" | wc -l) + num_failures=$(grep '' "$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__ + + + +$(< $JUNIT_REPORT_TESTS_FILE) + + +__EOF__ +} + function commit_message_has_mr_url() { commit=$1 commit_message=$(git show -s --format='format:%b' $commit) @@ -25,7 +61,14 @@ function commit_message_has_mr_url() { for commit in $commits; do if commit_message_has_mr_url $commit; then - echo "Commit $(echo $commit | cut -c -8) message must not contain a link to its own merge request" - exit 1 + append_failed_test_case superfluous_url $commit \ + "Commit message must not contain a link to its own merge request" + else + append_passed_test_case superfluous_url $commit fi done + +generate_junit_report commit-message-junit-report.xml + +! grep -q '