Skip to content

Commit 3ad7568

Browse files
committed
task: coverity
1 parent 3abbf5d commit 3ad7568

2 files changed

Lines changed: 127 additions & 0 deletions

File tree

‎.github/workflows/coverity.yml‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Coverity Scan
2+
3+
# Public static analysis via the free Coverity Scan service (scan.coverity.com,
4+
# operated by Black Duck). Coverity is a compiled-language analyzer: it must wrap
5+
# the real C build with `cov-build`, so this workflow installs the toolchain,
6+
# compiles the extensions under capture, and uploads the result.
7+
#
8+
# This project must be built with Intel icx, not gcc: CMakeLists.txt applies
9+
# -fveclib=SVML, -fvectorize and -fimf-precision=high unconditionally, and gcc
10+
# rejects all three. That mirrors build-with-clang.yml and the conda recipe.
11+
#
12+
# One-time setup (done once per project, outside this workflow):
13+
# 1. Register IntelPython/mkl_umath at https://scan.coverity.com/github
14+
# (the project name must match COVERITY_PROJECT below).
15+
# 2. Add two repository secrets (Settings -> Secrets and variables -> Actions):
16+
# COVERITY_SCAN_TOKEN - the project token from the Project Settings tab
17+
# COVERITY_SCAN_EMAIL - a maintainer email for build notifications
18+
#
19+
# Free-tier quota for a project under 100K LOC is 28 builds/week, max 4/day, so
20+
# this runs on a weekly schedule plus on demand rather than per-push.
21+
22+
on:
23+
schedule:
24+
- cron: "0 1 * * 1" # Mondays 01:00 UTC; well under the free build quota
25+
workflow_dispatch:
26+
27+
permissions:
28+
contents: read
29+
30+
concurrency:
31+
group: coverity-${{ github.ref }}
32+
cancel-in-progress: true
33+
34+
env:
35+
COVERITY_PROJECT: IntelPython/mkl_umath
36+
ONEAPI_ROOT: /opt/intel/oneapi
37+
38+
jobs:
39+
coverity-scan:
40+
# Forks lack the COVERITY_SCAN_* secrets; only run on the canonical repo.
41+
if: github.repository == 'IntelPython/mkl_umath'
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Checkout repo
46+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Setup Python
51+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
52+
with:
53+
python-version: "3.12"
54+
architecture: x64
55+
56+
- name: Add Intel repository
57+
run: |
58+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
59+
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
60+
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
61+
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
62+
sudo apt-get update
63+
64+
- name: Install Intel oneAPI
65+
run: |
66+
sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp
67+
sudo apt-get install -y intel-oneapi-mkl-devel
68+
69+
- name: Install mkl_umath dependencies
70+
run: pip install scikit-build cmake ninja cython "setuptools>=77" "numpy>=2"
71+
72+
- name: Download Coverity Build Tool
73+
env:
74+
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
75+
run: |
76+
curl --location --no-progress-meter \
77+
--data-urlencode "token=${COVERITY_SCAN_TOKEN}" \
78+
--data-urlencode "project=${COVERITY_PROJECT}" \
79+
--output cov-analysis.tar.gz \
80+
https://scan.coverity.com/download/linux64
81+
# An invalid token/project returns a small HTML error page, not the
82+
# multi-hundred-MB tarball. Fail loudly with a clear hint if so.
83+
if [ "$(stat -c '%s' cov-analysis.tar.gz)" -lt 1000000 ]; then
84+
echo "::error::Coverity build tool download failed. Verify the COVERITY_SCAN_TOKEN secret and that the registered project name matches '${COVERITY_PROJECT}'."
85+
head -c 512 cov-analysis.tar.gz || true
86+
exit 1
87+
fi
88+
mkdir -p cov-analysis
89+
tar -xzf cov-analysis.tar.gz --strip 1 -C cov-analysis
90+
echo "${PWD}/cov-analysis/bin" >> "$GITHUB_PATH"
91+
92+
- name: Build under cov-build
93+
run: |
94+
# shellcheck disable=SC1091
95+
source "${ONEAPI_ROOT}/setvars.sh"
96+
export CC="${CMPLR_ROOT}/bin/icx"
97+
# icx is clang-based but not auto-configured like gcc, so teach the
98+
# Coverity front-end about it before capturing the build.
99+
cov-configure --template --comptype clangcc --compiler "${CC}"
100+
# scikit-build caches its CMake tree in _skbuild and will skip
101+
# recompiling translation units that are already up to date, which
102+
# under-reports (or empties) the Coverity emit. Force a real rebuild.
103+
rm -rf _skbuild
104+
cov-build --dir cov-int pip install . --no-build-isolation --no-deps 2>&1 | tee cov-build.log
105+
# The project has 4 C translation units (mkl_umath_loops.c,
106+
# ufuncsmodule.c, generated __umath_generated.c and Cython
107+
# _patch_numpy.c); bail out if none were captured.
108+
if ! grep -qE "Emitted [1-9][0-9]* .*compilation unit" cov-build.log; then
109+
echo "::error::Coverity captured 0 compilation units — the C build did not run under cov-build."
110+
exit 1
111+
fi
112+
113+
- name: Submit results to Coverity Scan
114+
env:
115+
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
116+
COVERITY_SCAN_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }}
117+
run: |
118+
tar -czf cov-int.tgz cov-int
119+
curl --no-progress-meter \
120+
--form token="${COVERITY_SCAN_TOKEN}" \
121+
--form email="${COVERITY_SCAN_EMAIL}" \
122+
--form file=@cov-int.tgz \
123+
--form version="${GITHUB_SHA}" \
124+
--form description="GitHub Actions ${GITHUB_REF_NAME} (run ${GITHUB_RUN_ID})" \
125+
--form project="${COVERITY_PROJECT}" \
126+
https://scan.coverity.com/builds

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Conda package](https://github.com/IntelPython/mkl_umath/actions/workflows/conda-package.yml/badge.svg)](https://github.com/IntelPython/mkl_umath/actions/workflows/conda-package.yml)
22
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/IntelPython/mkl_umath/badge)](https://securityscorecards.dev/viewer/?uri=github.com/IntelPython/mkl_umath)
3+
[![Coverity Scan Build Status](https://scan.coverity.com/projects/33201/badge.svg)](https://scan.coverity.com/projects/intelpython-mkl_umath)
34

45
# `mkl_umath`
56

0 commit comments

Comments
 (0)