From 4b31251b0b626d3d84ffc4a86a8a2c67b26303c6 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 16 Nov 2026 01:01:37 +0200 Subject: [PATCH 1/7] ci: add native CodeQL scans Reuse Linux, Windows and macOS CMake builds for CodeQL on master pushes, weekly schedules, manual dispatch and pull requests labelled ci-codeql. Keep other branch and unlabelled pull-request builds free of scan overhead. Fixes #596 Assisted-by: Codex:GPT-6 --- .github/workflows/builds.yml | 92 +++++++++++++++++++++++++++++++++++- README.md | 6 +++ 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 35b518c56..95a430b88 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -1,15 +1,31 @@ name: GitHub Builds -on: [push, pull_request] +on: + push: + pull_request: + types: [opened, synchronize, reopened, labeled] + schedule: + - cron: '23 4 * * 2' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: builds-${{ github.event.pull_request.number || github.run_id }}-${{ github.event.action == 'labeled' && github.event.label.name || 'build' }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: NIX_COMPILE_FLAGS: -Wall -Wextra -pedantic -Werror GNU_COMPILE_FLAGS: -Wall -Wextra -pedantic -Werror -Wformat-signedness MSVC_COMPILE_FLAGS: /W4 /WX + # Branch pushes keep ordinary CI; PR scans are opt-in via ci-codeql. + CODEQL_ENABLED: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/master') || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-codeql')) }} jobs: macos-automake: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: macos-latest steps: @@ -33,7 +49,15 @@ jobs: macos-cmake: - runs-on: macos-latest + if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' + # CodeQL traced builds require macOS and Xcode earlier than version 27. + runs-on: macos-15 + timeout-minutes: 30 + permissions: + contents: read + security-events: write + env: + DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer steps: - uses: actions/checkout@v3 @@ -47,9 +71,25 @@ jobs: cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON -DHIDAPI_WITH_TESTS=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" cmake -B build/framework -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + - name: Initialize CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/init@v4 + timeout-minutes: 10 + with: + languages: c-cpp + build-mode: manual + source-root: hidapisrc - name: Build CMake Shared + timeout-minutes: 5 working-directory: build/shared run: make install + - name: Analyze CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/analyze@v4 + timeout-minutes: 15 + with: + checkout_path: hidapisrc + category: /language:c-cpp/os:macos - name: Build CMake Static working-directory: build/static run: make install @@ -116,7 +156,12 @@ jobs: ubuntu-cmake: + if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + security-events: write steps: - uses: actions/checkout@v3 @@ -132,9 +177,25 @@ jobs: rm -rf build install cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON -DHIDAPI_WITH_TESTS=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}" cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}" + - name: Initialize CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/init@v4 + timeout-minutes: 10 + with: + languages: c-cpp + build-mode: manual + source-root: hidapisrc - name: Build CMake Shared + timeout-minutes: 5 working-directory: build/shared run: make install + - name: Analyze CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/analyze@v4 + timeout-minutes: 15 + with: + checkout_path: hidapisrc + category: /language:c-cpp/os:linux - name: Build CMake Static working-directory: build/static run: make install @@ -212,7 +273,12 @@ jobs: windows-cmake-msvc: + if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' runs-on: windows-latest + timeout-minutes: 30 + permissions: + contents: read + security-events: write steps: - uses: actions/checkout@v3 @@ -232,9 +298,25 @@ jobs: shell: cmd run: | cmake -B build\msvc -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" + - name: Initialize CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/init@v4 + timeout-minutes: 10 + with: + languages: c-cpp + build-mode: manual + source-root: hidapisrc - name: Build CMake MSVC + timeout-minutes: 5 working-directory: build/msvc run: cmake --build . --config RelWithDebInfo --target install + - name: Analyze CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/analyze@v4 + timeout-minutes: 15 + with: + checkout_path: hidapisrc + category: /language:c-cpp/os:windows - name: Check artifacts CMake MSVC uses: andstor/file-existence-action@v2 with: @@ -345,6 +427,7 @@ jobs: windows-cmake-mingw: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest steps: @@ -388,6 +471,7 @@ jobs: windows-cygwin: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest defaults: @@ -446,6 +530,7 @@ jobs: windows-msbuild: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest steps: @@ -484,6 +569,7 @@ jobs: fedora-mingw: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: fedora:latest steps: @@ -554,6 +640,7 @@ jobs: archlinux: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: archlinux:latest steps: @@ -628,6 +715,7 @@ jobs: alpine: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: alpine:edge env: diff --git a/README.md b/README.md index f13b94628..208ba7b14 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,12 @@ | `BSD, last build (branch/PR)` | [![builds.sr.ht status](https://builds.sr.ht/~z3ntu/hidapi.svg)](https://builds.sr.ht/~z3ntu/hidapi) | | `Coverity Scan (last)` | [![Coverity Scan](https://scan.coverity.com/projects/583/badge.svg)](https://scan.coverity.com/projects/hidapi) | +The GitHub Builds workflow runs CodeQL on every push to `master`, weekly, and +on manual dispatch. Pull requests opt in with the `ci-codeql` label. Scans reuse +the native CMake builds for Windows, macOS, and both Linux backends, using the +default security queries. Native BSD backends and inactive preprocessor branches +are outside this coverage. + HIDAPI is a multi-platform library which allows an application to interface with USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and macOS. HIDAPI can be either built as a shared library (`.so`, `.dll` or `.dylib`) or From 5adb27e3977a46dc35de1d1ea34ba47dc2384d14 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 16 Nov 2026 01:08:52 +0200 Subject: [PATCH 2/7] ci: preserve macOS architecture across CodeQL tracing Keep CMake package consumers on arm64 when CodeQL launches tools through Rosetta. Remove the README explanation as requested. Assisted-by: Codex:GPT-6 --- .github/workflows/builds.yml | 2 ++ README.md | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 95a430b88..d1df0e4de 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -58,6 +58,8 @@ jobs: security-events: write env: DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer + # CodeQL can launch later CMake invocations through Rosetta. + CMAKE_APPLE_SILICON_PROCESSOR: arm64 steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index 208ba7b14..f13b94628 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,6 @@ | `BSD, last build (branch/PR)` | [![builds.sr.ht status](https://builds.sr.ht/~z3ntu/hidapi.svg)](https://builds.sr.ht/~z3ntu/hidapi) | | `Coverity Scan (last)` | [![Coverity Scan](https://scan.coverity.com/projects/583/badge.svg)](https://scan.coverity.com/projects/hidapi) | -The GitHub Builds workflow runs CodeQL on every push to `master`, weekly, and -on manual dispatch. Pull requests opt in with the `ci-codeql` label. Scans reuse -the native CMake builds for Windows, macOS, and both Linux backends, using the -default security queries. Native BSD backends and inactive preprocessor branches -are outside this coverage. - HIDAPI is a multi-platform library which allows an application to interface with USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and macOS. HIDAPI can be either built as a shared library (`.so`, `.dll` or `.dylib`) or From bd44cc1e3d14149b43ea7e77b980e2e7d02bf892 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 16 Nov 2026 01:16:39 +0200 Subject: [PATCH 3/7] ci: distinguish scan-only runs from required build checks Keep the existing check names for pushes and ordinary pull request events. Prefix scan-only checks so skipped jobs cannot replace required CI results. Assisted-by: Codex:GPT-6 --- .github/workflows/builds.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index d1df0e4de..1cad66e75 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -25,6 +25,7 @@ env: jobs: macos-automake: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}macos-automake if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: macos-latest @@ -49,6 +50,7 @@ jobs: macos-cmake: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}macos-cmake if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' # CodeQL traced builds require macOS and Xcode earlier than version 27. runs-on: macos-15 @@ -158,6 +160,7 @@ jobs: ubuntu-cmake: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}ubuntu-cmake if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' runs-on: ubuntu-latest timeout-minutes: 30 @@ -275,6 +278,7 @@ jobs: windows-cmake-msvc: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-cmake-msvc if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' runs-on: windows-latest timeout-minutes: 30 @@ -429,6 +433,7 @@ jobs: windows-cmake-mingw: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-cmake-mingw if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest @@ -473,6 +478,7 @@ jobs: windows-cygwin: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-cygwin if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest @@ -532,6 +538,7 @@ jobs: windows-msbuild: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-msbuild if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest @@ -571,6 +578,7 @@ jobs: fedora-mingw: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}fedora-mingw if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: fedora:latest @@ -642,6 +650,7 @@ jobs: archlinux: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}archlinux if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: archlinux:latest @@ -717,6 +726,7 @@ jobs: alpine: + name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}alpine if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: alpine:edge From 30f9d82bd7cc0a09dae805da0095202219cd9d8f Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 16 Nov 2026 01:19:27 +0200 Subject: [PATCH 4/7] ci: isolate CodeQL capture from ordinary build checks Run tracing after the normal checks and capture a clean rebuild of the configured native targets. This retains source coverage without carrying tracing overhead into the remaining compiler and packaging checks. Assisted-by: Codex:GPT-6 --- .github/workflows/builds.yml | 110 ++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 1cad66e75..4f53ef648 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -60,7 +60,7 @@ jobs: security-events: write env: DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer - # CodeQL can launch later CMake invocations through Rosetta. + # Keep arm64 output when CodeQL launches tools through Rosetta. CMAKE_APPLE_SILICON_PROCESSOR: arm64 steps: @@ -75,25 +75,10 @@ jobs: cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON -DHIDAPI_WITH_TESTS=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" cmake -B build/framework -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - - name: Initialize CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/init@v4 - timeout-minutes: 10 - with: - languages: c-cpp - build-mode: manual - source-root: hidapisrc - name: Build CMake Shared timeout-minutes: 5 working-directory: build/shared run: make install - - name: Analyze CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/analyze@v4 - timeout-minutes: 15 - with: - checkout_path: hidapisrc - category: /language:c-cpp/os:macos - name: Build CMake Static working-directory: build/static run: make install @@ -157,6 +142,27 @@ jobs: cd build_meson ninja + - name: Initialize CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/init@v4 + timeout-minutes: 10 + with: + languages: c-cpp + build-mode: manual + source-root: hidapisrc + - name: Build CodeQL + if: env.CODEQL_ENABLED == 'true' + timeout-minutes: 5 + working-directory: build/shared + run: cmake --build . --clean-first --parallel 2 + - name: Analyze CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/analyze@v4 + timeout-minutes: 15 + with: + checkout_path: hidapisrc + category: /language:c-cpp/os:macos + ubuntu-cmake: @@ -182,25 +188,10 @@ jobs: rm -rf build install cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON -DHIDAPI_WITH_TESTS=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}" cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}" - - name: Initialize CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/init@v4 - timeout-minutes: 10 - with: - languages: c-cpp - build-mode: manual - source-root: hidapisrc - name: Build CMake Shared timeout-minutes: 5 working-directory: build/shared run: make install - - name: Analyze CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/analyze@v4 - timeout-minutes: 15 - with: - checkout_path: hidapisrc - category: /language:c-cpp/os:linux - name: Build CMake Static working-directory: build/static run: make install @@ -275,6 +266,27 @@ jobs: cd build_meson ninja + - name: Initialize CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/init@v4 + timeout-minutes: 10 + with: + languages: c-cpp + build-mode: manual + source-root: hidapisrc + - name: Build CodeQL + if: env.CODEQL_ENABLED == 'true' + timeout-minutes: 5 + working-directory: build/shared + run: cmake --build . --clean-first --parallel 2 + - name: Analyze CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/analyze@v4 + timeout-minutes: 15 + with: + checkout_path: hidapisrc + category: /language:c-cpp/os:linux + windows-cmake-msvc: @@ -304,25 +316,10 @@ jobs: shell: cmd run: | cmake -B build\msvc -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - - name: Initialize CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/init@v4 - timeout-minutes: 10 - with: - languages: c-cpp - build-mode: manual - source-root: hidapisrc - name: Build CMake MSVC timeout-minutes: 5 working-directory: build/msvc run: cmake --build . --config RelWithDebInfo --target install - - name: Analyze CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/analyze@v4 - timeout-minutes: 15 - with: - checkout_path: hidapisrc - category: /language:c-cpp/os:windows - name: Check artifacts CMake MSVC uses: andstor/file-existence-action@v2 with: @@ -430,6 +427,27 @@ jobs: cd build_meson ninja + - name: Initialize CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/init@v4 + timeout-minutes: 10 + with: + languages: c-cpp + build-mode: manual + source-root: hidapisrc + - name: Build CodeQL + if: env.CODEQL_ENABLED == 'true' + timeout-minutes: 5 + working-directory: build/msvc + run: cmake --build . --config RelWithDebInfo --clean-first --parallel 2 + - name: Analyze CodeQL + if: env.CODEQL_ENABLED == 'true' + uses: github/codeql-action/analyze@v4 + timeout-minutes: 15 + with: + checkout_path: hidapisrc + category: /language:c-cpp/os:windows + windows-cmake-mingw: From 0c8d6d6490552072c3825ab78e7f67ecd5b27e9d Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 16 Nov 2026 01:26:18 +0200 Subject: [PATCH 5/7] ci: move CodeQL into an independent native build workflow Scan one Release library build on Linux, Windows and macOS in parallel with ordinary CI. Keep master-push, weekly and manual scans, and gate pull-request scans on ci-codeql. Restore the ordinary build workflow. Assisted-by: Codex:GPT-6 --- .github/workflows/builds.yml | 122 +---------------------------------- .github/workflows/codeql.yml | 80 +++++++++++++++++++++++ 2 files changed, 82 insertions(+), 120 deletions(-) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 4f53ef648..35b518c56 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -1,32 +1,15 @@ name: GitHub Builds -on: - push: - pull_request: - types: [opened, synchronize, reopened, labeled] - schedule: - - cron: '23 4 * * 2' - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: builds-${{ github.event.pull_request.number || github.run_id }}-${{ github.event.action == 'labeled' && github.event.label.name || 'build' }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} +on: [push, pull_request] env: NIX_COMPILE_FLAGS: -Wall -Wextra -pedantic -Werror GNU_COMPILE_FLAGS: -Wall -Wextra -pedantic -Werror -Wformat-signedness MSVC_COMPILE_FLAGS: /W4 /WX - # Branch pushes keep ordinary CI; PR scans are opt-in via ci-codeql. - CODEQL_ENABLED: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/master') || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-codeql')) }} jobs: macos-automake: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}macos-automake - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: macos-latest steps: @@ -50,18 +33,7 @@ jobs: macos-cmake: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}macos-cmake - if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' - # CodeQL traced builds require macOS and Xcode earlier than version 27. - runs-on: macos-15 - timeout-minutes: 30 - permissions: - contents: read - security-events: write - env: - DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer - # Keep arm64 output when CodeQL launches tools through Rosetta. - CMAKE_APPLE_SILICON_PROCESSOR: arm64 + runs-on: macos-latest steps: - uses: actions/checkout@v3 @@ -76,7 +48,6 @@ jobs: cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" cmake -B build/framework -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - name: Build CMake Shared - timeout-minutes: 5 working-directory: build/shared run: make install - name: Build CMake Static @@ -142,37 +113,10 @@ jobs: cd build_meson ninja - - name: Initialize CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/init@v4 - timeout-minutes: 10 - with: - languages: c-cpp - build-mode: manual - source-root: hidapisrc - - name: Build CodeQL - if: env.CODEQL_ENABLED == 'true' - timeout-minutes: 5 - working-directory: build/shared - run: cmake --build . --clean-first --parallel 2 - - name: Analyze CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/analyze@v4 - timeout-minutes: 15 - with: - checkout_path: hidapisrc - category: /language:c-cpp/os:macos - ubuntu-cmake: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}ubuntu-cmake - if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' runs-on: ubuntu-latest - timeout-minutes: 30 - permissions: - contents: read - security-events: write steps: - uses: actions/checkout@v3 @@ -189,7 +133,6 @@ jobs: cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON -DHIDAPI_WITH_TESTS=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}" cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}" - name: Build CMake Shared - timeout-minutes: 5 working-directory: build/shared run: make install - name: Build CMake Static @@ -266,37 +209,10 @@ jobs: cd build_meson ninja - - name: Initialize CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/init@v4 - timeout-minutes: 10 - with: - languages: c-cpp - build-mode: manual - source-root: hidapisrc - - name: Build CodeQL - if: env.CODEQL_ENABLED == 'true' - timeout-minutes: 5 - working-directory: build/shared - run: cmake --build . --clean-first --parallel 2 - - name: Analyze CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/analyze@v4 - timeout-minutes: 15 - with: - checkout_path: hidapisrc - category: /language:c-cpp/os:linux - windows-cmake-msvc: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-cmake-msvc - if: github.event.action != 'labeled' || github.event.label.name == 'ci-codeql' runs-on: windows-latest - timeout-minutes: 30 - permissions: - contents: read - security-events: write steps: - uses: actions/checkout@v3 @@ -317,7 +233,6 @@ jobs: run: | cmake -B build\msvc -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - name: Build CMake MSVC - timeout-minutes: 5 working-directory: build/msvc run: cmake --build . --config RelWithDebInfo --target install - name: Check artifacts CMake MSVC @@ -427,32 +342,9 @@ jobs: cd build_meson ninja - - name: Initialize CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/init@v4 - timeout-minutes: 10 - with: - languages: c-cpp - build-mode: manual - source-root: hidapisrc - - name: Build CodeQL - if: env.CODEQL_ENABLED == 'true' - timeout-minutes: 5 - working-directory: build/msvc - run: cmake --build . --config RelWithDebInfo --clean-first --parallel 2 - - name: Analyze CodeQL - if: env.CODEQL_ENABLED == 'true' - uses: github/codeql-action/analyze@v4 - timeout-minutes: 15 - with: - checkout_path: hidapisrc - category: /language:c-cpp/os:windows - windows-cmake-mingw: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-cmake-mingw - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest steps: @@ -496,8 +388,6 @@ jobs: windows-cygwin: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-cygwin - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest defaults: @@ -556,8 +446,6 @@ jobs: windows-msbuild: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}windows-msbuild - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: windows-latest steps: @@ -596,8 +484,6 @@ jobs: fedora-mingw: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}fedora-mingw - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: fedora:latest steps: @@ -668,8 +554,6 @@ jobs: archlinux: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}archlinux - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: archlinux:latest steps: @@ -744,8 +628,6 @@ jobs: alpine: - name: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'labeled') && 'CodeQL / ' || '' }}alpine - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'labeled') runs-on: ubuntu-latest container: alpine:edge env: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..22d63d7ff --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,80 @@ +name: CodeQL + +on: + push: + branches: [master] + pull_request: + branches: [master] + types: [opened, synchronize, reopened, labeled] + schedule: + - cron: '23 4 * * 2' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: codeql-${{ github.event.pull_request.number || github.run_id }}-${{ github.event.action == 'labeled' && github.event.label.name || 'scan' }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + analyze: + name: CodeQL (${{ matrix.platform }}) + if: >- + github.event_name != 'pull_request' || + (contains(github.event.pull_request.labels.*.name, 'ci-codeql') && + (github.event.action != 'labeled' || github.event.label.name == 'ci-codeql')) + runs-on: ${{ matrix.os }} + timeout-minutes: 20 + permissions: + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + include: + - platform: linux + os: ubuntu-24.04 + generator: Unix Makefiles + - platform: windows + os: windows-latest + generator: NMake Makefiles + - platform: macos + # CodeQL tracing requires macOS and Xcode earlier than version 27. + os: macos-15 + generator: Unix Makefiles + steps: + - uses: actions/checkout@v4 + - name: Install Linux dependencies + if: runner.os == 'Linux' + timeout-minutes: 5 + run: | + sudo apt-get update + sudo apt-get install -y libudev-dev libusb-1.0-0-dev + - name: Set up MSVC + if: runner.os == 'Windows' + uses: TheMrMilchmann/setup-msvc-dev@v4 + with: + arch: x64 + - name: Select macOS toolchain + if: runner.os == 'macOS' + run: | + echo "DEVELOPER_DIR=/Applications/Xcode_16.4.app/Contents/Developer" >> "$GITHUB_ENV" + echo "CMAKE_APPLE_SILICON_PROCESSOR=arm64" >> "$GITHUB_ENV" + - name: Configure + timeout-minutes: 5 + run: cmake -S . -B build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE=Release -DHIDAPI_WITH_TESTS=OFF -DHIDAPI_BUILD_HIDTEST=OFF + - name: Initialize CodeQL + uses: github/codeql-action/init@v4 + timeout-minutes: 5 + with: + languages: c-cpp + build-mode: manual + - name: Build + timeout-minutes: 5 + run: cmake --build build --config Release + - name: Analyze CodeQL + uses: github/codeql-action/analyze@v4 + timeout-minutes: 10 + with: + category: /language:c-cpp/os:${{ matrix.platform }} From 5632f81d5dcb24ba60a524fcfa4ea4cad327cf23 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 16 Nov 2026 01:28:08 +0200 Subject: [PATCH 6/7] ci: deduplicate eligible CodeQL jobs per pull request Apply concurrency after the job's label gate so skipped label events cannot cancel a scan, while opened and labelled events share one scan. Assisted-by: Codex:GPT-6 --- .github/workflows/codeql.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 22d63d7ff..a58197a9c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,10 +13,6 @@ on: permissions: contents: read -concurrency: - group: codeql-${{ github.event.pull_request.number || github.run_id }}-${{ github.event.action == 'labeled' && github.event.label.name || 'scan' }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - jobs: analyze: name: CodeQL (${{ matrix.platform }}) @@ -25,6 +21,9 @@ jobs: (contains(github.event.pull_request.labels.*.name, 'ci-codeql') && (github.event.action != 'labeled' || github.event.label.name == 'ci-codeql')) runs-on: ${{ matrix.os }} + concurrency: + group: codeql-${{ matrix.platform }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} timeout-minutes: 20 permissions: contents: read From 1e5de396031a4cd864f3f1ef771ff7fece847573 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 16 Nov 2026 01:38:29 +0200 Subject: [PATCH 7/7] ci: use current actions and configure full CodeQL extraction Use checkout v7 while retaining current major tags for CodeQL and MSVC setup. Disable unsupported overlays for manual C/C++ builds and enable the JNI native access used by CodeQL's Windows path resolver. Assisted-by: Codex:GPT-6 --- .github/workflows/codeql.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a58197a9c..4daefc0c5 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -28,6 +28,11 @@ jobs: permissions: contents: read security-events: write + env: + # Manual C/C++ builds require a full database rather than an overlay. + CODEQL_OVERLAY_DATABASE_MODE: none + # CodeQL's Windows path resolver loads a JNI native library. + JDK_JAVA_OPTIONS: --enable-native-access=ALL-UNNAMED strategy: fail-fast: false matrix: @@ -43,7 +48,7 @@ jobs: os: macos-15 generator: Unix Makefiles steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Install Linux dependencies if: runner.os == 'Linux' timeout-minutes: 5