Skip to content

Caching Env Example #1320

Caching Env Example

Caching Env Example #1320

name: "Caching Env Example"
on:
pull_request:
branches:
- "*"
push:
branches:
- "develop"
- "main"
- "master"
schedule:
# Note that cronjobs run on master/main by default
- cron: "0 0 * * *"
concurrency:
group:
${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
caching-example:
name: Caching-Env
# prevent cronjobs from running on forks
if:
(github.event_name == 'schedule' && github.repository ==
'conda-incubator/setup-miniconda') || (github.event_name != 'schedule')
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Setup Miniforge
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
with:
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: Cache Conda env
uses: actions/cache@v4
with:
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
id: cache
- name: Update environment
run:
conda env update -n anaconda-client-env -f
etc/example-environment-caching.yml
if: steps.cache.outputs.cache-hit != 'true'