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

Setup micromamba to miniconda #26

Merged
merged 17 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
71 changes: 71 additions & 0 deletions .github/actions/create-mamba-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: "Create a mamba environment"
description: "Steps to create mamba environment with all required dependencies and the project itself installed (via pip)."
inputs:
py3version:
description: "Minor version of Python version 3 to run the test on (e.g. `11` for python v3.11)"
required: true
env_name:
description: "Name of the Mamba environment. If it matches a name of a cached environment in the caller repository, that cache will be used."
required: true
additional_mamba_args:
description: "Any additional arguments to pass to micromamba when creating the python environment"
required: false
default: ""
cache_mamba_env:
description: "If true, cache the mamba environment for speedier CI"
required: false
default: "true"
cache_refresh_time_format:
description: >-
The time format to extract from the current date with which a cache refresh will be forced even if nothing has changed in the environment name.
E.g. '+%Y%m' forces a cache reset every month.
Format options are '%Y' (year), '%m' (month) and '%d' (day).
required: false
default: "+%Y%m"
runs:
using: "composite" #
steps:
- uses: actions/checkout@v4

- name: Get hash for environment name
id: get-env-hash
run: echo "hash=${{ github.event.repository.name }}-${{ inputs.env_name }}-${{ hashFiles('requirements/base.txt', 'requirements/dev.txt') }}" >> $GITHUB_OUTPUT

shell: bash
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: ${{ steps.get-env-hash.outputs.hash }}
use-mamba: true
python-version: 3.${{ inputs.py3version }}

- name: Get Date
id: get-refresh-timestamp
run: echo "timestamp=$(/bin/date -u ${{ inputs.cache_refresh_time_format }})" >> $GITHUB_OUTPUT
shell: bash

- name: Cache Mamba env
id: cache
if: ${{ inputs.cache_mamba_env }} == 'true'
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs
key: ${{ steps.get-refresh-timestamp.outputs.timestamp }}-${{ steps.get-env-hash.outputs.hash }}

- name: Update environment
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run:
mamba update
-c city-modelling-lab
-n ${{ steps.get-env-hash.outputs.hash }}
ruff
${{ inputs.additional_mamba_args }}
--file requirements/base.txt
--file requirements/dev.txt

- name: Install package
shell: bash
run: mamba run -n ${{ steps.get-env-hash.outputs.hash }} pip install --no-dependencies -e .
29 changes: 16 additions & 13 deletions .github/workflows/docs-a11y.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ on:
description: "If jupyter notebooks are included in the docs, specify the kernel name they expect, e.g. the package name"
required: false
type: string
additional_mamba_args:
description: "Any additional arguments to pass to micromamba when creating the python environment"
required: false
default: ""
type: string
py3version:
description: "Minor version of Python version 3 to run the test on (e.g. `11` for python v3.11)"
required: false
type: string
default: "11"

defaults:
run:
Expand All @@ -25,20 +35,13 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v1

- uses: arup-group/actions-city-modelling-lab/.github/actions/create-mamba-env@setup-micromamba-to-miniconda
with:
micromamba-version: latest
environment-name: ${{ github.event.repository.name }}-docs-${{ hashFiles('requirements/dev.txt') }}
environment-file: requirements/base.txt
create-args: >-
-c city-modelling-lab
-f requirements/dev.txt
python=3.11
post-cleanup: all
cache-environment: true

- name: Install package
run: pip install --no-dependencies -e .
py3version: ${{ inputs.py3version }}
env_name: docs
additional_mamba_args: ${{ inputs.additional_mamba_args }}
cache_mamba_env: "true"

- name: install jupyter kernel
if: inputs.notebook_kernel != ''
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ on:
description: "If jupyter notebooks are included in the docs, specify the kernel name they expect, e.g. the package name"
required: false
type: string
additional_mamba_args:
description: "Any additional arguments to pass to micromamba when creating the python environment"
required: false
default: ""
type: string
py3version:
description: "Minor version of Python version 3 to run the test on (e.g. `11` for python v3.11)"
required: false
type: string
default: "11"

defaults:
run:
Expand All @@ -35,20 +45,12 @@ jobs:
with:
fetch-depth: 0 # used to build docs into the gh-pages branch without losing branch history. See https://github.com/jimporter/mike/issues/49

- uses: mamba-org/setup-micromamba@v1
- uses: arup-group/actions-city-modelling-lab/.github/actions/create-mamba-env@setup-micromamba-to-miniconda
with:
micromamba-version: latest
environment-name: ${{ github.event.repository.name }}-docs-${{ hashFiles('requirements/dev.txt') }}
environment-file: requirements/base.txt
create-args: >-
-c city-modelling-lab
-f requirements/dev.txt
python=3.11
post-cleanup: all
cache-environment: true

- name: Install package
run: pip install --no-dependencies -e .
py3version: ${{ inputs.py3version }}
env_name: docs
additional_mamba_args: ${{ inputs.additional_mamba_args }}
cache_mamba_env: "true"

- name: install jupyter kernel
if: inputs.notebook_kernel != ''
Expand Down
24 changes: 7 additions & 17 deletions .github/workflows/python-install-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,22 @@ jobs:
test:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use supplied Mamba environment name
if: inputs.mamba_env_name != ''
run: echo "MAMBAENVNAME=${{ inputs.mamba_env_name }}" >> $GITHUB_ENV

- name: Create Mamba environment name based on OS and python version
if: inputs.mamba_env_name == ''
run: echo "MAMBAENVNAME=${{ inputs.os }}-3${{ inputs.py3version }}-${{ hashFiles('requirements/dev.txt') }}" >> $GITHUB_ENV
run: echo "MAMBAENVNAME=${{ inputs.os }}-3${{ inputs.py3version }}" >> $GITHUB_ENV

- uses: mamba-org/setup-micromamba@v1
- uses: arup-group/actions-city-modelling-lab/.github/actions/create-mamba-env@setup-micromamba-to-miniconda
with:
micromamba-version: latest
environment-name: ${{ github.event.repository.name }}-${{ env.MAMBAENVNAME }}
environment-file: requirements/base.txt
create-args: >-
${{ inputs.additional_mamba_args }}
-c city-modelling-lab
-f requirements/dev.txt
ruff
python=3.${{ inputs.py3version }}
post-cleanup: all
cache-environment: ${{ inputs.cache_mamba_env }}

- name: Install package
run: pip install --no-dependencies -e .
py3version: ${{ inputs.py3version }}
env_name: ${{ env.MAMBAENVNAME }}
additional_mamba_args: ${{ inputs.additional_mamba_args }}
cache_mamba_env: "${{ inputs.cache_mamba_env }}"

- name: Install jupyter kernel
if: inputs.notebook_kernel != ''
Expand Down
21 changes: 7 additions & 14 deletions .github/workflows/python-memory-profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: mamba-org/setup-micromamba@v1

- uses: arup-group/actions-city-modelling-lab/.github/actions/create-mamba-env@setup-micromamba-to-miniconda
with:
micromamba-version: latest
environment-name: ${{ github.event.repository.name }}-ubuntu-latest-3${{ inputs.py3version }}-profiling-${{ hashFiles('requirements/dev.txt') }}
environment-file: requirements/base.txt
create-args: >-
${{ inputs.additional_mamba_args }}
-c city-modelling-lab
-f requirements/dev.txt
python=3.${{ inputs.py3version }}
py3version: ${{ inputs.py3version }}
env_name: profiling
additional_mamba_args:
memray=1.9
pytest-memray=1.5
post-cleanup: all
cache-environment: true

- name: Install package
run: pip install --no-dependencies .
${{ inputs.additional_mamba_args }}
cache_mamba_env: "true"

- name: Run memory and time profiling test
run: |
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/validate-reusable-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ jobs:
tool_versions: action-validator 0.5.3

- name: Lint Actions
run: action-validator --verbose .github/workflows/*.y*ml
run: action-validator --verbose .github/actions/**/*.y*ml

- name: Lint Workflows
run: action-validator --verbose .github/workflows/*.y*ml
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ _Inputs_:
`update_latest` will build the docs and use it to update the `develop` version of your `gh-pages` branch, assuming the alias `latest` links to the named version `develop`.
`update_stable` will build the docs and use it to add a new version of your docs on `gh-pages` branch and will update the alias `stable` to point at this version.
- notebook_kernel: If jupyter notebooks are included in the docs, specify the kernel name they expect, e.g. the package name.
- py3version (optional, default="11"): Minor version of Python version 3 to run the test on (e.g. `11` for python v3.11).
- additional_mamba_args (optional, default=""): Any additional arguments to pass to micromamba when creating the python environment.

_Required secrets_: None

Expand All @@ -237,6 +239,8 @@ _Inputs_:
- upload_report (optional, default=true): If true, upload a workflow artifact containing a full HTML accessibility report.
- allow_pr_comment (optional, default=true): If true, allow a bot to leave a PR comment with a summary of the accessibility report (including a link to the HTML report if `upload_report` is _true_).
- notebook_kernel: If jupyter notebooks are included in the docs, specify the kernel name they expect, e.g. the package name.
- py3version (optional, default="11"): Minor version of Python version 3 to run the test on (e.g. `11` for python v3.11).
- additional_mamba_args (optional, default=""): Any additional arguments to pass to micromamba when creating the python environment.

_Required secrets_: None

Expand Down
Loading