Skip to content

Commit

Permalink
Handle comma and new line seperated label lists
Browse files Browse the repository at this point in the history
Using space seperated lists is not standard across GitHub Actions, which in general assume that you're providing a newline seperatd or comma seperated list (c.f. https://github.com/docker/build-push-action?tab=readme-ov-file#inputs as an example).

So if we agree that we should be expecting newline seperated or comma seperated inputs then we can just treat all input the same by:

First, converting all input into a comma separated string
Then, create an array of the comma seperated labels
Finally, parse that array into a single string that represents all the label arguments to be included (you were already doing this part)
  • Loading branch information
matthewfeickert authored Jan 23, 2024
1 parent 9b762da commit 97a6a9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inputs:
required: false
default: scientific-python-nightly-wheels
anaconda_nightly_upload_labels:
description: 'Labels assigned to the uploaded artifacts'
description: 'List of labels assigned to the uploaded artifacts'
required: false
default: main

Expand Down
33 changes: 17 additions & 16 deletions cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ANACONDA_LABELS="${INPUT_ANACONDA_NIGHTLY_UPLOAD_LABELS}"
# if the ANACONDA_ORG is empty, exit with status -1
# this is to prevent attempt to upload to the wrong anaconda channel
if [ -z "${ANACONDA_ORG}" ]; then
echo "ANACONDA_ORG is empty , exiting..."
echo "ANACONDA_ORG is empty, exiting..."
exit -1
fi

Expand All @@ -33,24 +33,25 @@ if [ -z "${ANACONDA_TOKEN}" ]; then
exit -1
fi

# if the ANACONDA_LABELS is empty, exit with status -1
# as this should be set in action.yml or by the user
# and it is better to fail on this to sigal a problem.
if [ -z "${ANACONDA_LABELS}" ]; then
echo "ANACONDA_LABELS is empty , using default label (main)..."
ANACONDA_LABELS="--label main"
else
# Count the number of words in the string
label_count=$(echo "$ANACONDA_LABELS" | wc -w)
if [ "$label_count" -gt 1 ]; then
formatted_labels=""
for label in ${ANACONDA_LABELS}; do
formatted_labels+="--label $label "
done
ANACONDA_LABELS="${formatted_labels}"
else
ANACONDA_LABELS="--label $ANACONDA_LABELS"
echo "only 1 label, using option: $ANACONDA_LABELS"
fi
echo "ANACONDA_LABELS is empty, exiting..."
exit -1
fi

# convert newlines to commas for parsing
# and ensure that there is no trailing comma
ANACONDA_LABELS="$(tr '\n' ',' <<< "${ANACONDA_LABELS}" | sed 's/,$//')"

IFS=',' read -ra LABELS <<< "${ANACONDA_LABELS}"

LABEL_ARGS=""
for label in "${LABELS[@]}"; do
LABEL_ARGS+="--label ${label} "
done

# Install anaconda-client from lock file
echo "Installing anaconda-client from upload-nightly-action conda-lock lock file..."
micromamba create \
Expand Down

0 comments on commit 97a6a9c

Please sign in to comment.