Skip to content

Commit

Permalink
Fix #112 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashaag authored Jan 15, 2023
1 parent 160ff6b commit e2b397b
Show file tree
Hide file tree
Showing 9 changed files with 3,649 additions and 6,902 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/resources/condarc1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channels:
- pytorch
- conda-forge
49 changes: 35 additions & 14 deletions .github/workflows/test_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ jobs:
fail-fast: false
matrix:
environment-file: [false, environment.yml]
condarc-file: ["", ".github/workflows/resources/condarc1"]
channels: ["", "conda-forge,blah"]
exclude:
- environment-file: false
condarc-file: ""
channels: ""
steps:
- uses: actions/checkout@v3

Expand All @@ -112,25 +118,40 @@ jobs:
with:
environment-file: ${{ matrix.environment-file }}
environment-name: test-channels
channels: ${{ matrix.channels }}
condarc-file: ${{ matrix.condarc-file }}
extra-specs: |
xtensor
channels: conda-forge,blah
ffmpeg
- name: check channels are correct
run: |
CHANNEL_OPT=$(micromamba config get channels)
echo $CHANNEL_OPT
if [[ "$CHANNEL_OPT" != *"conda-forge"* ]]; then
exit 1;
fi
if [[ "$CHANNEL_OPT" != *"blah"* ]]; then
exit 1;
fi
if [[ "${{ matrix.environment-file }}" != "false" ]]; then
if [[ "$CHANNEL_OPT" != *"defaults"* ]]; then
exit 1;
fi
set -x
cat ~/.condarc
# If a single channel configuration source is provided, channels should
# be taken from that source. Otherwise, we don't make any guarantees.
# Channels source: [e]nvironment.yml, [r]c file, [c]hannels
erc="$([ '${{ matrix.environment-file }}' = false ] && echo 0 || echo 1)"
erc="${erc}$([ -z '${{ matrix.condarc-file }}' ] && echo 0 || echo 1)"
erc="${erc}$([ -z '${{ matrix.channels }}' ] && echo 0 || echo 1)"
channels=$(micromamba config get channels)
# [d]efaults, [p]ytorch, [b]lah
dpb="$([[ "$channels" =~ defaults ]] && echo 1 || echo 0)"
dpb="${dpb}$([[ "$channels" =~ pytorch ]] && echo 1 || echo 0)"
dpb="${dpb}$([[ "$channels" =~ blah ]] && echo 1 || echo 0)"
if [ $(echo $erc | grep -o 1 | wc -l) = 1 ]; then
[ $dpb = $erc ]
# There should be no duplicate "channels:" section in .condarc.
# TODO: This should be true in any case!
[ 1 = $(grep "channels:" ~/.condarc | wc -l) ]
fi
# TODO: check that ffmpeg is installed from the expected channel
test_environment_without_name:
name: "Test environment.yml without name: attribute"
timeout-minutes: 10
Expand Down
3,664 changes: 1,618 additions & 2,046 deletions dist/main/index.js

Large diffs are not rendered by default.

3,643 changes: 1,609 additions & 2,034 deletions dist/post/index.js

Large diffs are not rendered by default.

23 changes: 10 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ const io = require('@actions/io')

const { PATHS, withMkdtemp, executeSubproc, setupProfile, micromambaCmd, haveBash } = require('./util')

function getInputAsArray (name) {
// From https://github.com/actions/cache/blob/main/src/utils/actionUtils.ts
return core
.getInput(name)
.split('\n')
.map(s => s.trim())
function parseList (s, sep) {
return s
.split(sep)
.map(x => x.trim())
.filter(x => x !== '')
}

Expand Down Expand Up @@ -159,12 +157,12 @@ function makeCondarcOpts (inputs, extraChannels) {
}
let channels = []
if (inputs.channels) {
channels = inputs.channels.split(',').map(s => s.trim())
channels = parseList(inputs.channels, ',')
}
if (extraChannels) {
if (extraChannels?.length) {
channels.push.apply(channels, extraChannels)
}
if (channels) {
if (channels.length) {
condarcOpts.channels = channels
}

Expand Down Expand Up @@ -199,8 +197,7 @@ async function installMicromamba (inputs) {
function isSelected (item) {
if (/sel\(.*\):.*/gi.test(item)) {
let condaPlatform = getCondaArch().split('-')[0]
if (["linux", "osx"].includes(condaPlatform))
condaPlatform += '|unix';
if (['linux', 'osx'].includes(condaPlatform)) { condaPlatform += '|unix' }
return new RegExp(`sel\\(${condaPlatform}\\):.*`, 'gi').test(item)
}
return true
Expand Down Expand Up @@ -330,14 +327,14 @@ async function installEnvironment (inputs, envFilePath, envYaml) {
// --- Main ---

async function main () {
// Using getInput is not safe in a post action for templated inputs.
// Using getInput is not safe in a post action for templated inputs.
// Therefore, we need to save the input values beforehand to the state.
const inputs = {
// Basic options
envFile: core.getInput('environment-file'),
envName: core.getInput('environment-name'),
micromambaVersion: core.getInput('micromamba-version'),
extraSpecs: getInputAsArray('extra-specs'),
extraSpecs: parseList(core.getInput('extra-specs'), '\n'),
channels: core.getInput('channels'),
condaRcFile: core.getInput('condarc-file'),
channelPriority: core.getInput('channel-priority'),
Expand Down
Loading

0 comments on commit e2b397b

Please sign in to comment.