Skip to content

Commit

Permalink
Add 'channels' option
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashaag committed Mar 13, 2022
1 parent 2dbade4 commit 0262775
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 38 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: ./
with:
environment-file: false
environment-name: nofile

- name: install mamba
uses: ./
Expand Down Expand Up @@ -88,3 +89,20 @@ jobs:
pytest --version
python -c "import pytest; assert pytest.__version__.startswith(str(${{ matrix.pytest }}))"
if: runner.os != 'Windows'

test_channels:
name: Test channels
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2

- name: install mamba
uses: ./
with:
environment-file: false
environment-name: test-channels
extra-specs: |
xtensor
channels: conda-forge,blah
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GitHub Action to provision a CI instance using micromamba.

### `environment-file`

The environment.yml or .lock file for the conda environment. If 'false', no enviroment will be created (only Micromamba will be installed).
The environment.yml or .lock file for the conda environment. If 'false', no enviroment will be created (only Micromamba will be installed) and you should provide 'channels'.

### `environment-name`

Expand All @@ -24,6 +24,10 @@ The environment.yml or .lock file for the conda environment. If 'false', no envi

(Optional) Additional specifications (packages) to install. Pretty useful when using matrix builds to pin versions of a test/run dependency. For multiple packages, use multiline syntax (see examples). Note that selectors (e.g. `sel(linux): my-linux-package`, `sel(osx): my-osx-package`, `sel(win): my-win-package`) are available.

### `channels`

(Optional) Comma separated list of channels to use in order of priority (eg., `conda-forge,my-private-channel`)

### `cache-downloads`

(Optional) If 'true', cache downloaded packages across calls to the provision-with-micromamba action. Cache invalidation can be controlled using the 'cache-downloads-key' option.
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ inputs:
environment-file:
description: >-
The environment.yml or .lock file for the conda environment.
If 'false', no enviroment will be created (only Micromamba will be installed).
If 'false', no enviroment will be created (only Micromamba will be installed)
and you should provide 'channels'.
required: true
default: environment.yml
environment-name:
Expand All @@ -30,6 +31,11 @@ inputs:
are available.
required: false
default: ""
channels:
description: >-
Comma separated list of channels to use in order of priority (eg., `conda-forge,my-private-channel`)
required: false
default: ""
cache-downloads:
description: >-
If 'true', cache downloaded packages across calls to the provision-with-micromamba action.
Expand Down
41 changes: 23 additions & 18 deletions dist/main/index.js

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

41 changes: 23 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ async function main () {
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'),
Expand All @@ -218,31 +219,33 @@ async function main () {
// cacheEnvAlwaysUpdate: core.getBooleanInput('cache-env-always-update')
cacheEnvAlwaysUpdate: false
}
const micromambaUrl = MICROMAMBA_PLATFORM_URL + inputs.micromambaVersion

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

// .condarc setup
touch(PATHS.condarc)
if (inputs.envFile !== 'false') {
// Read environment file
if (inputs.envFile === 'false') {
if (!inputs.envName) {
throw Error("Must provide 'environment-name' for 'environment-file: false'")
}
} else {
envFilePath = path.join(process.env.GITHUB_WORKSPACE || '', inputs.envFile)
let condarcOpts = `
if (!envFilePath.endsWith('.lock')) {
envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
}
}

// Setup .condarc
touch(PATHS.condarc)
let condarcOpts = `
always_yes: true
show_channel_urls: true
channel_priority: strict
`
if (!envFilePath.endsWith('.lock')) {
const envYaml = yaml.safeLoad(fs.readFileSync(envFilePath, 'utf8'))
if (!envName) {
envName = envYaml.name
}
if (envYaml.channels !== undefined) {
condarcOpts += `channels: [${envYaml.channels.join(', ')}]`
}
}
fs.appendFileSync(PATHS.condarc, condarcOpts)
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
Expand All @@ -253,6 +256,7 @@ channel_priority: strict
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)
Expand All @@ -263,6 +267,7 @@ channel_priority: strict
touch(PATHS.bashprofile)

// Install env
const envName = inputs.envName || envYaml?.name
if (envName) {
core.startGroup(`Install environment ${envName} from ${envFilePath || ''} ${inputs.extraSpecs || ''}...`)
let downloadCacheHit, downloadCacheArgs, envCacheHit, envCacheArgs
Expand Down Expand Up @@ -291,7 +296,7 @@ channel_priority: strict
}

// Add micromamba activate to profile
const autoactivateCmd = `micromamba activate ${envName}`
const autoactivateCmd = `micromamba activate ${envName};`
if (MAMBA_PLATFORM === 'win') {
const powershellAutoActivateEnv = `if (!(Test-Path $profile))
{
Expand Down

0 comments on commit 0262775

Please sign in to comment.