From d84a28dd228e67aed0251acdac352ba245e10a88 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Thu, 30 Jul 2026 05:14:01 -0400 Subject: [PATCH] Replace CMake CI build/test with lukka/run-cmake Add lukka/get-cmake to get CMake and Ninja Add hendrikmuhs/ccache-action to use ccache with run-cmake Add Github action build caching back via ccache --- .github/actions/openvic-dl-build/action.yml | 97 ++++++++++++++------- .github/workflows/releases.yml | 1 + 2 files changed, 66 insertions(+), 32 deletions(-) diff --git a/.github/actions/openvic-dl-build/action.yml b/.github/actions/openvic-dl-build/action.yml index 2fa9dd2..bbd500e 100644 --- a/.github/actions/openvic-dl-build/action.yml +++ b/.github/actions/openvic-dl-build/action.yml @@ -22,10 +22,25 @@ inputs: run-tests: description: Whether to run the unit tests after building default: 'true' + enable-cache: + description: Whether to enable the cache for building + default: 'true' runs: using: composite steps: + - name: Install ccache and restore cache + if: inputs.enable-cache == 'true' + uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 + with: + # Disables sporadic job summary behavior + job-summary: + append-timestamp: false + key: ${{ inputs.identifier }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ inputs.identifier }}-${{ github.ref }} + ${{ inputs.identifier }} + - name: Setup MSVC environment if: ${{ runner.os == 'Windows' }} shell: pwsh @@ -36,21 +51,8 @@ runs: Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64' Get-ChildItem env: | ForEach-Object { Add-Content -Path $env:GITHUB_ENV -Value "$($_.Name)=$($_.Value)" } - - name: Setup Ninja - shell: bash - run: | - # Ninja is preinstalled on GitHub-hosted images; fall back to the - # image's package manager if a future image drops it. - if ! command -v ninja >/dev/null 2>&1; then - if [ "$RUNNER_OS" = "macOS" ]; then - brew install ninja - elif [ "$RUNNER_OS" = "Windows" ]; then - choco install ninja -y - else - sudo apt-get update -y && sudo apt-get install -y ninja-build - fi - fi - ninja --version + - name: Get CMake and Ninja + uses: lukka/get-cmake@e6906078ebd1ccb8ce51ab4626ac46a1b5a517e3 # v4.4.0 - name: Install APT dependencies if: ${{ runner.os == 'Linux' }} @@ -70,26 +72,57 @@ runs: sudo update-alternatives --set g++ /usr/bin/g++-13 g++ --version - - name: Configure - shell: bash - run: | - cmake --preset ${{ inputs.preset }} \ - -DGODOTCPP_TARGET=${{ inputs.target }} \ - -DOPENVIC_DATALOADER_COMPLIANCE=${{ inputs.compliance-type }} \ - ${{ inputs.cmake-args }} - - name: Build - shell: bash - run: | - CONFIG_LOWER=$(echo "${{ inputs.configuration }}" | tr '[:upper:]' '[:lower:]') - cmake --build --preset ${{ inputs.preset }}-$CONFIG_LOWER + uses: lukka/run-cmake@5d55ea7949e25f69f0ecb516d8d572297e03a956 # v10.9 + if: ${{ inputs.run-tests != 'true' }} + env: + INPUTS_CONFIGURATION: ${{ inputs.configuration }} + INPUTS_TARGET: ${{ inputs.target }} + INPUTS_COMPLIANCE_TYPE: ${{ inputs.compliance-type }} + INPUTS_CMAKE_ARGS: ${{ inputs.cmake-args }} + INPUTS_ENABLE_CACHE: ${{ inputs.enable-cache }} + # Disables vcpkg on Windows + VCPKG_ROOT: + with: + configurePreset: ${{ inputs.preset }} + buildPreset: ${{ inputs.preset }} + # Arguments are evaluated by Javascript's eval function + configurePresetAdditionalArgs: | + [ + `-DGODOTCPP_TARGET=$[env.INPUTS_TARGET]`, + `-DOPENVIC_DATALOADER_COMPLIANCE=$[env.INPUTS_COMPLIANCE_TYPE]`, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_C_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] && `$[env.RUNNER_OS]` == 'Windows' ? `-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=$<$:Embedded>` : `` + ].concat(`$[env.INPUTS_CMAKE_ARGS]`.split(/\s+/)).filter((v) => v.length > 0) + buildPresetCmdString: "[`--build`, `--preset`, `$[env.BUILD_PRESET_NAME]-` + `$[env.INPUTS_CONFIGURATION]`.toLowerCase()]" - - name: Run tests + - name: Build and Test + uses: lukka/run-cmake@5d55ea7949e25f69f0ecb516d8d572297e03a956 # v10.9 if: ${{ inputs.run-tests == 'true' }} - shell: bash - run: | - CONFIG_LOWER=$(echo "${{ inputs.configuration }}" | tr '[:upper:]' '[:lower:]') - ctest --preset ${{ inputs.preset }}-$CONFIG_LOWER + env: + INPUTS_CONFIGURATION: ${{ inputs.configuration }} + INPUTS_TARGET: ${{ inputs.target }} + INPUTS_COMPLIANCE_TYPE: ${{ inputs.compliance-type }} + INPUTS_CMAKE_ARGS: ${{ inputs.cmake-args }} + INPUTS_ENABLE_CACHE: ${{ inputs.enable-cache }} + # Disables vcpkg on Windows + VCPKG_ROOT: + with: + configurePreset: ${{ inputs.preset }} + buildPreset: ${{ inputs.preset }} + testPreset: ${{ inputs.preset }} + # Arguments are evaluated by Javascript's eval function + configurePresetAdditionalArgs: | + [ + `-DGODOTCPP_TARGET=$[env.INPUTS_TARGET]`, + `-DOPENVIC_DATALOADER_COMPLIANCE=$[env.INPUTS_COMPLIANCE_TYPE]`, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_C_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] && `$[env.RUNNER_OS]` == 'Windows' ? `-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=$<$:Embedded>` : `` + ].concat(`$[env.INPUTS_CMAKE_ARGS]`.split(/\s+/)).filter((v) => v.length > 0) + buildPresetCmdString: "[`--build`, `--preset`, `$[env.BUILD_PRESET_NAME]-` + `$[env.INPUTS_CONFIGURATION]`.toLowerCase()]" + testPresetCmdString: "[`--preset`, `$[env.BUILD_PRESET_NAME]-` + `$[env.INPUTS_CONFIGURATION]`.toLowerCase()]" - name: Upload library artifact uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 49e96c7..561cb1d 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -91,6 +91,7 @@ jobs: target: template_release run-tests: false cmake-args: -DOPENVIC_DL_BUILD_TESTS=OFF ${{ matrix.cmake-args }} + enable-cache: false publish-release: name: Publish Release