Skip to content

Commit

Permalink
Build and cache conda environments with lockfiles (#2011)
Browse files Browse the repository at this point in the history
* Build with lockfiles on CI

* Cache conda environment

* Move defaults to top

* Use --file

* Test cache

* Cache conda env in build-docs workflow

* Test docs cache on my fork

* Missing cache path

* Change cache step name

* Pre-merge changes

* Fix typo

* Change cache step name (again)

* Minor changes to build docs workflow
  • Loading branch information
epassaro authored May 16, 2022
1 parent 0ece835 commit 0205add
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# https://tardis-sn.github.io/tardis/development/continuous_integration.html

name: build-docs
name: docs

on:

Expand All @@ -23,8 +23,9 @@ on:
workflow_dispatch: # manual trigger

env:
CACHE_NUMBER: 0 # increase to reset cache manually
DEPLOY_BRANCH: gh-pages # deployed docs branch
ROOT_REDIRECT: latest # https://tardis-sn.github.io/tardis/latest
ROOT_REDIRECT: latest # redirects to: https://tardis-sn.github.io/tardis/latest

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
Expand Down Expand Up @@ -59,10 +60,19 @@ jobs:
with:
miniforge-variant: Mambaforge
miniforge-version: latest
environment-file: tardis_env3.yml
activate-environment: tardis
use-mamba: true

- uses: actions/cache@v2
with:
path: /usr/share/miniconda3/envs/tardis
key: conda-linux-64-${{ hashFiles('conda-linux-64.lock') }}-${{ env.CACHE_NUMBER }}
id: cache-conda

- name: Update environment
run: mamba update -n tardis --file conda-linux-64.lock
if: steps.cache-conda.outputs.cache-hit != 'true'

- name: Install package
run: pip install -e .

Expand Down Expand Up @@ -105,12 +115,13 @@ jobs:
user_name: 'TARDIS Bot'
user_email: 'tardis.sn.bot@gmail.com'

- name: Redirect root
- name: Create redirect
run: |
mkdir redirects && cd redirects
echo '<head>' >> index.html
echo ' <meta http-equiv="Refresh" content="0; url='/${{ github.event.repository.name }}/${{ env.ROOT_REDIRECT }}'"/>' >> index.html
echo '</head>' >> index.html
if: github.event_name != 'pull_request_target'

- name: Deploy redirect
uses: peaceiris/actions-gh-pages@v3
Expand All @@ -121,6 +132,7 @@ jobs:
keep_files: true
user_name: 'TARDIS Bot'
user_email: 'tardis.sn.bot@gmail.com'
if: github.event_name != 'pull_request_target'

- name: Find comment
uses: peter-evans/find-comment@v1
Expand Down
38 changes: 28 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,37 @@ on:
branches:
- '*'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

env:
CACHE_NUMBER: 0 # increase to reset cache manually
PYTEST_FLAGS: --tardis-refdata=${{ github.workspace }}/tardis-refdata
--cov=tardis --cov-report=xml --cov-report=html
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash -l {0}

jobs:
build:

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
include:

defaults:
run:
shell: bash -l {0}
- os: ubuntu-latest
label: linux-64
prefix: /usr/share/miniconda3/envs/tardis

runs-on: ${{ matrix.os }}
- os: macos-latest
label: osx-64
prefix: /Users/runner/miniconda3/envs/tardis

name: ${{ matrix.label }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

Expand All @@ -46,10 +55,19 @@ jobs:
with:
miniforge-variant: Mambaforge
miniforge-version: latest
environment-file: tardis_env3.yml
activate-environment: tardis
use-mamba: true

- uses: actions/cache@v2
with:
path: ${{ matrix.prefix }}
key: conda-${{ matrix.label }}-${{ hashFiles('conda-${{ matrix.label }}.lock') }}-${{ env.CACHE_NUMBER }}
id: cache-conda

- name: Update environment
run: mamba update -n tardis --file conda-${{ matrix.label }}.lock
if: steps.cache-conda.outputs.cache-hit != 'true'

- name: Install package
run: pip install -e .

Expand Down

0 comments on commit 0205add

Please sign in to comment.