Skip to content

Commit

Permalink
Adding selectors to "extra-specs"
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Mar 2, 2022
1 parent 1876988 commit 846e2e8
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/test_extra-specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Test extra-specs
on:
push:
branches:
- main
pull_request: null

jobs:
test:
name: Test extra-specs
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2

- name: install mamba
uses: ./
with:
environment-file: environment.yml
environment-name: myenv
extra-specs: |
click
sel(linux): xtensor
sel(osx): cmake
sel(win): ninja
- name: list environment
run: |
micromamba list
- name: check presence
if: runner.os == 'linux'
run: |
if ! micromamba list | grep -q click; then exit 1; fi
if ! micromamba list | grep -q xtensor; then exit 1; fi
if micromamba list | grep -q cmake; then exit 1; fi
if micromamba list | grep -q ninja; then exit 1; fi
- name: check presence
if: runner.os == 'macos'
run: |
if ! micromamba list | grep -q click; then exit 1; fi
if micromamba list | grep -q xtensor; then exit 1; fi
if ! micromamba list | grep -q cmake; then exit 1; fi
if micromamba list | grep -q ninja; then exit 1; fi
- name: check presence
if: runner.os == 'windows'
run: |
if ! micromamba list | grep -q click; then exit 1; fi
if micromamba list | grep -q xtensor; then exit 1; fi
if micromamba list | grep -q cmake; then exit 1; fi
if ! micromamba list | grep -q ninja; then exit 1; fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The environment.yml or .lock file for the conda environment. If 'false', no envi

### `extra-specs`

(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).
(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 (`sel(linux): my-linux-package`, `sel(osx): my-osx-package`, `sel(win): my-win-package`) are available.

### `cache-downloads`

Expand Down
19 changes: 18 additions & 1 deletion dist/main/index.js

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

19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,28 @@ if(-not($success)){exit}`
await executePwsh(`${PATHS.micromambaExe} shell init -s cmd.exe -p ~\\micromamba -y`)
}

function isSelected (item) {
if (/sel\(.*\):.*/gi.test(item)) {
return new RegExp('sel\\(' + MAMBA_PLATFORM + '\\):.*', 'gi').test(item)
}
return true
}

function stripSelector (item, index, arr) {
arr[index] = item.replace(/sel\(.*\): ?/gi, '')
}

function selectSelectors (extraSpecs) {
const ret = extraSpecs.filter(isSelected)
ret.forEach(stripSelector)
return ret
}

async function createOrUpdateEnv (envName, envFilePath, extraSpecs) {
const envFolder = path.join(PATHS.micromambaEnvs, envName)
const action = fs.existsSync(envFolder) ? 'update' : 'create'
core.info(`${action} env ${envName}`)
const quotedExtraSpecsStr = extraSpecs.map(e => `"${e}"`).join(' ')
const quotedExtraSpecsStr = selectSelectors(extraSpecs).map(e => `"${e}"`).join(' ')
const cmd = `micromamba ${action} -n ${envName} ${quotedExtraSpecsStr} --strict-channel-priority -y -f ${envFilePath}`
if (MAMBA_PLATFORM === 'win') {
await executePwsh(cmd)
Expand Down

0 comments on commit 846e2e8

Please sign in to comment.