Skip to content

Commit f689fba

Browse files
skoudorostefanvmatthewfeickert
authored
ENH: Add optional anaconda_nightly_upload_organization argument (#47)
* NF: Add anaconda_nightly_upload_url parameter NF: add anaconda_nightly_upload_token paremeter DOC: Add associated documentation * DOC: add labels documentation * Apply suggestions from code review Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> * - address stefanv comments. - rename anaconda_nightly_upload_url to anaconda_nightly_upload_organization * FIX: del list, docker handle only str/bool/number - parse string in case of multiple labels * Handle comma and new line seperated label lists 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) --------- Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> Co-authored-by: Matthew Feickert <matthew.feickert@cern.ch>
1 parent a337403 commit f689fba

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ then generate a token at `https://anaconda.org/scientific-python-nightly-wheels/
4444
with permissions to _Allow write access to the API site_ and _Allow uploads to Standard Python repositories_,
4545
and add the token as a secret to your GitHub repository.
4646

47+
## Using a different channel
48+
49+
This Github Action can upload your nightly builds to a different channel. To do so,
50+
define the `anaconda_nightly_upload_organization` variable. Furthermore,
51+
you can add labels for organizing your artifacts using `anaconda_nightly_upload_labels`
52+
optional parameter. See below:
53+
54+
```yml
55+
jobs:
56+
steps:
57+
...
58+
- name: Upload wheel
59+
uses: scientific-python/upload-nightly-action@5fb764c5bce1ac2297084c0f7161b1919f17c74f # 0.2.0
60+
with:
61+
artifacts_path: dist
62+
anaconda_nightly_upload_organization: my-alternative-organization
63+
anaconda_nightly_upload_token: ${{secrets.UPLOAD_TOKEN}}
64+
anaconda_nightly_upload_labels: dev
65+
```
66+
4767
## Artifact cleanup-policy at the ``scientific-python-nightly-wheels`` channel
4868

4969
To avoid hosting outdated development versions, as well as to clean up space, we do have a

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ inputs:
1414
anaconda_nightly_upload_token:
1515
description: 'Token to upload to scientific python org'
1616
required: true
17+
anaconda_nightly_upload_organization:
18+
description: 'Organisation name to upload the wheels to'
19+
required: false
20+
default: scientific-python-nightly-wheels
21+
anaconda_nightly_upload_labels:
22+
description: 'List of labels assigned to the uploaded artifacts'
23+
required: false
24+
default: main
1725

1826
runs:
1927
using: 'docker'

cmd.sh

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ set -x
1414
# this is to prevent accidental uploads
1515
echo "Getting anaconda token from github secrets..."
1616

17-
ANACONDA_ORG="scientific-python-nightly-wheels"
17+
ANACONDA_ORG="${INPUT_ANACONDA_NIGHTLY_UPLOAD_ORGANIZATION}"
1818
ANACONDA_TOKEN="${INPUT_ANACONDA_NIGHTLY_UPLOAD_TOKEN}"
19+
ANACONDA_LABELS="${INPUT_ANACONDA_NIGHTLY_UPLOAD_LABELS}"
20+
21+
# if the ANACONDA_ORG is empty, exit with status -1
22+
# this is to prevent attempt to upload to the wrong anaconda channel
23+
if [ -z "${ANACONDA_ORG}" ]; then
24+
echo "ANACONDA_ORG is empty, exiting..."
25+
exit -1
26+
fi
27+
1928

2029
# if the ANACONDA_TOKEN is empty, exit with status -1
2130
# this is to prevent accidental uploads
@@ -24,6 +33,25 @@ if [ -z "${ANACONDA_TOKEN}" ]; then
2433
exit -1
2534
fi
2635

36+
# if the ANACONDA_LABELS is empty, exit with status -1
37+
# as this should be set in action.yml or by the user
38+
# and it is better to fail on this to sigal a problem.
39+
if [ -z "${ANACONDA_LABELS}" ]; then
40+
echo "ANACONDA_LABELS is empty, exiting..."
41+
exit -1
42+
fi
43+
44+
# convert newlines to commas for parsing
45+
# and ensure that there is no trailing comma
46+
ANACONDA_LABELS="$(tr '\n' ',' <<< "${ANACONDA_LABELS}" | sed 's/,$//')"
47+
48+
IFS=',' read -ra LABELS <<< "${ANACONDA_LABELS}"
49+
50+
LABEL_ARGS=""
51+
for label in "${LABELS[@]}"; do
52+
LABEL_ARGS+="--label ${label} "
53+
done
54+
2755
# Install anaconda-client from lock file
2856
echo "Installing anaconda-client from upload-nightly-action conda-lock lock file..."
2957
micromamba create \
@@ -48,5 +76,6 @@ echo "Uploading wheels to anaconda.org..."
4876
anaconda --token "${ANACONDA_TOKEN}" upload \
4977
--force \
5078
--user "${ANACONDA_ORG}" \
79+
$ANACONDA_LABELS \
5180
"${INPUT_ARTIFACTS_PATH}"/*.whl
5281
echo "Index: https://pypi.anaconda.org/${ANACONDA_ORG}/simple"

0 commit comments

Comments
 (0)