From 0205add1bb078339e3610c8a13905159f044ed51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 16 May 2022 12:16:11 -0300 Subject: [PATCH] Build and cache conda environments with lockfiles (#2011) * 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 --- .github/workflows/build-docs.yml | 20 +++++++++++++---- .github/workflows/tests.yml | 38 +++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 5e74d776088..54935e1f403 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -2,7 +2,7 @@ # # https://tardis-sn.github.io/tardis/development/continuous_integration.html -name: build-docs +name: docs on: @@ -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 }} @@ -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 . @@ -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 '' >> index.html echo ' ' >> index.html echo '' >> index.html + if: github.event_name != 'pull_request_target' - name: Deploy redirect uses: peaceiris/actions-gh-pages@v3 @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 58886e519d3..d9c3c9e2cab 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 .