Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix environment-name behaviour (#50, #54) and add Docker support (#46) #55

Merged
merged 18 commits into from
May 14, 2022
Prev Previous commit
Next Next commit
Fix #54
  • Loading branch information
jonashaag committed May 12, 2022
commit 90c7348d490e3c810026d413dfc724fd27d8ea62
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: install binary only
uses: ./
with:
environment-file: false

- name: install mamba
uses: ./

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ jobs:
- name: install mamba
uses: ./
with:
environment-name: noname
environment-file: .github/workflows/resources/environment_without_name.yml

- run: micromamba list | grep -q xtensor
- run: micromamba list -n noname | grep -q xtensor
shell: bash

test_extra_specs:
Expand Down
118 changes: 65 additions & 53 deletions dist/main/index.js

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

118 changes: 65 additions & 53 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,44 @@ async function createOrUpdateEnv (envName, envFilePath, extraSpecs) {
}
}

async function main () {
const inputs = {
micromambaVersion: core.getInput('micromamba-version'),
envName: core.getInput('environment-name'),
envFile: core.getInput('environment-file'),
extraSpecs: getInputAsArray('extra-specs'),
channels: core.getInput('channels'),
cacheDownloads: core.getBooleanInput('cache-downloads'),
cacheDownloadsKey: core.getInput('cache-downloads-key'),
cacheEnv: core.getBooleanInput('cache-env'),
cacheEnvKey: core.getInput('cache-env-key'),
// Not implemented
// cacheEnvAlwaysUpdate: core.getBooleanInput('cache-env-always-update')
cacheEnvAlwaysUpdate: false
async function installMicromamba (inputs, extraChannels) {
// Setup .condarc
touch(PATHS.condarc)
let condarcOpts = `
always_yes: true
show_channel_urls: true
channel_priority: strict
`
const channels = inputs.channels + (extraChannels || []).join(', ')
if (channels) {
condarcOpts += `channels: [${channels}]`
}
fs.appendFileSync(PATHS.condarc, condarcOpts)
core.debug(`Contents of ${PATHS.condarc}:\n${fs.readFileSync(PATHS.condarc)}`)

// Read environment file
let envFilePath, envYaml
if (inputs.envFile !== 'false') {
envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', inputs.envFile)
if (!envFilePath.endsWith('.lock')) {
envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
}
// Install micromamba
if (!fs.existsSync(PATHS.micromambaBinFolder)) {
core.startGroup('Install micromamba ...')
const installer = {
win: installMicromambaWindows,
linux: installMicromambaPosix,
osx: installMicromambaPosix
}[MAMBA_PLATFORM]
const micromambaUrl = MICROMAMBA_PLATFORM_URL + inputs.micromambaVersion
await installer(micromambaUrl)
core.exportVariable('MAMBA_ROOT_PREFIX', PATHS.micromambaRoot)
core.exportVariable('MAMBA_EXE', PATHS.micromambaExe)
core.addPath(PATHS.micromambaBinFolder)
core.endGroup()
}

touch(PATHS.bashprofile)
}

async function installEnvironment (inputs, envFilePath, envYaml) {
if (!envFilePath && !envYaml.extraSpecs) {
// Nothing to install
return
}

// Determine environment name
Expand Down Expand Up @@ -281,38 +296,6 @@ async function main () {
}
}

// Setup .condarc
touch(PATHS.condarc)
let condarcOpts = `
always_yes: true
show_channel_urls: true
channel_priority: strict
`
const channels = inputs.channels + (envYaml?.channels || []).join(', ')
if (channels) {
condarcOpts += `channels: [${channels}]`
}
fs.appendFileSync(PATHS.condarc, condarcOpts)
core.debug(`Contents of ${PATHS.condarc}:\n${fs.readFileSync(PATHS.condarc)}`)

// Install micromamba
if (!fs.existsSync(PATHS.micromambaBinFolder)) {
core.startGroup('Install micromamba ...')
const installer = {
win: installMicromambaWindows,
linux: installMicromambaPosix,
osx: installMicromambaPosix
}[MAMBA_PLATFORM]
const micromambaUrl = MICROMAMBA_PLATFORM_URL + inputs.micromambaVersion
await installer(micromambaUrl)
core.exportVariable('MAMBA_ROOT_PREFIX', PATHS.micromambaRoot)
core.exportVariable('MAMBA_EXE', PATHS.micromambaExe)
core.addPath(PATHS.micromambaBinFolder)
core.endGroup()
}

touch(PATHS.bashprofile)

// Install env
if (envFilePath || inputs.extraSpecs) {
core.startGroup(`Install environment ${envName} from ${envFilePath || ''} ${inputs.extraSpecs || ''}...`)
Expand Down Expand Up @@ -370,6 +353,35 @@ Write-Host "Profile already exists and new content added"
}
core.endGroup()
}
}

async function main () {
const inputs = {
micromambaVersion: core.getInput('micromamba-version'),
envName: core.getInput('environment-name'),
envFile: core.getInput('environment-file'),
extraSpecs: getInputAsArray('extra-specs'),
channels: core.getInput('channels'),
cacheDownloads: core.getBooleanInput('cache-downloads'),
cacheDownloadsKey: core.getInput('cache-downloads-key'),
cacheEnv: core.getBooleanInput('cache-env'),
cacheEnvKey: core.getInput('cache-env-key'),
// Not implemented
// cacheEnvAlwaysUpdate: core.getBooleanInput('cache-env-always-update')
cacheEnvAlwaysUpdate: false
}

// Read environment file
let envFilePath, envYaml
if (inputs.envFile !== 'false') {
envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', inputs.envFile)
if (!envFilePath.endsWith('.lock')) {
envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
}
}

await installMicromamba(inputs, envYaml?.channels)
await installEnvironment(inputs, envFilePath, envYaml)

// Show environment info
core.startGroup('Environment info')
Expand Down