From ecea471bfc5f6f0f9e151c0ba28169c1e5277ac9 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Thu, 30 Jul 2026 10:17:10 -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-build/action.yml | 66 ++++++++++++++---------- .github/workflows/nightly-releases.yml | 1 + .github/workflows/releases.yml | 1 + 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.github/actions/openvic-build/action.yml b/.github/actions/openvic-build/action.yml index f368d595..95d15787 100644 --- a/.github/actions/openvic-build/action.yml +++ b/.github/actions/openvic-build/action.yml @@ -19,10 +19,26 @@ inputs: release-name: description: Name of release default: '' + 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: + max-size: "2GB" + 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 @@ -33,21 +49,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' }} @@ -67,21 +70,32 @@ runs: sudo update-alternatives --set g++ /usr/bin/g++-13 g++ --version - - name: Configure - shell: bash + # A post-build step copies the extension library into game/bin/openvic, so + # the artifact path below is populated by this step alone. + - name: Build + uses: lukka/run-cmake@5d55ea7949e25f69f0ecb516d8d572297e03a956 # v10.9 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: # Baked into the commit-info header at configure time. OPENVIC_TAG: ${{ inputs.tag-name }} OPENVIC_RELEASE: ${{ inputs.release-name }} - run: | - cmake --preset ${{ inputs.preset }} \ - ${{ inputs.cmake-args }} - - # A post-build step copies the extension library into game/bin/openvic, so - # the artifact path below is populated by this step alone. - - name: Build - shell: bash - run: cmake --build out/build/${{ inputs.preset }} --config ${{ inputs.configuration }} + with: + configurePreset: ${{ inputs.preset }} + buildPreset: ${{ inputs.preset }} + # Arguments are evaluated by Javascript's eval function + configurePresetAdditionalArgs: | + [ + $[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`, `out/build/$[env.BUILD_PRESET_NAME]`, `--config`, `$[env.INPUTS_CONFIGURATION]`]" - name: Upload extension artifact uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 diff --git a/.github/workflows/nightly-releases.yml b/.github/workflows/nightly-releases.yml index af3c6695..cf4bbf1c 100644 --- a/.github/workflows/nightly-releases.yml +++ b/.github/workflows/nightly-releases.yml @@ -272,6 +272,7 @@ jobs: configuration: ${{ matrix.configuration }} tag-name: ${{ needs.nightly-check.outputs.tag-name }} cmake-args: ${{ matrix.cmake-args }} + enable-cache: false publish-nightly-release: name: Publish Release diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 6a37a961..0dc20936 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -134,6 +134,7 @@ jobs: tag-name: ${{ github.ref_name }} release-name: ${{ needs.static-checks-release.outputs.release-name }} cmake-args: ${{ matrix.cmake-args }} + enable-cache: false publish-release: name: Publish Release