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"]`.
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).
15
# The workflow runs on `ubuntu-latest` by default. This can be overridden by setting
16
# the repository variable `ENABLE_COVERITY_SCAN_ON_OS` to a JSON string array specifying
17
# the operating systems, e.g. `["ubuntu-latest", "windows-latest"]`.
19
# By default, the builds are submitted to the Coverity project `git`. To override this,
20
# set the repository variable `COVERITY_PROJECT`.
31
if: contains(fromJSON(vars.ENABLE_COVERITY_SCAN_FOR_BRANCHES || '[""]'), github.ref_name)
34
os: ${{ fromJSON(vars.ENABLE_COVERITY_SCAN_ON_OS || '["ubuntu-latest"]') }}
35
runs-on: ${{ matrix.os }}
37
COVERITY_PROJECT: ${{ vars.COVERITY_PROJECT || 'git' }}
38
COVERITY_LANGUAGE: cxx
39
COVERITY_PLATFORM: overridden-below
41
- uses: actions/checkout@v4
42
- name: install minimal Git for Windows SDK
43
if: contains(matrix.os, 'windows')
44
uses: git-for-windows/setup-git-for-windows-sdk@v1
45
- run: ci/install-dependencies.sh
46
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos')
48
distro: ${{ matrix.os }}
50
# The Coverity site says the tool is usually updated twice yearly, so the
51
# MD5 of download can be used to determine whether there's been an update.
52
- name: get the Coverity Build Tool hash
55
case "${{ matrix.os }}" in
57
COVERITY_PLATFORM=win64
58
COVERITY_TOOL_FILENAME=cov-analysis.zip
62
COVERITY_PLATFORM=macOSX
63
COVERITY_TOOL_FILENAME=cov-analysis.dmg
64
MAKEFLAGS=-j$(sysctl -n hw.physicalcpu)
67
COVERITY_PLATFORM=linux64
68
COVERITY_TOOL_FILENAME=cov-analysis.tgz
72
echo '::error::unhandled OS ${{ matrix.os }}' >&2
76
echo "COVERITY_PLATFORM=$COVERITY_PLATFORM" >>$GITHUB_ENV
77
echo "COVERITY_TOOL_FILENAME=$COVERITY_TOOL_FILENAME" >>$GITHUB_ENV
78
echo "MAKEFLAGS=$MAKEFLAGS" >>$GITHUB_ENV
79
MD5=$(curl https://scan.coverity.com/download/$COVERITY_LANGUAGE/$COVERITY_PLATFORM \
81
--form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \
82
--form project="$COVERITY_PROJECT" \
86
22) # 40x, i.e. access denied
87
echo "::error::incorrect token or project?" >&2
91
echo "::error::Failed to retrieve MD5" >&2
95
echo "hash=$MD5" >>$GITHUB_OUTPUT
97
# Try to cache the tool to avoid downloading 1GB+ on every run.
98
# A cache miss will add ~30s to create, but a cache hit will save minutes.
99
- name: restore the Coverity Build Tool
101
uses: actions/cache/restore@v4
103
path: ${{ runner.temp }}/cov-analysis
104
key: cov-build-${{ env.COVERITY_LANGUAGE }}-${{ env.COVERITY_PLATFORM }}-${{ steps.lookup.outputs.hash }}
105
- name: download the Coverity Build Tool (${{ env.COVERITY_LANGUAGE }} / ${{ env.COVERITY_PLATFORM}})
106
if: steps.cache.outputs.cache-hit != 'true'
108
curl https://scan.coverity.com/download/$COVERITY_LANGUAGE/$COVERITY_PLATFORM \
109
--fail --no-progress-meter \
110
--output $RUNNER_TEMP/$COVERITY_TOOL_FILENAME \
111
--form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \
112
--form project="$COVERITY_PROJECT"
113
- name: extract the Coverity Build Tool
114
if: steps.cache.outputs.cache-hit != 'true'
116
case "$COVERITY_TOOL_FILENAME" in
118
mkdir $RUNNER_TEMP/cov-analysis &&
119
tar -xzf $RUNNER_TEMP/$COVERITY_TOOL_FILENAME --strip 1 -C $RUNNER_TEMP/cov-analysis
123
attach="$(hdiutil attach $COVERITY_TOOL_FILENAME)" &&
124
volume="$(echo "$attach" | cut -f 3 | grep /Volumes/)" &&
125
mkdir cov-analysis &&
127
sh "$volume"/cov-analysis-macosx-*.sh &&
129
hdiutil detach "$volume"
133
mkdir cov-analysis-tmp &&
134
unzip -d cov-analysis-tmp $COVERITY_TOOL_FILENAME &&
135
mv cov-analysis-tmp/* cov-analysis
138
echo "::error::unhandled archive type: $COVERITY_TOOL_FILENAME" >&2
142
- name: cache the Coverity Build Tool
143
if: steps.cache.outputs.cache-hit != 'true'
144
uses: actions/cache/save@v4
146
path: ${{ runner.temp }}/cov-analysis
147
key: cov-build-${{ env.COVERITY_LANGUAGE }}-${{ env.COVERITY_PLATFORM }}-${{ steps.lookup.outputs.hash }}
148
- name: build with cov-build
150
export PATH="$RUNNER_TEMP/cov-analysis/bin:$PATH" &&
151
cov-configure --gcc &&
152
cov-build --dir cov-int make
153
- name: package the build
154
run: tar -czvf cov-int.tgz cov-int
155
- name: submit the build to Coverity Scan
159
--form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \
160
--form email='${{ secrets.COVERITY_SCAN_EMAIL }}' \
161
--form file=@cov-int.tgz \
162
--form version='${{ github.sha }}' \
163
"https://scan.coverity.com/builds?project=$COVERITY_PROJECT"