Skip to content

Commit

Permalink
initialize more shells and add condarc generation on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed May 10, 2021
1 parent 97bab46 commit 3ac5602
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 19 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ jobs:
run: |
python -VV
python -c "import numpy"
echo "MAMBA_EXE=$Env:MAMBA_EXE"
if: runner.os == 'Windows'

- name: run python in cmd.exe
shell: cmd
run: |
python -VV
python -c "import numpy"
micromamba --help
echo "MAMBA_EXE=%MAMBA_EXE%"
if: runner.os == 'Windows'

- name: run python in bash
Expand All @@ -32,4 +42,13 @@ jobs:
python -VV
python -c "import numpy"
micromamba --help
if: runner.os != 'Windows'
echo "MAMBA_EXE=$MAMBA_EXE"
- name: run python in zsh
shell: zsh -l {0}
run: |
python -VV
python -c "import numpy"
micromamba --help
echo "MAMBA_EXE=$MAMBA_EXE"
if: runner.os == 'macOS'
38 changes: 38 additions & 0 deletions .github/workflows/test_bash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: bash
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]

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

name: bash
steps:
- uses: actions/checkout@v2

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

- name: run python
run: |
python -VV
python -c "import numpy"
micromamba --help
- name: test environment name
run: |
python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'myenv'"
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inputs:
micromamba-version:
description: 'version of micromamba to use (default: 0.9.2). Use "latest" for bleeding edge.'
required: false
default: "0.9.2"
default: "0.12.2"

runs:
using: 'node12'
Expand Down
40 changes: 28 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,27 @@ async function run () {
const bashrcBak = path.join(os.homedir(), '.bashrc.actionbak')
const micromambaLoc = path.join(os.homedir(), 'micromamba-bin/micromamba')

if (process.platform !== 'win32') {
core.startGroup('Configuring conda...')
touch(condarc)
fs.appendFileSync(condarc, 'always_yes: true\n')
fs.appendFileSync(condarc, 'show_channel_urls: true\n')
fs.appendFileSync(condarc, 'channel_priority: strict\n')
if (envYaml.channels !== undefined) {
fs.appendFileSync(condarc, 'channels: [' + envYaml.channels.join(', ') + ']\n')
}
core.startGroup('Configuring micromamba...')
touch(condarc)
fs.appendFileSync(condarc, 'always_yes: true\n')
fs.appendFileSync(condarc, 'show_channel_urls: true\n')
fs.appendFileSync(condarc, 'channel_priority: strict\n')
if (envYaml.channels !== undefined) {
fs.appendFileSync(condarc, 'channels: [' + envYaml.channels.join(', ') + ']\n')
}
if (process.platform !== 'win32')
{
await execute('cat ' + condarc)
core.endGroup()
}
else
{
await execute('cat $(cygpath "' + condarc + '")')

// await execute('type ' + condarc)
}
core.endGroup()

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

core.startGroup('Installing environment ' + envName + ' from ' + envFilePath + ' ...')

Expand All @@ -84,7 +94,10 @@ async function run () {
await execute(`curl -Ls ${baseUrl}/osx-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`)
}
await execute(`chmod u+x ${micromambaLoc}`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba -y`)
// TODO need to fix a check in micromamba so that this works
// https://github.com/mamba-org/mamba/issues/925
// await execute(`${micromambaLoc} shell init -s zsh -p ~/micromamba -y`)
} else if (process.platform === 'linux') {
// linux
try {
Expand All @@ -98,7 +111,8 @@ async function run () {
await execute('mv ' + bashrc + ' ' + bashrcBak)
touch(bashrc)
try {
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba -y`)
await execute(`${micromambaLoc} shell init -s zsh -p ~/micromamba -y`)
fs.appendFileSync(profile, '\n' + fs.readFileSync(bashrc, 'utf8'), 'utf8')
await execute('mv ' + bashrcBak + ' ' + bashrc)
} catch (error) {
Expand Down Expand Up @@ -139,6 +153,8 @@ else
await execPwsh('MOVE -Force Library\\bin\\micromamba.exe micromamba.exe')
await execPwsh('.\\micromamba.exe --help')
await execPwsh('.\\micromamba.exe shell init -s powershell -p $HOME\\micromamba')
await execPwsh('.\\micromamba.exe shell init -s bash -p ~\\micromamba -y')
await execPwsh('.\\micromamba.exe shell init -s cmd.exe -p ~\\micromamba -y')
// 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')
Expand Down
25 changes: 20 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,27 @@ async function run () {
const bashrcBak = path.join(os.homedir(), '.bashrc.actionbak')
const micromambaLoc = path.join(os.homedir(), 'micromamba-bin/micromamba')

core.startGroup('Configuring micromamba...')
touch(condarc)
fs.appendFileSync(condarc, 'always_yes: true\n')
fs.appendFileSync(condarc, 'show_channel_urls: true\n')
fs.appendFileSync(condarc, 'channel_priority: strict\n')
if (envYaml.channels !== undefined) {
fs.appendFileSync(condarc, 'channels: [' + envYaml.channels.join(', ') + ']\n')
}
if (process.platform !== 'win32')
{
await execute('cat ' + condarc)
}
else
{
await execute('cat $(cygpath "' + condarc + '")')

// await execute('type ' + condarc)
}
core.endGroup()

if (process.platform !== 'win32') {
core.startGroup('Configuring micromamba...')
await execute('cat ' + condarc)
core.endGroup()

core.startGroup('Installing environment ' + envName + ' from ' + envFilePath + ' ...')

Expand All @@ -78,7 +87,10 @@ async function run () {
await execute(`curl -Ls ${baseUrl}/osx-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`)
}
await execute(`chmod u+x ${micromambaLoc}`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba -y`)
// TODO need to fix a check in micromamba so that this works
// https://github.com/mamba-org/mamba/issues/925
// await execute(`${micromambaLoc} shell init -s zsh -p ~/micromamba -y`)
} else if (process.platform === 'linux') {
// linux
try {
Expand All @@ -92,7 +104,8 @@ async function run () {
await execute('mv ' + bashrc + ' ' + bashrcBak)
touch(bashrc)
try {
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba -y`)
await execute(`${micromambaLoc} shell init -s zsh -p ~/micromamba -y`)
fs.appendFileSync(profile, '\n' + fs.readFileSync(bashrc, 'utf8'), 'utf8')
await execute('mv ' + bashrcBak + ' ' + bashrc)
} catch (error) {
Expand Down Expand Up @@ -133,6 +146,8 @@ else
await execPwsh('MOVE -Force Library\\bin\\micromamba.exe micromamba.exe')
await execPwsh('.\\micromamba.exe --help')
await execPwsh('.\\micromamba.exe shell init -s powershell -p $HOME\\micromamba')
await execPwsh('.\\micromamba.exe shell init -s bash -p ~\\micromamba -y')
await execPwsh('.\\micromamba.exe shell init -s cmd.exe -p ~\\micromamba -y')
// 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')
Expand Down

0 comments on commit 3ac5602

Please sign in to comment.