mamba-org / setup-micromamba

GitHub Action to set up micromamba
MIT License
105 stars 16 forks source link

Setup micromamba once, but install and use multiple envs (allow setup without creating an env?) #51

Closed MikulasZelinka closed 1 year ago

MikulasZelinka commented 1 year ago

Hello, I'd like to achieve the following:

  1. micromamba is setup once (and bash is initialised, as is already the default)
  2. we install multiple empty envs with different python versions
  3. we install a custom python package and run pytest in each of the different envs

I have this so far:

name: Testing (pytest)

on: push

jobs:
  test:
    runs-on: ubuntu-latest

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

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11"]

    steps:
      - uses: actions/checkout@v3

      - uses: mamba-org/setup-micromamba@v1.1.0
        with:
          environment-name: ${{ matrix.python-version }}
          create-args: python=${{ matrix.python-version }}

      - name: test
        run: |
          pip install .
          pip install pytest
          pytest

Now this works, however, micromamba is installed four times.

For example, if there was a way to just not install any env when setting micromamba up, I could just set up micromamba once without the matrix and then manually install the different envs in a shell using the matrix.

pavelzw commented 1 year ago

When you don't specify anything, the action doesn't set up an environment.

You could do something like this:

name: Testing (pytest)

on: push

jobs:
  test:
    runs-on: ubuntu-latest

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

    steps:
      - uses: actions/checkout@v3

      - uses: mamba-org/setup-micromamba@v1.1.0
      - name: test 3.8
        run: |
          micromamba create -n 3.8 python=3.8 pytest
          micromamba activate 3.8
          pip install .
          pytest
      ...
pavelzw commented 1 year ago

install the different envs in a shell using the matrix

From my understanding, this wouldn't work since a matrix always spawns a new runner where we need to install micromamba on. You could do this using a loop in bash, though.