Skip to content

Commit

Permalink
feat: use cache option (#6)
Browse files Browse the repository at this point in the history
* feat: use cache option

* refactor: address review comments

Signed-off-by: Henry Schreiner <[email protected]>

---------

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Jul 22, 2024
1 parent 47408fd commit c8e7913
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This could, for example, be the name of the job, or the current week number to b
- run: echo WEEK=$(date +%V) >>$GITHUB_ENV
shell: bash
- uses: ./action
- uses: hynek/setup-cached-uv@v1
with:
cache-suffix: -tests-${{ env.WEEK }}
# ...
Expand All @@ -61,9 +61,23 @@ Internally, the GitHub Actions function `hashFiles` is used to hash the passed p
Using this with a fully pinned `requirements.txt` file is the most efficient use of this action because it automatically invalidates the cache.


#### `if-use-cache`

This defaults to `true`, but can be used to disable the cache, since GitHub's default caching speed is slower than uv in many cases.
For example, if you have dependencies that don't provide prebuilt PyPy wheels, you can only cache that run like this:

```yaml
# ...
- uses: hynek/setup-cached-uv@v1
with:
if-use-cache: ${{ startsWith(matrix.python-version, 'pypy') }}
# ...
```


### Examples

Check out [our CI](.github/workflows/ci.yml) to see both inputs in action.
Check out [our CI](.github/workflows/ci.yml) to see some inputs in action.


## License
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ inputs:
required: false
default: ""

use-cache-if:
description: Save the cache.
required: false
default: true

runs:
using: composite

Expand All @@ -41,10 +46,11 @@ runs:
"HASH_CACHE_SUFFIX=-${{ hashFiles(inputs.cache-dependency-path) }}"
>>$GITHUB_ENV
shell: bash
if: inputs.cache-dependency-path != ''
if: inputs.cache-dependency-path != '' && inputs.use-cache-if == 'true'

- name: Load uv cache
uses: actions/cache@v4
if: inputs.use-cache-if == 'true'
with:
path: ${{ env.UV_CACHE }}
key: uv-${{ runner.os }}${{ inputs.cache-suffix }}${{ env.HASH_CACHE_SUFFIX }}

0 comments on commit c8e7913

Please sign in to comment.