Skip to content

Commit 76399eb

Browse files
authored
BUG download to another location (#9)
1 parent 92310b9 commit 76399eb

File tree

4 files changed

+69
-160
lines changed

4 files changed

+69
-160
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ jobs:
2525
python -VV
2626
python -c "import numpy"
2727
if: runner.os == 'Windows'
28+
2829
- name: run python in bash
2930
shell: bash -l {0}
3031
run: |
3132
python -VV
3233
python -c "import numpy"
34+
micromamba --help
3335
if: runner.os != 'Windows'

dist/index.js

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function execute (command) {
2525
}
2626
}
2727

28-
async function exec_pwsh (command) {
28+
async function execPwsh (command) {
2929
try {
3030
await exec('powershell', ['-command', command])
3131
} catch (error) {
@@ -46,7 +46,7 @@ function touch (filename) {
4646

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

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

7474
touch(profile)
7575

76-
if (process.platform === 'darwin')
77-
{
76+
await execute('mkdir -p ' + path.join(os.homedir(), 'micromamba-bin/'))
77+
78+
if (process.platform === 'darwin') {
7879
// macos
7980
try {
80-
await executeNoCatch(`curl -Ls ${base_url}/osx-64/latest | tar -xvj bin/micromamba`)
81+
await executeNoCatch(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
8182
} catch (error) {
82-
await execute(`curl -Ls ${base_url}/osx-64/latest | tar -xvz bin/micromamba`)
83+
await execute(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
8384
}
84-
await execute('mv ./bin/micromamba ./micromamba')
85-
await execute('rm -rf ./bin')
86-
await execute('./micromamba shell init -s bash -p ~/micromamba')
87-
}
88-
else if (process.platform === 'linux')
89-
{
85+
await execute(`chmod u+x ${micromambaLoc}`)
86+
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
87+
} else if (process.platform === 'linux') {
9088
// linux
9189
try {
92-
await executeNoCatch(`wget -qO- ${base_url}/linux-64/latest | tar -xvj bin/micromamba --strip-components=1`)
90+
await executeNoCatch(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
9391
} catch (error) {
94-
await execute(`wget -qO- ${base_url}/linux-64/latest | tar -xvz bin/micromamba --strip-components=1`)
92+
await execute(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
9593
}
94+
await execute(`chmod u+x ${micromambaLoc}`)
9695

9796
// on linux we move the bashrc to a backup and then restore
9897
await execute('mv ' + bashrc + ' ' + bashrcBak)
9998
touch(bashrc)
10099
try {
101-
await execute('./micromamba shell init -s bash -p ~/micromamba')
100+
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
102101
fs.appendFileSync(profile, '\n' + fs.readFileSync(bashrc, 'utf8'), 'utf8')
103102
await execute('mv ' + bashrcBak + ' ' + bashrc)
104103
} catch (error) {
105104
await execute('mv ' + bashrcBak + ' ' + bashrc)
106105
core.setFailed(error.message)
107106
}
108107
} else {
109-
throw 'Platform ' + process.platform + ' not supported.';
108+
core.setFailed('Platform ' + process.platform + ' not supported.')
110109
}
111110

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

119118
await execute('source ' + profile + ' && micromamba list')
120-
}
121-
else
122-
{
119+
} else {
123120
// handle win32!
124-
const powershell_auto_activate_env = `if (!(Test-Path $profile))
121+
const powershellAutoActivateEnv = `if (!(Test-Path $profile))
125122
{
126123
New-Item -path $profile -type "file" -value "CONTENTPLACEHOLDER"
127124
Write-Host "Created new profile and content added"
@@ -130,27 +127,27 @@ else
130127
{
131128
Add-Content -path $profile -value "CONTENTPLACEHOLDER"
132129
Write-Host "Profile already exists and new content added"
133-
}`;
134-
const autoactivate = powershell_auto_activate_env.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`);
135-
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`);
130+
}`
131+
const autoactivate = powershellAutoActivateEnv.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`)
132+
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`)
136133
touch(profile)
137134

138-
await exec_pwsh(`Invoke-Webrequest -URI ${base_url}/win-64/latest -OutFile micromamba.tar.bz2`);
139-
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa");
140-
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe");
141-
await exec_pwsh("MOVE -Force Library\\bin\\micromamba.exe micromamba.exe");
142-
await exec_pwsh(".\\micromamba.exe --help");
143-
await exec_pwsh(".\\micromamba.exe shell init -s powershell -p $HOME\\micromamba");
135+
await execPwsh(`Invoke-Webrequest -URI ${baseUrl}/win-64/latest -OutFile micromamba.tar.bz2`)
136+
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa')
137+
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe')
138+
await execPwsh('MOVE -Force Library\\bin\\micromamba.exe micromamba.exe')
139+
await execPwsh('.\\micromamba.exe --help')
140+
await execPwsh('.\\micromamba.exe shell init -s powershell -p $HOME\\micromamba')
144141
// Can only init once right now ...
145-
// await exec_pwsh(".\\micromamba.exe shell init -s bash -p $HOME\\micromamba");
146-
await exec_pwsh("MD $HOME\\micromamba\\pkgs -ea 0");
147-
await exec_pwsh(`.\\micromamba.exe create --strict-channel-priority -y -f ${envFilePath}`);
148-
await exec_pwsh(autoactivate);
142+
// await execPwsh(".\\micromamba.exe shell init -s bash -p $HOME\\micromamba")
143+
await execPwsh('MD $HOME\\micromamba\\pkgs -ea 0')
144+
await execPwsh(`.\\micromamba.exe create --strict-channel-priority -y -f ${envFilePath}`)
145+
await execPwsh(autoactivate)
149146

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

152149
core.endGroup()
153-
await exec_pwsh('micromamba list')
150+
await execPwsh('micromamba list')
154151
}
155152
} catch (error) {
156153
core.setFailed(error.message)

index.js

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function execute (command) {
1818
}
1919
}
2020

21-
async function exec_pwsh (command) {
21+
async function execPwsh (command) {
2222
try {
2323
await exec('powershell', ['-command', command])
2424
} catch (error) {
@@ -39,7 +39,7 @@ function touch (filename) {
3939

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

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

6767
touch(profile)
6868

69-
if (process.platform === 'darwin')
70-
{
69+
await execute('mkdir -p ' + path.join(os.homedir(), 'micromamba-bin/'))
70+
71+
if (process.platform === 'darwin') {
7172
// macos
7273
try {
73-
await executeNoCatch(`curl -Ls ${base_url}/osx-64/latest | tar -xvj bin/micromamba`)
74+
await executeNoCatch(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
7475
} catch (error) {
75-
await execute(`curl -Ls ${base_url}/osx-64/latest | tar -xvz bin/micromamba`)
76+
await execute(`curl -Ls ${baseUrl}/osx-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
7677
}
77-
await execute('mv ./bin/micromamba ./micromamba')
78-
await execute('rm -rf ./bin')
79-
await execute('./micromamba shell init -s bash -p ~/micromamba')
80-
}
81-
else if (process.platform === 'linux')
82-
{
78+
await execute(`chmod u+x ${micromambaLoc}`)
79+
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
80+
} else if (process.platform === 'linux') {
8381
// linux
8482
try {
85-
await executeNoCatch(`wget -qO- ${base_url}/linux-64/latest | tar -xvj bin/micromamba --strip-components=1`)
83+
await executeNoCatch(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvjO bin/micromamba > ${micromambaLoc}`)
8684
} catch (error) {
87-
await execute(`wget -qO- ${base_url}/linux-64/latest | tar -xvz bin/micromamba --strip-components=1`)
85+
await execute(`wget -qO- ${baseUrl}/linux-64/latest | tar -xvzO bin/micromamba > ${micromambaLoc}`)
8886
}
87+
await execute(`chmod u+x ${micromambaLoc}`)
8988

9089
// on linux we move the bashrc to a backup and then restore
9190
await execute('mv ' + bashrc + ' ' + bashrcBak)
9291
touch(bashrc)
9392
try {
94-
await execute('./micromamba shell init -s bash -p ~/micromamba')
93+
await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba`)
9594
fs.appendFileSync(profile, '\n' + fs.readFileSync(bashrc, 'utf8'), 'utf8')
9695
await execute('mv ' + bashrcBak + ' ' + bashrc)
9796
} catch (error) {
9897
await execute('mv ' + bashrcBak + ' ' + bashrc)
9998
core.setFailed(error.message)
10099
}
101100
} else {
102-
throw 'Platform ' + process.platform + ' not supported.';
101+
core.setFailed('Platform ' + process.platform + ' not supported.')
103102
}
104103

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

112111
await execute('source ' + profile + ' && micromamba list')
113-
}
114-
else
115-
{
112+
} else {
116113
// handle win32!
117-
const powershell_auto_activate_env = `if (!(Test-Path $profile))
114+
const powershellAutoActivateEnv = `if (!(Test-Path $profile))
118115
{
119116
New-Item -path $profile -type "file" -value "CONTENTPLACEHOLDER"
120117
Write-Host "Created new profile and content added"
@@ -123,27 +120,27 @@ else
123120
{
124121
Add-Content -path $profile -value "CONTENTPLACEHOLDER"
125122
Write-Host "Profile already exists and new content added"
126-
}`;
127-
const autoactivate = powershell_auto_activate_env.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`);
128-
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`);
123+
}`
124+
const autoactivate = powershellAutoActivateEnv.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`)
125+
core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`)
129126
touch(profile)
130127

131-
await exec_pwsh(`Invoke-Webrequest -URI ${base_url}/win-64/latest -OutFile micromamba.tar.bz2`);
132-
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa");
133-
await exec_pwsh("C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe");
134-
await exec_pwsh("MOVE -Force Library\\bin\\micromamba.exe micromamba.exe");
135-
await exec_pwsh(".\\micromamba.exe --help");
136-
await exec_pwsh(".\\micromamba.exe shell init -s powershell -p $HOME\\micromamba");
128+
await execPwsh(`Invoke-Webrequest -URI ${baseUrl}/win-64/latest -OutFile micromamba.tar.bz2`)
129+
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa')
130+
await execPwsh('C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe')
131+
await execPwsh('MOVE -Force Library\\bin\\micromamba.exe micromamba.exe')
132+
await execPwsh('.\\micromamba.exe --help')
133+
await execPwsh('.\\micromamba.exe shell init -s powershell -p $HOME\\micromamba')
137134
// Can only init once right now ...
138-
// await exec_pwsh(".\\micromamba.exe shell init -s bash -p $HOME\\micromamba");
139-
await exec_pwsh("MD $HOME\\micromamba\\pkgs -ea 0");
140-
await exec_pwsh(`.\\micromamba.exe create --strict-channel-priority -y -f ${envFilePath}`);
141-
await exec_pwsh(autoactivate);
135+
// await execPwsh(".\\micromamba.exe shell init -s bash -p $HOME\\micromamba")
136+
await execPwsh('MD $HOME\\micromamba\\pkgs -ea 0')
137+
await execPwsh(`.\\micromamba.exe create --strict-channel-priority -y -f ${envFilePath}`)
138+
await execPwsh(autoactivate)
142139

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

145142
core.endGroup()
146-
await exec_pwsh('micromamba list')
143+
await execPwsh('micromamba list')
147144
}
148145
} catch (error) {
149146
core.setFailed(error.message)

package-lock.json

Lines changed: 1 addition & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)