threads / patch / 60667

patchci: add job performing static analysis on GitLab CI

Subject: [PATCH] ci: add job performing static analysis on GitLab CI

## tl;dr

2 messages between Dec 28, 2023 and Jan 4, 2024. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Patrick Steinhardt· Dec 28, 2023, 11:02 UTC · lore

Our GitHub Workflows definitions have a static analysis job that runs the following tasks:

  - Coccinelle to check for suggested refactorings.
  - `make hdr-check` to check for missing includes or forward
    declarations in our header files.
  - `make check-pot` to check our translations for issues.
  - `./ci/check-directional-formatting.bash` to check whether our
    sources contain any Unicode directional formatting code points.
Add an equivalent job to our GitLab CI definitions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---

This addition is inspired by my reftable patch series where I forgot to add a "hash-ll.h" include. This would've been catched by our GitLab CI pipeline if we already had the static-analysis job added in this patch.

These changes are part of [1], which thus also contains an example pipeline run.

[1]: https://gitlab.com/gitlab-org/git/-/merge_requests/79
 .gitlab-ci.yml                    | 10 ++++++++++
 ci/install-docker-dependencies.sh |  7 ++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
Show changes to 2 files +16 −1

.gitlab-ci.yml, ci/install-docker-dependencies.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cd98bcb18a..793243421c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -51,3 +51,13 @@ test:
     paths:
       - t/failed-test-artifacts
     when: on_failure
+
+static-analysis:
+  image: ubuntu:22.04
+  variables:
+    jobname: StaticAnalysis
+  before_script:
+    - ./ci/install-docker-dependencies.sh
+  script:
+    - ./ci/run-static-analysis.sh
+    - ./ci/check-directional-formatting.bash
diff --git a/ci/install-docker-dependencies.sh b/ci/install-docker-dependencies.sh
index 48c43f0f90..eb2c9e1eca 100755
--- a/ci/install-docker-dependencies.sh
+++ b/ci/install-docker-dependencies.sh
@@ -21,7 +21,7 @@ linux-musl)
 		apache2 apache2-http2 apache2-proxy apache2-ssl apache2-webdav apr-util-dbd_sqlite3 \
 		bash cvs gnupg perl-cgi perl-dbd-sqlite >/dev/null
 	;;
-linux-*)
+linux-*|StaticAnalysis)
 	# Required so that apt doesn't wait for user input on certain packages.
 	export DEBIAN_FRONTEND=noninteractive
 
@@ -31,6 +31,11 @@ linux-*)
 		perl-modules liberror-perl libauthen-sasl-perl libemail-valid-perl \
 		libdbd-sqlite3-perl libio-socket-ssl-perl libnet-smtp-ssl-perl ${CC_PACKAGE:-${CC:-gcc}} \
 		apache2 cvs cvsps gnupg libcgi-pm-perl subversion
+
+	if test "$jobname" = StaticAnalysis
+	then
+		apt install -q -y coccinelle
+	fi
 	;;
 pedantic)
 	dnf -yq update >/dev/null &&
-- 
2.43.GIT
Toon Claes· Jan 4, 2024, 09:19 UTC · re: Patrick Steinhardt · lore

Re: [PATCH] ci: add job performing static analysis on GitLab CI

Patrick Steinhardt <ps@pks.im> writes:
Show 20 quoted lines
> --- a/ci/install-docker-dependencies.sh
> +++ b/ci/install-docker-dependencies.sh
> @@ -21,7 +21,7 @@ linux-musl)
>  		apache2 apache2-http2 apache2-proxy apache2-ssl apache2-webdav apr-util-dbd_sqlite3 \
>  		bash cvs gnupg perl-cgi perl-dbd-sqlite >/dev/null
>  	;;
> -linux-*)
> +linux-*|StaticAnalysis)
>  	# Required so that apt doesn't wait for user input on certain packages.
>  	export DEBIAN_FRONTEND=noninteractive
>
> @@ -31,6 +31,11 @@ linux-*)
>  		perl-modules liberror-perl libauthen-sasl-perl libemail-valid-perl \
>  		libdbd-sqlite3-perl libio-socket-ssl-perl libnet-smtp-ssl-perl ${CC_PACKAGE:-${CC:-gcc}} \
>  		apache2 cvs cvsps gnupg libcgi-pm-perl subversion
> +
> +	if test "$jobname" = StaticAnalysis
> +	then
> +		apt install -q -y coccinelle
> +	fi

I was wondering why this was added, because I would assume the GitHub Workflow needed this too. Well, it seems the "StaticAnalysis" job for the Workflow runs ci/install-dependencies.sh instead of ci/install-docker-dependencies.sh. The ci/install-docker-dependencies.sh script is only used in the GitHub Workflow for the "dockerized" jobs. They set $jobname to "linux-musl", "linux32", and "pedantic", so this change is not affected by that.

Bottom line, changes all look good to me.

-- Toon

← back to recent threads