git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] .github/workflows: add coverity action

From
Taylor Blau <me@ttaylorr.com>
Date
Sep 21, 2023, 21:53 UTC
Message-ID
<b23951c569660e1891a7fb3ad2c2ea1952897bd7.1695332105.git.me@ttaylorr.com>
In-Reply-To
<4590e1381feb8962cadf2b40b22086531d662ef8.1692675172.git.me@ttaylorr.com>

Coverity is a static analysis tool that detects and generates reports on various security and code quality issues.

It is particularly useful when diagnosing memory safety issues which may be used as part of exploiting a security vulnerability.

Coverity's website provides a service accepts "builds" (which is the output of running `cov-build` on your project, which invokes `make` with additional magic) as input and generates reports as output. In order to generate a report, we have to first compile Git and then upload the build archive to Coverity.

This Action generates and uploads a build archive to Coverity when a GitHub repository has done the following:

- Configured the "COVERITY_SCAN_EMAIL" and "COVERITY_SCAN_TOKEN"
  repository secrets. Tokens are found on the "Project Settings" page at
  [1]. Tokens may be added as repository secrets on GitHub repositories
  by following the guide at [2].
- Enabled Coverity builds by (in addition to the above) creating a
  repository variable called `ENABLE_COVERITY`. Repository variables
  (which are different than secrets) can be added according to the guide
  at [3].

This enables Coverity to automatically report on new changes pushed to the configured branch set, which is specified via the `COVERITY_BRANCHES` repository variable.

The implementation is mostly straightforward. Though note that we could upload the build archive to Coverity directly with a straightforward curl request. But using the vapier/coverity-scan Action comes with some additional niceties, such as caching the (rather large) Coverity tool download between runs.

If the repository does not have the `ENABLE_COVERITY` variable set, or the list of branches specified by `COVERITY_BRANCHES` does not contain the branch being pushed to, this Action is a no-op.

[1]: https://scan.coverity.com/projects/NAME?tab=project_settings [2]: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions [3]: https://docs.github.com/en/actions/learn-github-actions/variables

Helped-by: Jeff King <peff@peff.net>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
This fell to the bottom of my queue, but I got back to it today while
doing some ~~spring~~ fall inbox cleaning :-). Thanks Peff and Johannes
for helpful review in the first round. Range-diff is below:

Range-diff against v1: 1: f74ae75ddb < -: ---------- .github/workflows: add coverity action -: ---------- > 1: b23951c569 .github/workflows: add coverity action

 .github/workflows/coverity.yml | 22 ++++++++++++++++++++++
 ci/install-dependencies.sh     |  2 +-
 ci/lib.sh                      |  2 +-
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 .github/workflows/coverity.yml
diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml
new file mode 100644
index 0000000000..3ba00b3929
--- /dev/null
+++ b/.github/workflows/coverity.yml
@@ -0,0 +1,22 @@
+name: Coverity
+
+on: [push, pull_request]
+
+jobs:
+  coverity:
+    if: (vars.ENABLE_COVERITY == 'true') &&
+      (vars.COVERITY_BRANCHES == '' ||
+       contains(vars.COVERITY_BRANCHES, github.ref_name) ||
+       contains(vars.COVERITY_BRANCHES, '*'))
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+      - run: ci/install-dependencies.sh
+        env:
+          jobname: coverity
+      - uses: vapier/coverity-scan-action@cae3c096a2eb21c431961a49375ac17aea2670ce
+        with:
+          email: ${{ secrets.COVERITY_SCAN_EMAIL }}
+          token: ${{ secrets.COVERITY_SCAN_TOKEN }}
+          command: make -j8
+
diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh
index 4f407530d3..7e100ee63f 100755
--- a/ci/install-dependencies.sh
+++ b/ci/install-dependencies.sh
@@ -74,7 +74,7 @@ Documentation)
 	test -n "$ALREADY_HAVE_ASCIIDOCTOR" ||
 	sudo gem install --version 1.5.8 asciidoctor
 	;;
-linux-gcc-default)
+linux-gcc-default|coverity)
 	sudo apt-get -q update
 	sudo apt-get -q -y install $UBUNTU_COMMON_PKGS
 	;;
diff --git a/ci/lib.sh b/ci/lib.sh
index 6fbb5bade1..2ad0ae340e 100755
--- a/ci/lib.sh
+++ b/ci/lib.sh
@@ -227,7 +227,7 @@ export SKIP_DASHED_BUILT_INS=YesPlease

 case "$runs_on_pool" in
 ubuntu-*)
-	if test "$jobname" = "linux-gcc-default"
+	if test "$jobname" = "linux-gcc-default" || test "$jobname" = "coverity"
 	then
 		break
 	fi
--
2.42.0.242.gc844f407a1
Previous: Jeff KingNext: Junio C Hamano
Message 8 of 13 in “.github/workflows: add coverity action”
  1. .github/workflows: add coverity actionTaylor Blau, Aug 22, 2023
  2. Jeff KingAug 25, 2023
  3. Jeff KingAug 25, 2023
  4. Johannes SchindelinAug 29, 2023
  5. Jeff KingAug 30, 2023
  6. Johannes SchindelinAug 30, 2023
  7. Jeff KingAug 30, 2023
  8. .github/workflows: add coverity actionTaylor Blau, Sep 21, 2023
  9. Junio C HamanoSep 21, 2023
  10. Johannes SchindelinSep 22, 2023
  11. Jeff KingSep 23, 2023
  12. Jeff KingSep 23, 2023
  13. Jeff KingSep 23, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.