Skip to content

Commit

Permalink
Merge pull request #12 from tdegeus/patch
Browse files Browse the repository at this point in the history
Adding environment-name option
  • Loading branch information
beckermr authored Feb 24, 2021
2 parents 76399eb + b018b71 commit 0f7b39a
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 7 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: options
on:
push:
branches:
- main
pull_request: null

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
name: option
steps:
- uses: actions/checkout@v2

- name: install mamba
uses: ./
with:
environment-file: environment.yml
environment-name: myenv

- name: run python in powershell
shell: powershell
run: |
python -VV
python -c "import numpy"
if: runner.os == 'Windows'

- name: run python in bash
shell: bash -l {0}
run: |
python -VV
python -c "import numpy"
micromamba --help
if: runner.os != 'Windows'

- name: test environment name in powershell
shell: powershell
run: |
python -c "import os; env = os.environ['CONDA_PREFIX'].split('\\')[-1]; assert env == 'myenv'"
if: runner.os == 'Windows'

- name: test environment name in bash
shell: bash -l {0}
run: |
python -c "import os; env = os.environ['CONDA_PREFIX'].split('/')[-1]; assert env == 'myenv'"
if: runner.os != 'Windows'
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ GitHub Action to provision a CI instance using micromamba

**Optional** The the `environment.yml` file for the conda environment. Default is `environment.yml`

### `environment-name`

**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`.

## Example usage

```
Expand Down Expand Up @@ -39,6 +45,27 @@ jobs:
python -c "import numpy"
```

## Example with customization

```
name: test
on:
push: null
jobs:
test:
runs-on: ubuntu-latest
name: test
steps:
- uses: actions/checkout@v2
- name: install mamba
uses: mamba-org/provision-with-micromamba@main
with:
- environment-file: myenv.yaml
- environment-name: myenv
```

## Development

When developing, you need to
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
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)'
required: false
runs:
using: 'node12'
main: 'dist/index.js'
6 changes: 3 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function run () {
const envFileName = core.getInput('environment-file')
const envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', envFileName)
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
const envName = envYaml.name
const envName = core.getInput('environment-name') || envYaml.name
const condarc = path.join(os.homedir(), '.condarc')
const profile = path.join(os.homedir(), '.bash_profile')
const bashrc = path.join(os.homedir(), '.bashrc')
Expand Down Expand Up @@ -110,7 +110,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 --strict-channel-priority -y -f ' + envFilePath)
await execute('source ' + profile + ' && micromamba create -n ' + envName + ' --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 @@ -141,7 +141,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 --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(`.\\micromamba.exe create -n ` + envName + ` --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(autoactivate)

fs.appendFileSync(profile, `micromamba activate ${envName}\n`)
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function run () {
const envFileName = core.getInput('environment-file')
const envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', envFileName)
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
const envName = envYaml.name
const envName = core.getInput('environment-name') || envYaml.name
const condarc = path.join(os.homedir(), '.condarc')
const profile = path.join(os.homedir(), '.bash_profile')
const bashrc = path.join(os.homedir(), '.bashrc')
Expand Down Expand Up @@ -103,7 +103,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 --strict-channel-priority -y -f ' + envFilePath)
await execute('source ' + profile + ' && micromamba create -n ' + envName + ' --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 @@ -134,7 +134,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 --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(`.\\micromamba.exe create -n ` + envName + ` --strict-channel-priority -y -f ${envFilePath}`)
await execPwsh(autoactivate)

fs.appendFileSync(profile, `micromamba activate ${envName}\n`)
Expand Down
89 changes: 88 additions & 1 deletion package-lock.json

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

0 comments on commit 0f7b39a

Please sign in to comment.