Skip to content

Commit a56b623

Browse files
dschogitster
authored andcommitted
ci: add a GitHub workflow to submit Coverity scans
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 that accepts "builds" (which contains the object files generated during a standard build as well as a database generated by Coverity's scan tool). Let's add a GitHub workflow to automate all of this. To avoid running it without appropriate Coverity configuration (e.g. the token required to use Coverity's services), the job only runs when the repository variable "ENABLE_COVERITY_SCAN_FOR_BRANCHES" has been configured accordingly (see https://docs.github.com/en/actions/learn-github-actions/variables for details how to configure repository variables): It is expected to be a valid JSON array of branch strings, e.g. `["main", "next"]`. In addition, this workflow requires two repository secrets: - COVERITY_SCAN_EMAIL: the email to send the report to, and - COVERITY_SCAN_TOKEN: the Coverity token (look in the Project Settings tab of your Coverity project). Note: The initial version of this patch used `vapier/coverity-scan-action` to benefit from that Action's caching of the Coverity tool, which is rather large. Sadly, that Action only supports Linux, and we want to have the option of building on Windows, too. Besides, in the meantime Coverity requires `cov-configure` to be runantime, and that Action was not adjusted accordingly, i.e. it seems not to be maintained actively. Therefore it would seem prudent to implement the steps manually instead of using that Action. Initial-patch-by: Taylor Blau <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43c8a30 commit a56b623

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/coverity.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Coverity
2+
3+
# This GitHub workflow automates submitting builds to Coverity Scan. To enable it,
4+
# set the repository variable `ENABLE_COVERITY_SCAN_FOR_BRANCHES` (for details, see
5+
# https://docs.github.com/en/actions/learn-github-actions/variables) to a JSON
6+
# string array containing the names of the branches for which the workflow should be
7+
# run, e.g. `["main", "next"]`.
8+
#
9+
# In addition, two repository secrets must be set (for details how to add secrets, see
10+
# https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions):
11+
# `COVERITY_SCAN_EMAIL` and `COVERITY_SCAN_TOKEN`. The former specifies the
12+
# email to which the Coverity reports should be sent and the latter can be
13+
# obtained from the Project Settings tab of the Coverity project).
14+
15+
on:
16+
push:
17+
18+
jobs:
19+
coverity:
20+
if: contains(fromJSON(vars.ENABLE_COVERITY_SCAN_FOR_BRANCHES || '[""]'), github.ref_name)
21+
runs-on: ubuntu-latest
22+
env:
23+
COVERITY_PROJECT: git
24+
COVERITY_LANGUAGE: cxx
25+
COVERITY_PLATFORM: linux64
26+
steps:
27+
- uses: actions/checkout@v3
28+
- run: ci/install-dependencies.sh
29+
env:
30+
runs_on_pool: ubuntu-latest
31+
32+
- name: download the Coverity Build Tool (${{ env.COVERITY_LANGUAGE }} / ${{ env.COVERITY_PLATFORM}})
33+
run: |
34+
curl https://scan.coverity.com/download/$COVERITY_LANGUAGE/$COVERITY_PLATFORM \
35+
--fail --no-progress-meter \
36+
--output $RUNNER_TEMP/cov-analysis.tgz \
37+
--form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \
38+
--form project="$COVERITY_PROJECT"
39+
- name: extract the Coverity Build Tool
40+
run: |
41+
mkdir $RUNNER_TEMP/cov-analysis &&
42+
tar -xzf $RUNNER_TEMP/cov-analysis.tgz --strip 1 -C $RUNNER_TEMP/cov-analysis
43+
- name: build with cov-build
44+
run: |
45+
export PATH="$RUNNER_TEMP/cov-analysis/bin:$PATH" &&
46+
cov-configure --gcc &&
47+
cov-build --dir cov-int make -j$(nproc)
48+
- name: package the build
49+
run: tar -czvf cov-int.tgz cov-int
50+
- name: submit the build to Coverity Scan
51+
run: |
52+
curl \
53+
--fail \
54+
--form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \
55+
--form email='${{ secrets.COVERITY_SCAN_EMAIL }}' \
56+
57+
--form version='${{ github.sha }}' \
58+
"https://scan.coverity.com/builds?project=$COVERITY_PROJECT"

0 commit comments

Comments
 (0)