Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Coverity Scan

# Public static analysis via the free Coverity Scan service (scan.coverity.com,
# operated by Black Duck). Coverity is a compiled-language analyzer: it must wrap
# the real C build with `cov-build`, so this workflow installs the toolchain,
# compiles the extensions under capture, and uploads the result.
#
# This project must be built with Intel icx, not gcc: CMakeLists.txt applies
# -fveclib=SVML, -fvectorize and -fimf-precision=high unconditionally, and gcc
# rejects all three. That mirrors build-with-clang.yml and the conda recipe.
#
# One-time setup (done once per project, outside this workflow):
# 1. Register IntelPython/mkl_umath at https://scan.coverity.com/github
# (the project name must match COVERITY_PROJECT below).
# 2. Add two repository secrets (Settings -> Secrets and variables -> Actions):
# COVERITY_SCAN_TOKEN - the project token from the Project Settings tab
# COVERITY_SCAN_EMAIL - a maintainer email for build notifications
#
# Free-tier quota for a project under 100K LOC is 28 builds/week, max 4/day, so
# this runs on a weekly schedule plus on demand rather than per-push.

on:
schedule:
- cron: "0 1 * * 1" # Mondays 01:00 UTC; well under the free build quota
workflow_dispatch:

permissions:
contents: read

concurrency:
group: coverity-${{ github.ref }}
cancel-in-progress: true

env:
COVERITY_PROJECT: IntelPython/mkl_umath
ONEAPI_ROOT: /opt/intel/oneapi

jobs:
coverity-scan:
# Forks lack the COVERITY_SCAN_* secrets; only run on the canonical repo.
if: github.repository == 'IntelPython/mkl_umath'
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.12"
architecture: x64

- name: Add Intel repository
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
sudo apt-get update

- name: Install Intel oneAPI
run: |
sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp
sudo apt-get install -y intel-oneapi-mkl-devel

- name: Install mkl_umath dependencies
run: pip install scikit-build cmake ninja cython "setuptools>=77" "numpy>=2"

- name: Download Coverity Build Tool
env:
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
run: |
curl --location --no-progress-meter \
--data-urlencode "token=${COVERITY_SCAN_TOKEN}" \
--data-urlencode "project=${COVERITY_PROJECT}" \
--output cov-analysis.tar.gz \
https://scan.coverity.com/download/linux64
# An invalid token/project returns a small HTML error page, not the
# multi-hundred-MB tarball. Fail loudly with a clear hint if so.
if [ "$(stat -c '%s' cov-analysis.tar.gz)" -lt 1000000 ]; then
echo "::error::Coverity build tool download failed. Verify the COVERITY_SCAN_TOKEN secret and that the registered project name matches '${COVERITY_PROJECT}'."
head -c 512 cov-analysis.tar.gz || true
exit 1
fi
mkdir -p cov-analysis
tar -xzf cov-analysis.tar.gz --strip 1 -C cov-analysis
echo "${PWD}/cov-analysis/bin" >> "$GITHUB_PATH"

- name: Build under cov-build
run: |
# shellcheck disable=SC1091
source "${ONEAPI_ROOT}/setvars.sh"
export CC="${CMPLR_ROOT}/bin/icx"
# icx is clang-based but not auto-configured like gcc, so teach the
# Coverity front-end about it before capturing the build.
cov-configure --template --comptype clangcc --compiler "${CC}"
# scikit-build caches its CMake tree in _skbuild and will skip
# recompiling translation units that are already up to date, which
# under-reports (or empties) the Coverity emit. Force a real rebuild.
rm -rf _skbuild
cov-build --dir cov-int pip install . --no-build-isolation --no-deps 2>&1 | tee cov-build.log
# The project has 4 C translation units (mkl_umath_loops.c,
# ufuncsmodule.c, generated __umath_generated.c and Cython
# _patch_numpy.c); bail out if none were captured.
if ! grep -qE "Emitted [1-9][0-9]* .*compilation unit" cov-build.log; then
echo "::error::Coverity captured 0 compilation units — the C build did not run under cov-build."
exit 1
fi

- name: Submit results to Coverity Scan
env:
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
COVERITY_SCAN_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }}
run: |
tar -czf cov-int.tgz cov-int
curl --no-progress-meter \
--form token="${COVERITY_SCAN_TOKEN}" \
--form email="${COVERITY_SCAN_EMAIL}" \
--form file=@cov-int.tgz \
--form version="${GITHUB_SHA}" \
--form description="GitHub Actions ${GITHUB_REF_NAME} (run ${GITHUB_RUN_ID})" \
--form project="${COVERITY_PROJECT}" \
https://scan.coverity.com/builds
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![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)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/IntelPython/mkl_umath/badge)](https://securityscorecards.dev/viewer/?uri=github.com/IntelPython/mkl_umath)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/33201/badge.svg)](https://scan.coverity.com/projects/intelpython-mkl_umath)

# `mkl_umath`

Expand Down
Loading