From 8656beccceca636fc049fff51df8d4834ea532d8 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 13:10:30 +0800 Subject: [PATCH] Refactor CMake multi-platform workflow Updated the GitHub Actions workflow to improve clarity and structure, including separate steps for setting the compiler and configuring for Linux and Windows. --- .github/workflows/cmake-multi-platform.yml | 139 ++++++++++++--------- 1 file changed, 80 insertions(+), 59 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 81d4ebc..0ec3211 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -2,9 +2,11 @@ name: CMake on multiple platforms on: push: - branches: [ "main", "master" ] + branches: + - master + - main + pull_request: - branches: [ "master" ] jobs: @@ -33,65 +35,84 @@ jobs: steps: - - uses: actions/checkout@v4 - - #################################################### - # Ubuntu - #################################################### - - - name: Install Linux dependencies - if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y \ - default-libmysqlclient-dev \ - pkg-config - - #################################################### - # Windows - #################################################### - - - name: Install MySQL via vcpkg - if: runner.os == 'Windows' - run: | - git clone https://github.com/microsoft/vcpkg.git - ./vcpkg/bootstrap-vcpkg.bat - ./vcpkg/vcpkg install libmysql:x64-windows - - - name: Show installed packages - if: runner.os == 'Windows' - run: | - dir vcpkg\installed\x64-windows\share - - #################################################### - # Configure - #################################################### - - - name: Configure - env: - CC: ${{ matrix.cc }} - CXX: ${{ matrix.cxx }} - run: | - if [ "${{ runner.os }}" = "Windows" ]; then - cmake -B build \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake - else - cmake -B build \ + ################################################### + # Checkout + ################################################### + + - uses: actions/checkout@v4 + + ################################################### + # Linux dependencies + ################################################### + + - name: Install Linux dependencies + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y \ + default-libmysqlclient-dev \ + pkg-config + + ################################################### + # Setup compiler (Linux) + ################################################### + + - name: Set compiler + if: runner.os == 'Linux' + run: | + echo "CC={{ matrix.cc }}" >> {{ matrix.cc }}" >> GITHUB_ENV + echo "CXX={{ matrix.cxx }}" >> {{ matrix.cxx }}" >> GITHUB_ENV + + ################################################### + # Setup vcpkg (Windows) + ################################################### + + - name: Setup vcpkg + if: runner.os == 'Windows' + uses: lukka/run-vcpkg@v11 + + ################################################### + # Install MySQL (Windows) + ################################################### + + - name: Install MySQL + if: runner.os == 'Windows' + run: | + vcpkg install libmysql:x64-windows + + ################################################### + # Configure Linux + ################################################### + + - name: Configure Linux + if: runner.os == 'Linux' + run: | + cmake \ + -B build \ -DCMAKE_BUILD_TYPE=Release - fi - shell: bash - #################################################### - # Build - #################################################### + ################################################### + # Configure Windows + ################################################### + + - name: Configure Windows + if: runner.os == 'Windows' + run: | + cmake ` + -B build ` + -DCMAKE_BUILD_TYPE=Release ` + -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" + + ################################################### + # Build + ################################################### - - name: Build - run: cmake --build build --config Release + - name: Build + run: cmake --build build --config Release - #################################################### - # Test - #################################################### + ################################################### + # Test + ################################################### - - name: Test - run: ctest --test-dir build --build-config Release + - name: Test + run: ctest --test-dir build --build-config Release