Skip to content

Commit

Permalink
Fix environment-file: false
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashaag committed Mar 10, 2022
1 parent 98bc874 commit bb59c58
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test_caching.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'testenv'"
test_env_fail:
name: Test environment creation failure
name: Test env creation failure
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -133,3 +133,4 @@ jobs:
micromamba <0.1
cache-downloads: ${{ matrix.cache-downloads }}
cache-env: ${{ matrix.cache-env }}
continue-on-error: true
32 changes: 22 additions & 10 deletions dist/main/index.js

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

32 changes: 22 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ function selectSelectors (extraSpecs) {
async function createOrUpdateEnv (envName, envFilePath, extraSpecs) {
const envFolder = path.join(PATHS.micromambaEnvs, envName)
const action = fs.existsSync(envFolder) ? 'update' : 'create'
const selectedExtraSpecs = selectSelectors(extraSpecs)
core.info(`${action} env ${envName}`)
const quotedExtraSpecsStr = selectSelectors(extraSpecs).map(e => `"${e}"`).join(' ')
const cmd = `micromamba ${action} -n ${envName} ${quotedExtraSpecsStr} --strict-channel-priority -y -f ${envFilePath}`
let cmd = `micromamba ${action} -n ${envName} --strict-channel-priority -y`
if (selectedExtraSpecs) {
cmd += ' ' + selectedExtraSpecs.map(e => `"${e}"`).join(' ')
}
if (envFilePath) {
cmd += ' -f ' + envFilePath
}
if (MAMBA_PLATFORM === 'win') {
await executePwsh(cmd)
} else {
Expand All @@ -222,7 +228,8 @@ async function main () {
}
const micromambaUrl = MICROMAMBA_PLATFORM_URL + inputs.micromambaVersion

let envFilePath, envName
let envFilePath
let envName = inputs.envName

// .condarc setup
touch(PATHS.condarc)
Expand All @@ -233,11 +240,11 @@ always_yes: true
show_channel_urls: true
channel_priority: strict
`
if (envFilePath.endsWith('.lock')) {
envName = inputs.envName
} else {
if (!envFilePath.endsWith('.lock')) {
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
envName = inputs.envName || envYaml.name
if (!envName) {
envName = envYaml.name
}
if (envYaml.channels !== undefined) {
condarcOpts += `channels: [${envYaml.channels.join(', ')}]`
}
Expand Down Expand Up @@ -265,13 +272,18 @@ channel_priority: strict

// Install env
if (envName) {
core.startGroup(`Install environment ${envName} from ${envFilePath} ...`)
core.startGroup(`Install environment ${envName} from ${envFilePath || ''} ${inputs.extraSpecs || ''}...`)
let downloadCacheHit, downloadCacheArgs, envCacheHit, envCacheArgs

// Try to load the entire env from cache.
if (inputs.cacheEnv) {
const envHash = sha256Short(fs.readFileSync(envFilePath)) + '-' + sha256Short(JSON.stringify(inputs.extraSpecs))
const key = inputs.cacheEnvKey || `${MAMBA_PLATFORM}-${process.arch} ${today()} ${envHash}`
let key = inputs.cacheEnvKey || `${MAMBA_PLATFORM}-${process.arch} ${today()}`
if (envFilePath) {
key += ' file: ' + sha256Short(fs.readFileSync(envFilePath))
}
if (inputs.extraSpecs) {
key += ' extra: ' + sha256Short(JSON.stringify(inputs.extraSpecs))
}
envCacheArgs = [path.join(PATHS.micromambaEnvs, envName), `micromamba-env ${key}`]
envCacheHit = await tryRestoreCache(...envCacheArgs)
}
Expand Down

0 comments on commit bb59c58

Please sign in to comment.