Could you add an example for a python workspace
For pip:
The default location for the cache directory depends on the Operating System:
Unix
~/.cache/pipand it respects theXDG_CACHE_HOMEdirectory.macOS
~/Library/Caches/pip.Windows
<CSIDL_LOCAL_APPDATA>\pip\Cache
https://pip.pypa.io/en/stable/reference/pip_install/#caching
Try something like this for Ubuntu:
name: Test
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.6", "3.7"]
os: [ubuntu-latest, ubuntu-16.04, macOS-latest]
steps:
- uses: actions/checkout@v1
- uses: actions/cache@preview
with:
path: ~/.cache/pip
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
That won't work for the other operating systems, but doesn't fail the build.
An if can be added to duplicated blocks with different paths (plus a name: for clarity):
- name: Ubuntu cache
uses: actions/cache@preview
if: startsWith(matrix.os, 'ubuntu')
with:
path: ~/.cache/pip
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
- name: macOS cache
uses: actions/cache@preview
if: startsWith(matrix.os, 'macOS')
with:
path: ~/Library/Caches/pip
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
Example: https://github.com/hugovk/tinytext/runs/283473777
Unfortunately you cannot list multiple directories, eg. for both Ubuntu and macOS:
- uses: actions/cache@preview
with:
path:
- ~/.cache/pip
- ~/Library/Caches/pip
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
- Your workflow file was invalid: The pipeline is not valid. .github/workflows/test.yml (Line: 20, Col: 13): A sequence was not expected
I've not tried Windows yet, anyone know the path: to use for <CSIDL_LOCAL_APPDATA>\pip\Cache?
Here's an example for caching two directories. Both on a single OS/Python:
name: Lint
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
steps:
- uses: actions/checkout@v1
- name: pip cache
uses: actions/cache@preview
with:
path: ~/.cache/pip
key: lint-${{ matrix.python-version }}-pip
- name: pre-commit cache
uses: actions/cache@preview
with:
path: ~/.cache/pre-commit
key: lint-${{ matrix.python-version }}-pre-commit
You have to be careful the keys are unique between different workflows to avoid collisions!
(See also https://github.com/actions/cache/issues/17.)
Most helpful comment
pip cache
For pip:
https://pip.pypa.io/en/stable/reference/pip_install/#caching
Only Ubuntu
Try something like this for Ubuntu:
That won't work for the other operating systems, but doesn't fail the build.
Ubuntu + macOS
An
ifcan be added to duplicated blocks with differentpaths (plus aname:for clarity):Example: https://github.com/hugovk/tinytext/runs/283473777
Unfortunately you cannot list multiple directories, eg. for both Ubuntu and macOS:
Windows
I've not tried Windows yet, anyone know the
path:to use for<CSIDL_LOCAL_APPDATA>\pip\Cache?