Skip to content

Commit

Permalink
Make workflow and jobs names part of the cache key (#10)
Browse files Browse the repository at this point in the history
* Use github.job for dedup

* Maybe action is even better?

* Nope

* Make it default
  • Loading branch information
hynek authored Jul 26, 2024
1 parent 8699f0c commit 051aa61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

- uses: ./action
with:
cache-suffix: -hash-deps-path-job
cache-suffix: -LE-SUFFIX
cache-dependency-path: "**/LICENSE"

- run: |
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
[#9](https://github.com/hynek/setup-cached-uv/pull/9)


### Changed

- The name of the workflow and of the current job are now part of the cache key.
While this means that you can't share a cache between jobs, this should be only a minor inconvenience in practice and make it do the right thing in the vast majority of cases.

If this is a problem for you, please open an issue and tell us about your use-case.
We can always add an option to set the whole key explicitly.
[#10](https://github.com/hynek/setup-cached-uv/pull/10)


## [1.3.0](https://github.com/hynek/setup-cached-uv/compare/v1.2.0...v1.3.0) - 2024-07-26

### Fixed
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ jobs:
## Cache Management
> [!CAUTION]
> It’s important to understand that once a cache of a certain name has been created, it will be used in all subsequent jobs within the same workflow and will **not** be updated.
> It’s important to understand that once a cache of a certain key has been created, it will be used in all subsequent jobs within the same workflow and will **not** be updated.
>
> This means that if you create the cache in the first job that installs only, say, *build* and *twine*, and later load the cache again and install more packages, those packages will **not** be cached for the next run.
>
> A cache also [doesn’t expire as long as it has been used in the last 7 days](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy).
> That does **not** mean that you’re getting obsolete package versions – just that they’re not cached.
To work around this, *setup-cached-uv* allows you to add two types of suffixes as inputs to the cache name.
To work around this, *setup-cached-uv* allows you to add two types of suffixes as inputs to the cache key.
This way you can have multiple caches per workflow that contain different sets of packages.
Note that the operating system of the runner is automatically added to the cache name – meaning, without adding suffixes, the names of the caches are `uv-Linux`, `uv-macOS`, and `uv-Windows`.
Note that the operating system of the runner, the name of the workflow, and the job name are automatically added to the cache key – meaning, without adding suffixes, the names of the caches are something like `uv-Linux-CI-tests`, `uv-macOS-CI-tests`, and `uv-Windows-CI-tests`.


### Optional Inputs

#### `cache-suffix`

A static string to append to the cache name.
This could, for example, be the name of the job, or the current week number to bust the cache weekly:
A static string to append to the cache key.
This could, for example, be the current week number to refresh the cache weekly:

```yaml
# ...
Expand All @@ -47,7 +47,7 @@ This could, for example, be the name of the job, or the current week number to b
- uses: hynek/setup-cached-uv@v1
with:
cache-suffix: -tests-${{ env.WEEK }}
cache-suffix: ${{ env.WEEK }}
# ...
```

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ runs:
if: inputs.use-cache-if == 'true'
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}${{ inputs.cache-suffix }}${{ env.HASH_CACHE_SUFFIX }}
key: uv-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}${{ inputs.cache-suffix }}${{ env.HASH_CACHE_SUFFIX }}

- name: Schedule cache pruning
uses: gacts/run-and-post-run@4683764dd706df847f57b9bed39d08164bcd2690
Expand Down

0 comments on commit 051aa61

Please sign in to comment.