From 48fac330c897ceaa45b89f2d1735c6a8140a1b13 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 26 Jul 2024 08:46:40 +0200 Subject: [PATCH] Make it default --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 7 +++++++ README.md | 12 ++++++------ action.yml | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7bffd7..48931b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: - uses: ./action with: - cache-suffix: -${{ env.WEEK }}-${{ github.job }} + cache-suffix: -${{ env.WEEK }} - run: uv --version diff --git a/CHANGELOG.md b/CHANGELOG.md index 5befb93..9848a56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,13 @@ 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. + [#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 diff --git a/README.md b/README.md index 264477d..f718acd 100644 --- a/README.md +++ b/README.md @@ -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 the current week number to refresh the cache weekly: ```yaml # ... @@ -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 }} # ... ``` diff --git a/action.yml b/action.yml index 9aa672f..5e3717d 100644 --- a/action.yml +++ b/action.yml @@ -58,7 +58,7 @@ runs: if: inputs.use-cache-if == 'true' with: path: ${{ env.UV_CACHE_DIR }} - key: uv-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-${{ 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