From e1aa3e8a9e26024a8d8a6a1ac4a9a000b01766a4 Mon Sep 17 00:00:00 2001 From: pifopi Date: Sun, 25 Jan 2026 22:30:17 +0100 Subject: [PATCH] Rework CI and add clang query --- .../workflows/cpp-ci-serial-programs-base.yml | 144 ++++++++++++++++++ .../cpp-ci-serial-programs-mac-intel.yml | 9 ++ .../workflows/cpp-ci-serial-programs-mac.yml | 9 ++ .../cpp-ci-serial-programs-ubuntu-clang.yml | 10 ++ .../cpp-ci-serial-programs-ubuntu-default.yml | 10 ++ .../cpp-ci-serial-programs-windows-clang.yml | 11 ++ ...cpp-ci-serial-programs-windows-default.yml | 11 ++ .github/workflows/cpp-ci-serial-programs.yml | 91 ----------- 8 files changed, 204 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/cpp-ci-serial-programs-base.yml create mode 100644 .github/workflows/cpp-ci-serial-programs-mac-intel.yml create mode 100644 .github/workflows/cpp-ci-serial-programs-mac.yml create mode 100644 .github/workflows/cpp-ci-serial-programs-ubuntu-clang.yml create mode 100644 .github/workflows/cpp-ci-serial-programs-ubuntu-default.yml create mode 100644 .github/workflows/cpp-ci-serial-programs-windows-clang.yml create mode 100644 .github/workflows/cpp-ci-serial-programs-windows-default.yml delete mode 100644 .github/workflows/cpp-ci-serial-programs.yml diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml new file mode 100644 index 000000000..2bbd11a48 --- /dev/null +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -0,0 +1,144 @@ +name: C++ CI Serial Programs base +on: + workflow_call: + inputs: + os: + required: true + type: string + + compiler: + required: true + type: string + + upload-build: + type: boolean + default: false + + run-tests: + type: boolean + default: false + + run-clang-query: + type: boolean + default: false + +jobs: + build: + runs-on: ${{inputs.os}} + + steps: + - name: Set variables + shell: bash + run: | + if [[ "${{inputs.compiler}}" == "clang" ]]; then + if [[ "${{inputs.os}}" == windows* ]]; then + CMAKE_ADDITIONAL_FLAGS="-T ClangCL" + elif [[ "${{inputs.os}}" == ubuntu* ]]; then + CMAKE_ADDITIONAL_FLAGS="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" + fi + fi + echo "CMAKE_ADDITIONAL_FLAGS=$CMAKE_ADDITIONAL_FLAGS" >> $GITHUB_ENV + + if [[ "${{inputs.os}}" == "windows*" ]]; then + UPLOAD_FOLDER="Arduino-Source/SerialPrograms/bin/RelWithDebInfo" + else + UPLOAD_FOLDER="Arduino-Source/SerialPrograms/bin" + fi + echo "UPLOAD_FOLDER=$UPLOAD_FOLDER" >> $GITHUB_ENV + + - name: Checkout Arduino-Source + uses: actions/checkout@v6 + with: + path: 'Arduino-Source' + submodules: 'recursive' + + - name: Install Qt + uses: jurplel/install-qt-action@v4 + with: + version: '6.10.1' + modules: 'qtmultimedia qtserialport' + + - name: Install dependencies (Ubuntu) + if: startsWith(inputs.os, 'ubuntu') + run: | + cd Arduino-Source + sudo apt update + sudo apt upgrade + sudo apt install clang-tools libopencv-dev + + sudo apt install ./3rdPartyBinaries/libdpp-10.0.28-linux-x64.deb + + - name: Install dependencies (Mac) + if: startsWith(inputs.os, 'mac') + run: | + cd Arduino-Source + brew install opencv onnxruntime + + brew tap-new --no-git PA/libdpp + FORMULA_DIR="$(brew --repo PA/libdpp)/Formula" + mkdir -p "$FORMULA_DIR" + cp 3rdPartyBinaries/libdpp@10.0.28.rb "$FORMULA_DIR/" + brew install libdpp@10.0.28 + + - name: Generate binaries + run: | + cd Arduino-Source/SerialPrograms + mkdir bin + cd bin + cmake .. -DQT_MAJOR:STRING=6 ${{env.CMAKE_ADDITIONAL_FLAGS}} + cmake --build . --config RelWithDebInfo --parallel 10 + + - name: Prepare upload build + if: inputs.upload-build + shell: bash + run: | + echo https://github.com/${{github.repository}}/commit/${{github.sha}} > ${{env.UPLOAD_FOLDER}}/version.txt + + - name: Upload Build + uses: actions/upload-artifact@v6 + if: inputs.upload-build + with: + name: Serial Programs (os=${{inputs.os}} - compiler=${{inputs.compiler}}) + path: ${{env.UPLOAD_FOLDER}} + + - name: Checkout CommandLineTests + uses: actions/checkout@v6 + if: inputs.run-tests + with: + repository: 'PokemonAutomation/CommandLineTests' + path: 'CommandLineTests' + + - name: Run tests (Windows) + if: startsWith(inputs.os, 'windows') && inputs.run-tests + run: | + cd Arduino-Source/SerialPrograms/bin + $env:DISCORD_BOT_TOKEN = "Value" + $process = Start-Process -FilePath "./RelWithDebInfo/SerialPrograms.exe" ` + -ArgumentList "--command-line-test-mode --command-line-test-folder ../../../CommandLineTests" ` + -NoNewWindow -Wait -PassThru + if ($process.ExitCode -ne 0) { + Write-Error "Tests failed with exit code $($process.ExitCode)" + exit 1 + } + + - name: Run clang query + if: inputs.run-clang-query + run : | + cd Arduino-Source + + cat << 'EOF' > query.txt + set output dump + match invocation( + isExpansionInFileMatching("SerialPrograms/"), + hasDeclaration(cxxConstructorDecl(ofClass(hasName("std::filesystem::path")))), + hasArgument(0, hasType(asString("std::string"))) + ) + EOF + + files=$(jq -r '.[].file' SerialPrograms/bin/compile_commands.json) + echo "$files" | xargs --max-args=150 clang-query -p SerialPrograms/bin/ -f query.txt >> output.txt + cat output.txt + if grep --silent "Match #" output.txt; then + echo "::error Forbidden std::filesystem::path construction detected!" + exit 1 + fi diff --git a/.github/workflows/cpp-ci-serial-programs-mac-intel.yml b/.github/workflows/cpp-ci-serial-programs-mac-intel.yml new file mode 100644 index 000000000..1e2b07f6a --- /dev/null +++ b/.github/workflows/cpp-ci-serial-programs-mac-intel.yml @@ -0,0 +1,9 @@ +name: C++ CI Serial Programs Mac Intel +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + uses: ./.github/workflows/cpp-ci-serial-programs-base.yml + with: + os: macos-15-intel + compiler: default \ No newline at end of file diff --git a/.github/workflows/cpp-ci-serial-programs-mac.yml b/.github/workflows/cpp-ci-serial-programs-mac.yml new file mode 100644 index 000000000..807d0eea5 --- /dev/null +++ b/.github/workflows/cpp-ci-serial-programs-mac.yml @@ -0,0 +1,9 @@ +name: C++ CI Serial Programs Mac +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + uses: ./.github/workflows/cpp-ci-serial-programs-base.yml + with: + os: macos-15 + compiler: default \ No newline at end of file diff --git a/.github/workflows/cpp-ci-serial-programs-ubuntu-clang.yml b/.github/workflows/cpp-ci-serial-programs-ubuntu-clang.yml new file mode 100644 index 000000000..59ceed9de --- /dev/null +++ b/.github/workflows/cpp-ci-serial-programs-ubuntu-clang.yml @@ -0,0 +1,10 @@ +name: C++ CI Serial Programs Ubuntu clang +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + uses: ./.github/workflows/cpp-ci-serial-programs-base.yml + with: + os: ubuntu-24.04 + compiler: clang + run-clang-query: true \ No newline at end of file diff --git a/.github/workflows/cpp-ci-serial-programs-ubuntu-default.yml b/.github/workflows/cpp-ci-serial-programs-ubuntu-default.yml new file mode 100644 index 000000000..5c4a9b2fc --- /dev/null +++ b/.github/workflows/cpp-ci-serial-programs-ubuntu-default.yml @@ -0,0 +1,10 @@ +name: C++ CI Serial Programs Ubuntu Default +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + uses: ./.github/workflows/cpp-ci-serial-programs-base.yml + with: + os: ubuntu-24.04 + compiler: default + run-clang-query: true \ No newline at end of file diff --git a/.github/workflows/cpp-ci-serial-programs-windows-clang.yml b/.github/workflows/cpp-ci-serial-programs-windows-clang.yml new file mode 100644 index 000000000..7c616ff1a --- /dev/null +++ b/.github/workflows/cpp-ci-serial-programs-windows-clang.yml @@ -0,0 +1,11 @@ +name: C++ CI Serial Programs Windows Clang +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + uses: ./.github/workflows/cpp-ci-serial-programs-base.yml + with: + os: windows-2025 + compiler: clang + upload-build: true + run-tests: true \ No newline at end of file diff --git a/.github/workflows/cpp-ci-serial-programs-windows-default.yml b/.github/workflows/cpp-ci-serial-programs-windows-default.yml new file mode 100644 index 000000000..4e835a3f9 --- /dev/null +++ b/.github/workflows/cpp-ci-serial-programs-windows-default.yml @@ -0,0 +1,11 @@ +name: C++ CI Serial Programs Windows Default +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + uses: ./.github/workflows/cpp-ci-serial-programs-base.yml + with: + os: windows-2025 + compiler: default + upload-build: true + run-tests: true \ No newline at end of file diff --git a/.github/workflows/cpp-ci-serial-programs.yml b/.github/workflows/cpp-ci-serial-programs.yml deleted file mode 100644 index 140bc1362..000000000 --- a/.github/workflows/cpp-ci-serial-programs.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: C++ CI Serial Programs - -on: [push, pull_request, workflow_dispatch] - -jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - os: [windows-2025, macos-15, macos-15-intel, ubuntu-24.04] - compiler: ['default', 'clang'] - qt_version: ['6.10.1'] - include: - - qt_version: '6.10.1' - qt_version_major: '6' - qt_modules: 'qtmultimedia qtserialport' - - - os: 'windows-2025' - compiler: 'clang' - cmake_additional_param: '-T ClangCL' - - - os: 'ubuntu-24.04' - compiler: 'clang' - cmake_additional_param: '-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++' - - exclude: - - os: 'macos-15' - compiler: 'clang' - - os: 'macos-15-intel' - compiler: 'clang' - # Excluded because macos default toolset is already clang - - steps: - - uses: actions/checkout@v6 - with: - path: 'Arduino-Source' - submodules: 'recursive' - - uses: actions/checkout@v6 - with: - repository: 'PokemonAutomation/CommandLineTests' - path: 'CommandLineTests' - - uses: jurplel/install-qt-action@v4 - with: - version: ${{ matrix.qt_version }} - modules: ${{ matrix.qt_modules }} - - name: Install dependencies - if: startsWith(matrix.os, 'ubuntu') - run: | - sudo apt update - sudo apt upgrade - sudo apt install libopencv-dev - sudo apt install ./Arduino-Source/3rdPartyBinaries/libdpp-10.0.28-linux-x64.deb - - name: Install dependencies - if: startsWith(matrix.os, 'mac') - run: | - brew install opencv onnxruntime - brew tap-new --no-git PA/libdpp - FORMULA_DIR="$(brew --repo PA/libdpp)/Formula" - mkdir -p "$FORMULA_DIR" - cp Arduino-Source/3rdPartyBinaries/libdpp@10.0.28.rb "$FORMULA_DIR/" - brew install libdpp@10.0.28 - - name: Generate binaries - run: | - cd Arduino-Source/SerialPrograms - mkdir bin - cd bin - cmake .. -DQT_MAJOR:STRING=${{ matrix.qt_version_major }} ${{ matrix.cmake_additional_param }} - cmake --build . --config RelWithDebInfo --parallel 10 - - name: Prepare upload folder - if: startsWith(matrix.os, 'windows') - run: | - cd Arduino-Source - echo https://github.com/${{github.repository}}/commit/${{github.sha}} > SerialPrograms/bin/RelWithDebInfo/version.txt - - uses: actions/upload-artifact@v6 - if: startsWith(matrix.os, 'windows') - with: - name: Serial Programs (os=${{ matrix.os }} - compiler=${{ matrix.compiler }} - qt_version=${{ matrix.qt_version }}) - path: Arduino-Source/SerialPrograms/bin/RelWithDebInfo - - name: Run tests - if: startsWith(matrix.os, 'windows') - run: | - cd Arduino-Source/SerialPrograms/bin - $process = Start-Process -FilePath "./RelWithDebInfo/SerialPrograms.exe" ` - -ArgumentList "--command-line-test-mode --command-line-test-folder ../../../CommandLineTests" ` - -NoNewWindow -Wait -PassThru - if ($process.ExitCode -ne 0) { - Write-Error "Tests failed with exit code $($process.ExitCode)" - exit 1 - }