Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/actions/cmake-project-finalize/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CMake project finalize
description: Finalize conan packages in cache
inputs:
conan-cache-key-prefix:
description: Prefix for the conan cache key
required: true
conan-cache-matched-key:
description: Matched cache used to restore conan cache
required: true

runs:
using: composite
steps:
- env:
CONAN_CACHE_MATCHED_KEY: ${{ inputs.conan-cache-matched-key }}
id: init
run: |
# Initialize cmake-project-finalize action
"${GITHUB_ACTION_PATH}/init.sh"
shell: bash

- if: steps.init.outputs.save-cache == 'true'
name: Cache Conan packages
uses: actions/cache/save@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
key: ${{ inputs.conan-cache-key-prefix }}-${{ hashFiles('solvers/cpp/conan.lock') }}-${{ steps.init.outputs.packages-hash }}
path: ${{ steps.init.outputs.conan-cache-path }}
59 changes: 59 additions & 0 deletions .github/actions/cmake-project-finalize/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -euo pipefail

# Validate required environment variables
if [[ -z "${CONAN_HOME}" ]]; then
echo "::error::CONAN_HOME is not set"
exit 1
fi

pushd solvers/cpp

echo "::group::List existing recipes and binaries"
conan list --cache '*/*#*:*' -f=compact
echo "::endgroup::"

# Remove all recipes that have not been used in the last 1 hour
# (with their binaries). In practice, this will remove all recipes that have
# not been used in the last build.
echo "::group::Remove unused recipes and binaries"
conan remove "*" --lru=1h --confirm
echo "::endgroup::"

# Remove all binaries (but not recipes) not used in the last 1 hour
echo "::group::Remove unused binaries"
conan remove "*:*" --lru=1h --confirm
echo "::endgroup::"

# Remove non-critical folders from the cache for the remaining recipes
echo "::group::Remove non-critical folders from the cache"
conan cache clean
echo "::endgroup::"

# Generate file about existing recipes and binaries

echo "::group::List remaining recipes and binaries"
conan list --cache '*/*#*:*' -f=compact | tee "${RUNNER_TEMP}/existing_packages.txt"
echo "::endgroup::"

packagesHash=$(sha256sum "${RUNNER_TEMP}/existing_packages.txt" | cut -d ' ' -f 1)

popd

matchedKeyPackagesHash=${CONAN_CACHE_MATCHED_KEY##*-}

if [[ "${packagesHash}" != "${matchedKeyPackagesHash}" ]]; then
saveCache=true
else
saveCache=false
fi


echo "::group::Outputs from init"
{
echo "conan-cache-path=${CONAN_HOME}/p"
echo "packages-hash=${packagesHash}"
echo "save-cache=${saveCache}"
} | tee -a "${GITHUB_OUTPUT}"
echo "::endgroup::"
32 changes: 26 additions & 6 deletions .github/actions/cmake-project-setup/action.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
name: CMake project setup
description: Setup cmake, conan and CMakeUserPresets.json
inputs:
conan-cache-key-prefix:
description: Prefix for the conan cache key
required: true
outputs:
conan-cache-matched-key:
description: Cache restore key used to restore Conan packages
value: ${{ steps.cache-conan-packages.outputs.cache-matched-key }}

runs:
using: composite
steps:
- id: init
run: |
# Initialize cmake-project-setup action
"${GITHUB_ACTION_PATH}/init.sh"
shell: bash

- id: cache-conan-packages
name: Restore Conan packages cache
uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
# Use an intentionally non-matching suffix so that restores only use the prefixes below.
# The full key is only used when saving a new cache entry.
key: ${{ inputs.conan-cache-key-prefix }}-${{ hashFiles('solvers/cpp/conan.lock') }}-partial-match-only
path: ${{ steps.init.outputs.conan-cache-path }}
restore-keys: |
${{ inputs.conan-cache-key-prefix }}-${{ hashFiles('solvers/cpp/conan.lock') }}-
${{ inputs.conan-cache-key-prefix }}-

- name: Install CMake
# TODO: Install cmake through mise
uses: lukka/get-cmake@9e07ecdcee1b12e5037e42f410b67f03e2f626e1 # v4.2.1

- name: Setup Conan Client
# TODO: Setup only conan package cache here and use conan through mise
uses: conan-io/setup-conan@2f4bd34e8e0af00e1a77a66e1d284e06d71d703f # v1.3.0
with:
cache_packages: true

- name: Prepare files
run: |
cp .github/files/CMakeUserPresets.json solvers/cpp/
Expand Down
27 changes: 27 additions & 0 deletions .github/actions/cmake-project-setup/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -euo pipefail

conanHome=${RUNNER_TEMP}/aoc-conan-home

export CONAN_HOME="${conanHome}"

echo "::group::Detect Conan profile"
pushd solvers/cpp
conan profile detect
popd
echo "::endgroup::"

echo "::group::Environment variable changes"
{
echo -n "CONAN_HOME="
echo "${conanHome}" | tr -d '\n'
echo
} | tee -a "${GITHUB_ENV}"
echo "::endgroup::"

echo "::group::Outputs from init"
{
echo "conan-cache-path=${conanHome}/p"
} | tee -a "${GITHUB_OUTPUT}"
echo "::endgroup::"
21 changes: 15 additions & 6 deletions .github/workflows/cpp-build-test-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ jobs:
cache-mode: use
downloads-hash-from-prepare: ${{ matrix.homebrew-downloads-hash-from-prepare }}

- name: Setup CMake project
- name: Setup tools through mise
uses: ./.github/actions/mise-project-setup
with:
directory: solvers/cpp

- id: setup-cmake-project
name: Setup CMake project
uses: ./.github/actions/cmake-project-setup
with:
conan-cache-key-prefix: conan-${{ steps.preset-name.outputs.name }}

- if: matrix.os == 'ubuntu'
name: Specify HOMEBREW_PREFIX
Expand All @@ -85,11 +93,6 @@ jobs:
cmakeListsTxtPath: solvers/cpp/CMakeLists.txt
workflowPreset: ${{ steps.preset-name.outputs.name }}

- name: Restore aoc-main mise project
uses: ./.github/actions/mise-project-setup
with:
directory: aoc-main

- name: Restore aoc-main uv project
uses: ./.github/actions/uv-project-setup
with:
Expand All @@ -100,3 +103,9 @@ jobs:
AOC_CPP_SKIP_PREPARE: "1"
AOC_CPP_WORKFLOW_PRESET: ${{ steps.preset-name.outputs.name }}
run: mise run aoc:all -- --solver cpp -vv

- name: Finalize cmake project
uses: ./.github/actions/cmake-project-finalize
with:
conan-cache-key-prefix: conan-${{ steps.preset-name.outputs.name }}
conan-cache-matched-key: ${{ steps.setup-cmake-project.outputs.conan-cache-matched-key }}
Loading