Skip to content

Commit

Permalink
BUG download to another location (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr authored Jan 14, 2021
1 parent 92310b9 commit 76399eb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 160 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ jobs:
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'
69 changes: 33 additions & 36 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function execute (command) {
}
}

async function exec_pwsh (command) {
async function execPwsh (command) {
try {
await exec('powershell', ['-command', command])
} catch (error) {
Expand All @@ -46,7 +46,7 @@ function touch (filename) {

async function run () {
try {
const base_url = 'https://micro.mamba.pm/api/micromamba'
const baseUrl = 'https://micro.mamba.pm/api/micromamba'
const envFileName = core.getInput('environment-file')
const envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', envFileName)
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
Expand All @@ -55,9 +55,9 @@ async function run () {
const profile = path.join(os.homedir(), '.bash_profile')
const bashrc = path.join(os.homedir(), '.bashrc')
const bashrcBak = path.join(os.homedir(), '.bashrc.actionbak')
const micromambaLoc = path.join(os.homedir(), 'micromamba-bin/micromamba')

if (process.platform !== 'win32')
{
if (process.platform !== 'win32') {
core.startGroup('Configuring conda...')
touch(condarc)
fs.appendFileSync(condarc, 'always_yes: true\n')
Expand All @@ -73,40 +73,39 @@ async function run () {

touch(profile)

if (process.platform === 'darwin')
{
await execute('mkdir -p ' + path.join(os.homedir(), 'micromamba-bin/'))

if (process.platform === 'darwin') {
// macos
try {
await executeNoCatch(`curl -Ls ${base_url}/osx-64/latest | tar -xvj bin/micromamba`)
await executeNoCatch(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
} catch (error) {
await execute(`curl -Ls ${base_url}/osx-64/latest | tar -xvz bin/micromamba`)
await execute(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
}
await execute('mv ./bin/micromamba ./micromamba')
await execute('rm -rf ./bin')
await execute('./micromamba shell init -s bash -p ~/micromamba')
}
else if (process.platform === 'linux')
{
await execute(`chmod u+x ${micromambaLoc}`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
} else if (process.platform === 'linux') {
// linux
try {
await executeNoCatch(`wget -qO- ${base_url}/linux-64/latest | tar -xvj bin/micromamba --strip-components=1`)
await executeNoCatch(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
} catch (error) {
await execute(`wget -qO- ${base_url}/linux-64/latest | tar -xvz bin/micromamba --strip-components=1`)
await execute(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
}
await execute(`chmod u+x ${micromambaLoc}`)

// on linux we move the bashrc to a backup and then restore
await execute('mv ' + bashrc + ' ' + bashrcBak)
touch(bashrc)
try {
await execute('./micromamba shell init -s bash -p ~/micromamba')
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
fs.appendFileSync(profile, '\n' + fs.readFileSync(bashrc, 'utf8'), 'utf8')
await execute('mv ' + bashrcBak + ' ' + bashrc)
} catch (error) {
await execute('mv ' + bashrcBak + ' ' + bashrc)
core.setFailed(error.message)
}
} else {
throw 'Platform ' + process.platform + ' not supported.';
core.setFailed('Platform ' + process.platform + ' not supported.')
}

// final bits of the install
Expand All @@ -117,11 +116,9 @@ async function run () {
core.endGroup()

await execute('source ' + profile + ' && micromamba list')
}
else
{
} else {
// handle win32!
const powershell_auto_activate_env = `if (!(Test-Path $profile))
const powershellAutoActivateEnv = `if (!(Test-Path $profile))
{
New-Item -path $profile -type "file" -value "CONTENTPLACEHOLDER"
Write-Host "Created new profile and content added"
Expand All @@ -130,27 +127,27 @@ else
{
Add-Content -path $profile -value "CONTENTPLACEHOLDER"
Write-Host "Profile already exists and new content added"
}`;
const autoactivate = powershell_auto_activate_env.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`);
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`);
}`
const autoactivate = powershellAutoActivateEnv.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`)
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`)
touch(profile)

await exec_pwsh(`Invoke-Webrequest -URI ${base_url}/win-64/latest -OutFile micromamba.tar.bz2`);
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa");
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe");
await exec_pwsh("MOVE -Force Library\\bin\\micromamba.exe micromamba.exe");
await exec_pwsh(".\\micromamba.exe --help");
await exec_pwsh(".\\micromamba.exe shell init -s powershell -p $HOME\\micromamba");
await execPwsh(`Invoke-Webrequest -URI ${baseUrl}/win-64/latest -OutFile micromamba.tar.bz2`)
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa')
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe')
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')
// Can only init once right now ...
// await exec_pwsh(".\\micromamba.exe shell init -s bash -p $HOME\\micromamba");
await exec_pwsh("MD $HOME\\micromamba\\pkgs -ea 0");
await exec_pwsh(`.\\micromamba.exe create --strict-channel-priority -y -f ${envFilePath}`);
await exec_pwsh(autoactivate);
// 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(autoactivate)

fs.appendFileSync(profile, `micromamba activate ${envName}\n`)

core.endGroup()
await exec_pwsh('micromamba list')
await execPwsh('micromamba list')
}
} catch (error) {
core.setFailed(error.message)
Expand Down
69 changes: 33 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function execute (command) {
}
}

async function exec_pwsh (command) {
async function execPwsh (command) {
try {
await exec('powershell', ['-command', command])
} catch (error) {
Expand All @@ -39,7 +39,7 @@ function touch (filename) {

async function run () {
try {
const base_url = 'https://micro.mamba.pm/api/micromamba'
const baseUrl = 'https://micro.mamba.pm/api/micromamba'
const envFileName = core.getInput('environment-file')
const envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', envFileName)
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
Expand All @@ -48,9 +48,9 @@ async function run () {
const profile = path.join(os.homedir(), '.bash_profile')
const bashrc = path.join(os.homedir(), '.bashrc')
const bashrcBak = path.join(os.homedir(), '.bashrc.actionbak')
const micromambaLoc = path.join(os.homedir(), 'micromamba-bin/micromamba')

if (process.platform !== 'win32')
{
if (process.platform !== 'win32') {
core.startGroup('Configuring conda...')
touch(condarc)
fs.appendFileSync(condarc, 'always_yes: true\n')
Expand All @@ -66,40 +66,39 @@ async function run () {

touch(profile)

if (process.platform === 'darwin')
{
await execute('mkdir -p ' + path.join(os.homedir(), 'micromamba-bin/'))

if (process.platform === 'darwin') {
// macos
try {
await executeNoCatch(`curl -Ls ${base_url}/osx-64/latest | tar -xvj bin/micromamba`)
await executeNoCatch(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
} catch (error) {
await execute(`curl -Ls ${base_url}/osx-64/latest | tar -xvz bin/micromamba`)
await execute(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
}
await execute('mv ./bin/micromamba ./micromamba')
await execute('rm -rf ./bin')
await execute('./micromamba shell init -s bash -p ~/micromamba')
}
else if (process.platform === 'linux')
{
await execute(`chmod u+x ${micromambaLoc}`)
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
} else if (process.platform === 'linux') {
// linux
try {
await executeNoCatch(`wget -qO- ${base_url}/linux-64/latest | tar -xvj bin/micromamba --strip-components=1`)
await executeNoCatch(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
} catch (error) {
await execute(`wget -qO- ${base_url}/linux-64/latest | tar -xvz bin/micromamba --strip-components=1`)
await execute(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
}
await execute(`chmod u+x ${micromambaLoc}`)

// on linux we move the bashrc to a backup and then restore
await execute('mv ' + bashrc + ' ' + bashrcBak)
touch(bashrc)
try {
await execute('./micromamba shell init -s bash -p ~/micromamba')
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
fs.appendFileSync(profile, '\n' + fs.readFileSync(bashrc, 'utf8'), 'utf8')
await execute('mv ' + bashrcBak + ' ' + bashrc)
} catch (error) {
await execute('mv ' + bashrcBak + ' ' + bashrc)
core.setFailed(error.message)
}
} else {
throw 'Platform ' + process.platform + ' not supported.';
core.setFailed('Platform ' + process.platform + ' not supported.')
}

// final bits of the install
Expand All @@ -110,11 +109,9 @@ async function run () {
core.endGroup()

await execute('source ' + profile + ' && micromamba list')
}
else
{
} else {
// handle win32!
const powershell_auto_activate_env = `if (!(Test-Path $profile))
const powershellAutoActivateEnv = `if (!(Test-Path $profile))
{
New-Item -path $profile -type "file" -value "CONTENTPLACEHOLDER"
Write-Host "Created new profile and content added"
Expand All @@ -123,27 +120,27 @@ else
{
Add-Content -path $profile -value "CONTENTPLACEHOLDER"
Write-Host "Profile already exists and new content added"
}`;
const autoactivate = powershell_auto_activate_env.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`);
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`);
}`
const autoactivate = powershellAutoActivateEnv.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`)
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`)
touch(profile)

await exec_pwsh(`Invoke-Webrequest -URI ${base_url}/win-64/latest -OutFile micromamba.tar.bz2`);
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa");
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe");
await exec_pwsh("MOVE -Force Library\\bin\\micromamba.exe micromamba.exe");
await exec_pwsh(".\\micromamba.exe --help");
await exec_pwsh(".\\micromamba.exe shell init -s powershell -p $HOME\\micromamba");
await execPwsh(`Invoke-Webrequest -URI ${baseUrl}/win-64/latest -OutFile micromamba.tar.bz2`)
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa')
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe')
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')
// Can only init once right now ...
// await exec_pwsh(".\\micromamba.exe shell init -s bash -p $HOME\\micromamba");
await exec_pwsh("MD $HOME\\micromamba\\pkgs -ea 0");
await exec_pwsh(`.\\micromamba.exe create --strict-channel-priority -y -f ${envFilePath}`);
await exec_pwsh(autoactivate);
// 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(autoactivate)

fs.appendFileSync(profile, `micromamba activate ${envName}\n`)

core.endGroup()
await exec_pwsh('micromamba list')
await execPwsh('micromamba list')
}
} catch (error) {
core.setFailed(error.message)
Expand Down
89 changes: 1 addition & 88 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 76399eb

Please sign in to comment.