-
Notifications
You must be signed in to change notification settings - Fork 298
Improvements to GitHub Actions package caching #6803
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
Open
trexfeathers
wants to merge
13
commits into
SciTools:main
Choose a base branch
from
trexfeathers:better-gha-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7933a3e
Created persist-dir-cache.
trexfeathers e7b2fdf
Refactor conda-pkg-cache.
trexfeathers 4ae11cd
More sensible Conda caching in all workflows.
trexfeathers 49fdf42
Include missing shell keys.
trexfeathers 0d55c06
New approach that is Python specific and copes with unavailable post:…
trexfeathers 40a0f52
Use Python version as key_suffix.
trexfeathers 2d18e46
Minor corrections.
trexfeathers d286c76
Fix CACHE_BUILD and CACHE_WEEKS handling.
trexfeathers 210f953
More fixes for CACHE_WEEKS.
trexfeathers fea533a
Work around actions/runner#2009 .
trexfeathers 8e3ffc7
More traditional hashing solution.
trexfeathers 1f0a113
Fix typo.
trexfeathers 45dc273
Dummy commit to demonstrate Conda package caching.
trexfeathers 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
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
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,22 +1,42 @@ | ||
| name: "conda-pkg-cache" | ||
| description: "cache the conda environment packages" | ||
| description: "standardise conda package cache to ~/conda_pkgs_dir and cache across workflow runs" | ||
|
|
||
| inputs: | ||
| cache_build: | ||
| description: "conda environment cache build number" | ||
| python_version: | ||
| description: "conda package cache python version" | ||
| required: false | ||
| default: "0" | ||
| cache_period: | ||
| description: "conda environment cache timestamp" | ||
| required: true | ||
| env_name: | ||
| description: "environment name" | ||
| required: true | ||
| default: "3.13" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - uses: actions/cache@v4 | ||
| - id: set-cache-period | ||
| shell: bash | ||
| env: | ||
| # Maximum cache period (in weeks) before forcing a cache refresh.. | ||
| CACHE_WEEKS: 2 | ||
| run: echo "CACHE_PERIOD=$(date +%Y).$(expr $(date +%U) / ${CACHE_WEEKS})" >> $GITHUB_OUTPUT | ||
|
|
||
| - id: define-cache-key | ||
| shell: bash | ||
| env: | ||
| # Lets us manually bump the cache to rebuild. | ||
| CACHE_BUILD: "0" | ||
| run: | | ||
| OS="${{ runner.os }}" | ||
| PERIOD="${{ steps.set-cache-period.outputs.CACHE_PERIOD }}" | ||
| BUILD="${{ env.CACHE_BUILD }}" | ||
| PY="${{ inputs.python_version }}" | ||
| REQ="${{ hashFiles('requirements/locks/**') }}" | ||
| CACHE_KEY="conda_pkgs_dir-${OS}-p${PERIOD}-b${BUILD}-py${PY}-${REQ}" | ||
| echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_ENV | ||
|
|
||
| - id: set-pkg-dir | ||
| shell: bash | ||
| run: conda config --add pkgs_dirs ~/conda_pkgs_dir | ||
|
|
||
| - id: conda-pkg-cache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/conda_pkgs_dir | ||
| key: ${{ runner.os }}-conda-pkgs-${{ inputs.env_name }}-p${{ inputs.cache_period }}-b${{ inputs.cache_build }} | ||
| key: ${{ env.CACHE_KEY }} |
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could stand some improvement. The
wheelsjob always finishes first and populates the cache. When thetestsjob - this one - finishes, it does not overwrite the cache. For the top level Nox environment, the Python version is not controlled, so the dependency stack will often be for a different Python version than what is in the cache, leading to lots of new downloads.Solutions
matrix.python-version, so that the Cartopy dependency stack comes from the cache.testsworkflow 'control' of the cache, havingwheelsetc only use the cache but not populate it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should benchmarking also be using the Cartopy cache?