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 all 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 .
20 changes: 6 additions & 14 deletions .github/workflows/docs-a11y.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +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@main
with:
micromamba-version: latest
environment-name: ${{ github.event.repository.name }}-docs-${{ 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 }}
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
19 changes: 5 additions & 14 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +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@main
with:
micromamba-version: latest
environment-name: ${{ github.event.repository.name }}-docs-${{ 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 }}
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@main
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@main
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Moved to `conda-incubator/setup-miniconda` instead of `mamba-org/setup-micromamba` where we would benefit from having `mamba`/`conda` available on the runner PATH (#26).

### Added

- Composite action for building a project-specific conda environment, used across reusable workflows but also available for direct use as a step in other projects (#26).

## [v1.0.0] - 2024-07-12

### Fixed
Expand Down
Loading