Skip to content

luceda/provision-with-micromamba

 
 

Repository files navigation

provision-with-micromamba

test

GitHub Action to provision a CI instance using micromamba.

Dependencies

provision-with-micromamba requires the curl and tar programs (with bzip2 support). They are preinstalled in the default GitHub Actions environments.

Inputs

environment-file

The environment.yml or .lock file for the conda environment. If 'false', no enviroment will be created (only Micromamba will be installed) and you should provide 'channels'.

environment-name

(Optional) The name of the conda environment (defaults to name from the environment.yml file). Required if 'environment-file' is a '.lock' file or 'false'.

micromamba-version

(Optional) Version of micromamba to use, eg. '0.20' (default 'latest').

extra-specs

(Optional) Additional specifications (packages) to install. Pretty useful when using matrix builds to pin versions of a test/run dependency. For multiple packages, use multiline syntax (see examples). Note that selectors (e.g. sel(linux): my-linux-package, sel(osx): my-osx-package, sel(win): my-win-package) are available.

channels

(Optional) Comma separated list of channels to use in order of priority (eg., conda-forge,my-private-channel)

cache-downloads

(Optional) If 'true', cache downloaded packages across calls to the provision-with-micromamba action. Cache invalidation can be controlled using the 'cache-downloads-key' option.

cache-downloads-key

(Optional) Custom download cache key used with 'cache-downloads: true'. The default download cache key will invalidate the cache once per day.

cache-env

(Optional) If 'true', cache installed environments across calls to the provision-with-micromamba action. Cache invalidation can be controlled using the 'cache-env-key' option.

cache-env-key

(Optional) Custom environment cache key used with 'cache-env: true'. With the default environment cache key, separate caches will be created for each operating system (eg., Linux) and platform (eg., x64) and day (eg., 2022-01-31), and the cache will be invalidated whenever the contents of 'environment-file' or 'extra-specs' change.

Example usage

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Install Conda environment from environment.yml
        uses: mamba-org/provision-with-micromamba@main

      # Linux and macOS
      - name: Run Python
        shell: bash -l {0}
        run: |
          python -c "import numpy"

      # Windows
      # With Powershell:
      - name: Run Python
        shell: powershell
        run: |
          python -c "import numpy"
      # Or with cmd:
      - name: Run cmd.exe
        shell: cmd /C CALL {0}
        run: >-
          micromamba info && micromamba list

Please see the IMPORTANT notes on additional information on environment activation.

Example with customization

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        pytest: ["6.1", "6.2"]
    steps:
      - uses: actions/checkout@v2

      - name: Install Conda environment with Micromamba
        uses: mamba-org/provision-with-micromamba@main
        with:
          environment-file: myenv.yaml
          environment-name: myenvname
          extra-specs: |
            python=3.7
            pytest=${{ matrix.pytest }}

Example with download caching

Use cache-downloads to enable download caching across action runs (.tar.bz2 files).

By default the cache is invalidated once per day. See the cache-downloads-key option for custom cache invalidation.

- name: Install Conda environment with Micromamba
  uses: mamba-org/provision-with-micromamba@main
  with:
    cache-downloads: true

Example with environment caching

Use cache-env to cache the entire Conda environment (envs/myenv directory) across action runs.

By default the cache is invalidated whenever the contents of the environment-file or extra-specs change, plus once per day. See the cache-env-key option for custom cache invalidation.

- name: Install Conda environment with Micromamba
  uses: mamba-org/provision-with-micromamba@main
  with:
    cache-env: true

Notes on caching

Branches have separate caches

Due to a limitation of GitHub Actions any download or environment caches created on a branch will not be available on the main/parent branch after merging. This also applies to PRs.

In contrast, branches can use a cache created on the main/parent branch.

See also this thread.

When to use download caching

Please see this comment for now.

When to use environment caching

Please see this comment for now.

More examples

More examples may be found in this repository's tests.

Reference

See action.yml.

IMPORTANT

Some shells require special syntax (e.g. bash -l {0}). You can set this up with the default option:

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

# Or top-level:
defaults:
  run:
    shell: bash -l {0}
jobs:
  ...

Find the reasons below (taken from setup-miniconda):

  • Bash shells do not use ~/.profile or ~/.bashrc so these shells need to be explicitely declared as shell: bash -l {0} on steps that need to be properly activated (or use a default shell). This is because bash shells are executed with bash --noprofile --norc -eo pipefail {0} thus ignoring updated on bash profile files made by conda init bash. See Github Actions Documentation and thread.
  • Cmd shells do not run Autorun commands so these shells need to be explicitely declared as shell: cmd /C call {0} on steps that need to be properly activated (or use a default shell). This is because cmd shells are executed with %ComSpec% /D /E:ON /V:OFF /S /C "CALL "{0}"" and the /D flag disabled execution of Command Processor/Autorun Windows registry keys, which is what conda init cmd.exe sets. See Github Actions Documentation.
  • sh is not supported. Please use bash.

Development

When developing, you need to

  1. install nodejs
  2. clone the repo
  3. run npm install -y
  4. run npm run build after making changes

About

Clone for use in luceda/python-lint-annotate

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.9%
  • Python 2.1%