Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix caching example #212

Merged
merged 6 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions .github/workflows/caching-envs-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ jobs:
(github.event_name == 'schedule' && github.repository ==
'conda-incubator/setup-miniconda') || (github.event_name != 'schedule')

strategy:
matrix:
include:
- os: ubuntu-latest
label: linux-64
prefix: /usr/share/miniconda3/envs/anaconda-client-env

- os: macos-latest
label: osx-64
prefix: /Users/runner/miniconda3/envs/anaconda-client-env

- os: windows-latest
label: win-64
prefix: C:\Miniconda3\envs\anaconda-client-env

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand All @@ -46,15 +31,17 @@ jobs:
miniforge-version: latest
activate-environment: anaconda-client-env
use-mamba: true

- name: Get Date
id: get-date
run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')"
shell: bash

- name: Set cache date
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV

- name: Cache conda env
- name: Cache Conda env
uses: actions/cache@v2
with:
path: ${{ matrix.prefix }}
key: ${{ matrix.label }}-conda-${{ hashFiles('etc/example-environment-caching.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}--${{ runner.arch }}--${{ steps.get-date.outputs.today }}-${{ hashFiles('etc/example-environment-caching.yml') }}-${{ env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/example-5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v2
- uses: ./
with:
installer-url: https://github.com/conda-forge/miniforge/releases/download/4.9.0-3/Miniforge-pypy3-4.9.0-3-MacOSX-x86_64.sh?foo=bar&baz
installer-url: https://github.com/conda-forge/miniforge/releases/download/4.11.0-0/Miniforge-pypy3-4.11.0-0-MacOSX-x86_64.sh?foo=bar&baz
allow-softlinks: true
show-channel-urls: true
use-only-tar-bz2: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
- uses: actions/checkout@v2
- run: |
npm install
npm check
npm build
npm run check
npm run build
46 changes: 13 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,31 +575,7 @@ as they are not included in the conda package cache.

### Caching environments

A Miniforge variant is recommended to cache deployed environments, since the
Miniconda installation path requires succesive changes of folder ownership in
order to work with the `cache` action.

Every operating system use a different Miniforge `prefix`, so if you want to
cache the environment on all of them you must use a `matrix` strategy.

```yaml
strategy:
matrix:
include:
- os: ubuntu-latest
label: linux-64
prefix: /usr/share/miniconda3/envs/anaconda-client-env

- os: macos-latest
label: osx-64
prefix: /Users/runner/miniconda3/envs/anaconda-client-env

- os: windows-latest
label: win-64
prefix: C:\Miniconda3\envs\anaconda-client-env
```

Then, the first installation step should setup a Miniconda variant without
The first installation step should setup a Miniconda variant without
specifying a environment file.

```yaml
Expand All @@ -613,18 +589,22 @@ specifying a environment file.
```

It's a good idea to refresh the cache every 24 hours to avoid inconsistencies
of package versions between the CI pipeline and local installations. You can
skip that step if you use a resolved environment file product of
of package versions between the CI pipeline and local installations.
Here we ensure that this happens by adding the current date to the cache key.
You can remove the "Get Date" step below if you use a resolved environment file product of
`conda env export` or `conda list --explicit`.

```yaml
- name: Set cache date
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV

- uses: actions/cache@v2
- name: Get Date
id: get-date
run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')"
shell: bash

- name: Cache Conda env
uses: actions/cache@v2
with:
path: ${{ matrix.prefix }}
key: ${{ matrix.label }}-conda-${{ hashFiles('etc/example-environment-caching.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}--${{ runner.arch }}--${{ steps.get-date.outputs.today }}-${{ hashFiles('etc/example-environment-caching.yml') }}-${{ env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
Expand Down