mirror of https://github.com/actions/cache.git
Add Python example using 'pip cache dir' to get cache location (#285)
* Fix existing example * Add Python example using 'pip cache dir' to get cache location * Let users decide how they install pip 20.1+pull/289/head
parent
9f07ee13de
commit
ccf9619480
27
examples.md
27
examples.md
|
@ -18,6 +18,7 @@
|
||||||
- [Python - pip](#python---pip)
|
- [Python - pip](#python---pip)
|
||||||
- [Simple example](#simple-example)
|
- [Simple example](#simple-example)
|
||||||
- [Multiple OS's in a workflow](#multiple-oss-in-a-workflow)
|
- [Multiple OS's in a workflow](#multiple-oss-in-a-workflow)
|
||||||
|
- [Using pip to get cache location](#using-pip-to-get-cache-location)
|
||||||
- [Using a script to get cache location](#using-a-script-to-get-cache-location)
|
- [Using a script to get cache location](#using-a-script-to-get-cache-location)
|
||||||
- [R - renv](#r---renv)
|
- [R - renv](#r---renv)
|
||||||
- [Simple example](#simple-example-1)
|
- [Simple example](#simple-example-1)
|
||||||
|
@ -290,14 +291,32 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
||||||
${{ runner.os }}-pip-
|
${{ runner.os }}-pip-
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using pip to get cache location
|
||||||
|
|
||||||
|
> Note: This requires pip 20.1+
|
||||||
|
```yaml
|
||||||
|
- name: Get pip cache dir
|
||||||
|
id: pip-cache
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=dir::$(pip cache dir)"
|
||||||
|
|
||||||
|
- name: pip cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ${{ steps.pip-cache.outputs.dir }}
|
||||||
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pip-
|
||||||
|
```
|
||||||
|
|
||||||
### Using a script to get cache location
|
### Using a script to get cache location
|
||||||
|
|
||||||
> Note: This uses an internal pip API and may not always work
|
> Note: This uses an internal pip API and may not always work
|
||||||
```yaml
|
```yaml
|
||||||
- name: Get pip cache
|
- name: Get pip cache dir
|
||||||
id: pip-cache
|
id: pip-cache
|
||||||
run: |
|
run: |
|
||||||
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
|
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
|
||||||
|
|
||||||
- uses: actions/cache@v1
|
- uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
|
|
Loading…
Reference in New Issue