From 95645a2080455ffb44a6601780160231356fe7c0 Mon Sep 17 00:00:00 2001 From: "Harlow, Jordan" Date: Tue, 28 Jul 2026 11:32:42 -0600 Subject: [PATCH] task: coverity scanning --- .github/workflows/coverity.yml | 106 +++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 107 insertions(+) create mode 100644 .github/workflows/coverity.yml diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 0000000..405ca25 --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,106 @@ +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 Meson build +# stack, compiles the extension under capture, and uploads the result. +# +# One-time setup (done once per project, outside this workflow): +# 1. Register IntelPython/mkl_fft 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_fft + +jobs: + coverity-scan: + # Forks lack the COVERITY_SCAN_* secrets; only run on the canonical repo. + if: github.repository == 'IntelPython/mkl_fft' + 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 + + # Meson locates MKL through its CMake config (see meson.build), so the + # mkl-devel wheel is enough -- no MKLROOT or oneAPI install required. + - name: Install mkl_fft dependencies + run: pip install meson-python ninja cmake cython "numpy>=2" mkl-devel + + - 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: Configure Coverity for GCC + run: cov-configure --gcc + + - name: Build under cov-build + run: | + # Meson caches its build tree in build/ and skips compiling when it is + # up to date, which would leave Coverity with nothing to capture and + # get the upload rejected. Remove it to force a real rebuild. + rm -rf build + cov-build --dir cov-int pip install -e . --no-build-isolation --no-deps 2>&1 | tee cov-build.log + # The extension has 2 C translation units (the generated mklfft.c and + # the Cython-generated _pydfti.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 diff --git a/README.md b/README.md index d7b5f5d..14e5ebc 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Editable build using pip and pre-release NumPy](https://github.com/IntelPython/mkl_fft/actions/workflows/build_pip.yml/badge.svg)](https://github.com/IntelPython/mkl_fft/actions/workflows/build_pip.yml) [![Conda package with conda-forge channel only](https://github.com/IntelPython/mkl_fft/actions/workflows/conda-package-cf.yml/badge.svg)](https://github.com/IntelPython/mkl_fft/actions/workflows/conda-package-cf.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/IntelPython/mkl_fft/badge)](https://securityscorecards.dev/viewer/?uri=github.com/IntelPython/mkl_fft) +[![Coverity Scan Build Status](https://scan.coverity.com/projects/33202/badge.svg)](https://scan.coverity.com/projects/intelpython-mkl_fft) ## `mkl_fft` -- a NumPy-based Python interface to Intel® oneAPI Math Kernel Library (oneMKL) Fourier Transform Functions