[gnome-shell-extensions] ci: Import run-eslint script from gnome-shell
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions] ci: Import run-eslint script from gnome-shell
- Date: Wed, 14 Aug 2019 16:36:04 +0000 (UTC)
commit 119da3291bc149d14acf4a30e261a97ae55ab1f0
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Aug 14 13:19:36 2019 +0200
ci: Import run-eslint script from gnome-shell
Since we dropped the legacy configuration, we run eslint directly
instead of via a script. However gnome-shell's variant of the script
also has special treatment of merge requests to only consider errors
in changed lines.
While we strive for zero errors, new errors can appear when we update
eslint or change the configuration. Not blocking merge requests due
to unrelated eslint errors is a good thing, run eslint through a
modified version of the gnome-shell script.
https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/90
.gitlab-ci.yml | 7 ++---
.gitlab-ci/run-eslint.sh | 78 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 5 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8f6b13a..b008266 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,9 +3,6 @@ stages:
- source_check
- build
-variables:
- LINT_LOG: "eslint-report.txt"
-
.only_default: &only_default
only:
- branches
@@ -24,11 +21,11 @@ eslint:
image: registry.gitlab.gnome.org/gnome/gnome-shell/extension-ci:v1
stage: source_check
script:
- - eslint -o $LINT_LOG --no-color || { cat $LINT_LOG; false; }
+ - ./.gitlab-ci/run-eslint.sh
<<: *only_default
artifacts:
paths:
- - ${LINT_LOG}
+ - reports
when: on_failure
build-shell-extensions:
diff --git a/.gitlab-ci/run-eslint.sh b/.gitlab-ci/run-eslint.sh
new file mode 100755
index 0000000..a5cb204
--- /dev/null
+++ b/.gitlab-ci/run-eslint.sh
@@ -0,0 +1,78 @@
+#!/usr/bin/env bash
+
+OUTPUT_REGULAR=reports/lint-report.txt
+OUTPUT_MR=reports/lint-mr-report.txt
+
+SRCDIR=extensions
+
+LINE_CHANGES=changed-lines.txt
+
+is_empty() {
+ (! grep -q . $1)
+}
+
+run_eslint() {
+ # ensure output exists even if eslint doesn't report any errors
+ mkdir -p $(dirname $OUTPUT_REGULAR)
+ touch $OUTPUT_REGULAR
+
+ eslint -f unix -o $OUTPUT_REGULAR $SRCDIR
+}
+
+list_commit_range_additions() {
+ # Turn raw context-less git-diff into a list of
+ # filename:lineno pairs of new (+) lines
+ git diff -U0 "$@" -- js |
+ awk '
+ BEGIN { file=""; }
+ /^+++ b/ { file=substr($0,7); }
+ /^@@ / {
+ len = split($3,a,",")
+ start=a[1]
+ count=(len > 1) ? a[2] : 1
+
+ for (line=start; line<start+count; line++)
+ printf "%s/%s:%d:\n",ENVIRON["PWD"],file,line;
+ }'
+}
+
+copy_matched_lines() {
+ local source=$1
+ local matches=$2
+ local target=$3
+
+ echo -n > $target
+ for l in $(<$matches); do
+ grep $l $source >> $target
+ done
+}
+
+# Clean up old files from previous runs
+rm -f $OUTPUT_REGULAR $OUTPUT_MR $LINE_CHANGES
+
+if [ "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then
+ git fetch $CI_MERGE_REQUEST_PROJECT_URL.git $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
+ branch_point=$(git merge-base HEAD FETCH_HEAD)
+ commit_range=$branch_point...$CI_COMMIT_SHA
+
+ list_commit_range_additions $commit_range > $LINE_CHANGES
+
+ # Don't bother with running lint when no JS changed
+ if is_empty $LINE_CHANGES; then
+ exit 0
+ fi
+fi
+
+echo Generating lint report
+run_eslint
+echo Done.
+
+# Just show the report and succeed when not testing a MR
+if [ -z "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then
+ cat $OUTPUT_REGULAR
+ exit 0
+fi
+
+copy_matched_lines $OUTPUT_REGULAR $LINE_CHANGES $OUTPUT_MR
+cat $OUTPUT_MR
+is_empty $OUTPUT_MR
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]