Skip to content

Commit c6b77cf

Browse files
committed
Workflow with conda env cache
1 parent dbc7e75 commit c6b77cf

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Python Package with caching
2+
3+
# taken from https://github.com/epassaro/cache-conda-envs
4+
5+
# cancel any previous running or pending jobs from the same branch
6+
concurrency:
7+
group: python-package-conda-cache-${{ github.head_ref }}
8+
cancel-in-progress: true
9+
10+
on:
11+
push:
12+
branches:
13+
- '*'
14+
15+
pull_request:
16+
branches:
17+
- '*'
18+
19+
schedule:
20+
- cron: '0 0 * * *'
21+
22+
env:
23+
CACHE_NUMBER: 0 # increase to reset cache manually
24+
25+
jobs:
26+
build:
27+
28+
strategy:
29+
matrix:
30+
include:
31+
- os: ubuntu-latest
32+
label: linux-64
33+
prefix: /usr/share/miniconda3/envs/my-env
34+
35+
name: ${{ matrix.label }}
36+
runs-on: ${{ matrix.os }}
37+
steps:
38+
- uses: actions/checkout@v2
39+
40+
- name: Setup Mambaforge
41+
uses: conda-incubator/setup-miniconda@v2
42+
with:
43+
miniforge-variant: Mambaforge
44+
miniforge-version: latest
45+
activate-environment: my-env
46+
use-mamba: true
47+
48+
- name: Set cache date
49+
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
50+
51+
- uses: actions/cache@v2
52+
with:
53+
path: ${{ matrix.prefix }}
54+
key: ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
55+
id: cache
56+
57+
- name: Update environment
58+
run: mamba env update -n my-env -f environment.yml
59+
if: steps.cache.outputs.cache-hit != 'true'
60+
61+
- name: Run tests
62+
shell: bash -l {0}
63+
run: pytest ./tests

0 commit comments

Comments
 (0)