-
Notifications
You must be signed in to change notification settings - Fork 0
Improve conan package caching in CI #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
nikobockerman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 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##*-} | ||
nikobockerman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if [[ "${packagesHash}" != "${matchedKeyPackagesHash}" ]]; then | ||
| saveCache=true | ||
| else | ||
| saveCache=false | ||
nikobockerman marked this conversation as resolved.
Show resolved
Hide resolved
nikobockerman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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::" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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::" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.