Skip to content

Commit

Permalink
add extra specs input
Browse files Browse the repository at this point in the history
support multiline extra specs
double quote each extra spec to avoid shell errors (redirection > in
bash, etc.)
add tests
add new input in README, add example
  • Loading branch information
adriendelsalle committed Oct 20, 2021
1 parent 17b1e86 commit ba8af56
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 16 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ jobs:
with:
environment-file: environment.yml
environment-name: myenv
extra-specs: |
pytest<=6.1
python=3.8.8
- name: run python in powershell
shell: powershell
run: |
python -VV
python -c "import numpy"
micromamba --help
if: runner.os == 'Windows'

- name: run python in bash
Expand All @@ -48,3 +52,31 @@ jobs:
run: |
python -c "import os; env = os.environ['CONDA_PREFIX'].split('/')[-1]; assert env == 'myenv'"
if: runner.os != 'Windows'

- name: check python version in powershell
shell: powershell
run: |
python --version
python -c "import platform; assert platform.python_version() == '3.8.8'"
if: runner.os == 'Windows'

- name: check python version in bash
shell: bash -l {0}
run: |
python --version
python -c "import platform; assert platform.python_version() == '3.8.8'"
if: runner.os != 'Windows'

- name: check pytest version in powershell
shell: powershell
run: |
pytest --version
python -c "import pytest; assert pytest.__version__.startswith('6.1')"
if: runner.os == 'Windows'

- name: check pytest version in bash
shell: bash -l {0}
run: |
pytest --version
python -c "import pytest; assert pytest.__version__.startswith('6.1')"
if: runner.os != 'Windows'
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# provision-with-micromamba

[![test](https://github.com/mamba-org/provision-with-micromamba/workflows/test/badge.svg)](https://github.com/mamba-org/provision-with-micromamba/actions?query=workflow%3Atest)

GitHub Action to provision a CI instance using micromamba
Expand All @@ -11,14 +12,20 @@ GitHub Action to provision a CI instance using micromamba

### `environment-name`

**Optional** Specify a custom environment name,
to overwrite the name specified in the `environment.yml`,
**Optional** Specify a custom environment name,
to overwrite the name specified in the `environment.yml`,
or in in case it was not specified in the `environment.yml`.

### `micromamba-version`

**Optional** Specifiy a custom micromamba version. Use `"latest"` for bleeding edge.

### `extra-specs`

**Optional** Specifiy additional specifications (packages) to install. Pretty useful when using matrix builds to pin versions of a test/run dependency.

Note: for multiple packages, use multiline syntax (see examples below)

## Example usage

Note: some shells need special syntax for invocation (e.g. `bash -l {0}`). You can set this up in [defaults](setup_default).
Expand All @@ -43,7 +50,7 @@ jobs:
shell: bash -l {0}
run: |
python -c "import numpy"
# windows
- name: run python
shell: powershell
Expand Down Expand Up @@ -74,6 +81,9 @@ jobs:
with:
environment-file: myenv.yaml
environment-name: myenv
extra-specs: |
python=3.7
pytest<=6.1
```

## IMPORTANT
Expand Down Expand Up @@ -124,7 +134,6 @@ Find the reasons below (taken from [setup-miniconda](https://github.com/conda-in
and result in very long install times.
- Conda activation does not correctly work on `sh`. Please use `bash`.


## Development

When developing, you need to
Expand Down
20 changes: 12 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
name: 'provision-with-micromamba'
description: 'provision a CI instance using micromamba'
name: "provision-with-micromamba"
description: "provision a CI instance using micromamba"
branding:
icon: 'chevrons-right'
color: 'green'
icon: "chevrons-right"
color: "green"
inputs:
environment-file:
description: 'the environment.yml file for the conda environment'
description: "the environment.yml file for the conda environment"
required: true
default: environment.yml
environment-name:
description: 'the name of the conda environment (defaults to name from the environment.yml file)'
description: "the name of the conda environment (defaults to name from the environment.yml file)"
required: false
micromamba-version:
description: 'version of micromamba to use (default: 0.9.2). Use "latest" for bleeding edge.'
required: false
default: "latest"
extra-specs:
description: "extra specifications to install (defaults is empty)"
required: false
default: ""

runs:
using: 'node12'
main: 'dist/index.js'
using: "node12"
main: "dist/index.js"
9 changes: 7 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function run () {
const micromambaVersion = core.getInput('micromamba-version')
const envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', envFileName)
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
const extraSpecs = core.getInput('extra-specs').split("\n").filter(x => x !== "");
const envName = core.getInput('environment-name') || envYaml.name
const condarc = path.join(os.homedir(), '.condarc')
const profile = path.join(os.homedir(), '.bash_profile')
Expand Down Expand Up @@ -78,6 +79,10 @@ async function run () {
}
core.endGroup()

const quotedExtraSpecsStr = extraSpecs.map(function(e) {
return '"' + e + '"';
}).join(" ");

if (process.platform !== 'win32') {

core.startGroup('Installing environment ' + envName + ' from ' + envFilePath + ' ...')
Expand Down Expand Up @@ -125,7 +130,7 @@ async function run () {

// final bits of the install
await execute('mkdir -p ' + path.join(os.homedir(), 'micromamba/pkgs/'))
await execute('source ' + profile + ' && micromamba create -n ' + envName + ' --strict-channel-priority -y -f ' + envFilePath)
await execute('source ' + profile + ' && micromamba create -n ' + envName + ' ' + quotedExtraSpecsStr + ' --strict-channel-priority -y -f ' + envFilePath)
fs.appendFileSync(profile, 'set -eo pipefail\n')
fs.appendFileSync(profile, 'micromamba activate ' + envName + '\n')
core.endGroup()
Expand Down Expand Up @@ -159,7 +164,7 @@ else
// Can only init once right now ...
// await execPwsh("~\\micromamba.exe shell init -s bash -p $HOME\\micromamba")
await execPwsh('MD $HOME\\micromamba\\pkgs -ea 0')
await execPwsh(`~\\micromamba.exe create -n ` + envName + ` --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(`~\\micromamba.exe create -n ` + envName + ' ' + quotedExtraSpecsStr + ` --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(autoactivate)

fs.appendFileSync(profile, `micromamba activate ${envName}\n`)
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function run () {
const micromambaVersion = core.getInput('micromamba-version')
const envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', envFileName)
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
const extraSpecs = core.getInput('extra-specs').split("\n").filter(x => x !== "");
const envName = core.getInput('environment-name') || envYaml.name
const condarc = path.join(os.homedir(), '.condarc')
const profile = path.join(os.homedir(), '.bash_profile')
Expand Down Expand Up @@ -71,6 +72,10 @@ async function run () {
}
core.endGroup()

const quotedExtraSpecsStr = extraSpecs.map(function(e) {
return '"' + e + '"';
}).join(" ");

if (process.platform !== 'win32') {

core.startGroup('Installing environment ' + envName + ' from ' + envFilePath + ' ...')
Expand Down Expand Up @@ -118,7 +123,7 @@ async function run () {

// final bits of the install
await execute('mkdir -p ' + path.join(os.homedir(), 'micromamba/pkgs/'))
await execute('source ' + profile + ' && micromamba create -n ' + envName + ' --strict-channel-priority -y -f ' + envFilePath)
await execute('source ' + profile + ' && micromamba create -n ' + envName + ' ' + quotedExtraSpecsStr + ' --strict-channel-priority -y -f ' + envFilePath)
fs.appendFileSync(profile, 'set -eo pipefail\n')
fs.appendFileSync(profile, 'micromamba activate ' + envName + '\n')
core.endGroup()
Expand Down Expand Up @@ -152,7 +157,7 @@ else
// Can only init once right now ...
// await execPwsh("~\\micromamba.exe shell init -s bash -p $HOME\\micromamba")
await execPwsh('MD $HOME\\micromamba\\pkgs -ea 0')
await execPwsh(`~\\micromamba.exe create -n ` + envName + ` --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(`~\\micromamba.exe create -n ` + envName + ' ' + quotedExtraSpecsStr + ` --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(autoactivate)

fs.appendFileSync(profile, `micromamba activate ${envName}\n`)
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba8af56

Please sign in to comment.