diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ff853c..dd0feec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.x' @@ -34,9 +34,9 @@ jobs: python -m pip install build twine python -m pip list - - name: Build a wheel and a sdist + - name: Build v0.0.1 wheel and sdist run: | - PYTHONWARNINGS=error,default::DeprecationWarning python -m build --outdir ./dist tests/test_package + python -m build --outdir ./dist tests/test_package - name: Verify the distribution run: twine check --strict dist/* @@ -53,6 +53,34 @@ jobs: artifacts_path: dist anaconda_nightly_upload_token: ${{ secrets.UPLOAD_TOKEN }} + - name: Build v0.0.2 wheel and sdist + run: | + # Bump version to avoid wheel name conflicts + sed -i 's/0.0.1/0.0.2/g' tests/test_package/pyproject.toml + rm ./dist/* + python -m build --outdir ./dist tests/test_package + + - name: Test upload with non-main label + uses: ./ + with: + artifacts_path: dist + anaconda_nightly_upload_token: ${{ secrets.UPLOAD_TOKEN }} + anaconda_nightly_upload_labels: test + + - name: Build v0.0.3 wheel and sdist + run: | + # Bump version to avoid wheel name conflicts + sed -i 's/0.0.2/0.0.3/g' tests/test_package/pyproject.toml + rm ./dist/* + python -m build --outdir ./dist tests/test_package + + - name: Test upload with multiple labels + uses: ./ + with: + artifacts_path: dist + anaconda_nightly_upload_token: ${{ secrets.UPLOAD_TOKEN }} + anaconda_nightly_upload_labels: dev,test + cleanup: runs-on: ubuntu-latest needs: [test] diff --git a/README.md b/README.md index 68d9eaf..f5e933d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ jobs: steps: ... - name: Upload wheel - uses: scientific-python/upload-nightly-action@8f0394fd2aa0c85d7364a9958652e8994e06b23c # 0.1.0 + uses: scientific-python/upload-nightly-action@5fb764c5bce1ac2297084c0f7161b1919f17c74f # 0.2.0 with: artifacts_path: dist anaconda_nightly_upload_token: ${{secrets.UPLOAD_TOKEN}} @@ -44,6 +44,26 @@ then generate a token at `https://anaconda.org/scientific-python-nightly-wheels/ with permissions to _Allow write access to the API site_ and _Allow uploads to Standard Python repositories_, and add the token as a secret to your GitHub repository. +## Using a different channel + +This Github Action can upload your nightly builds to a different channel. To do so, +define the `anaconda_nightly_upload_organization` variable. Furthermore, +you can add labels for organizing your artifacts using `anaconda_nightly_upload_labels` +optional parameter. See below: + +```yml +jobs: + steps: + ... + - name: Upload wheel + uses: scientific-python/upload-nightly-action@5fb764c5bce1ac2297084c0f7161b1919f17c74f # 0.2.0 + with: + artifacts_path: dist + anaconda_nightly_upload_organization: my-alternative-organization + anaconda_nightly_upload_token: ${{secrets.UPLOAD_TOKEN}} + anaconda_nightly_upload_labels: dev +``` + ## Artifact cleanup-policy at the ``scientific-python-nightly-wheels`` channel To avoid hosting outdated development versions, as well as to clean up space, we do have a diff --git a/action.yml b/action.yml index 6f84f14..2aefbb8 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,14 @@ inputs: anaconda_nightly_upload_token: description: 'Token to upload to scientific python org' required: true + anaconda_nightly_upload_organization: + description: 'Organisation name to upload the wheels to' + required: false + default: scientific-python-nightly-wheels + anaconda_nightly_upload_labels: + description: 'List of labels assigned to the uploaded artifacts' + required: false + default: main runs: using: 'docker' diff --git a/cmd.sh b/cmd.sh index 8313e8e..430c8dd 100644 --- a/cmd.sh +++ b/cmd.sh @@ -14,8 +14,17 @@ set -x # this is to prevent accidental uploads echo "Getting anaconda token from github secrets..." -ANACONDA_ORG="scientific-python-nightly-wheels" +ANACONDA_ORG="${INPUT_ANACONDA_NIGHTLY_UPLOAD_ORGANIZATION}" ANACONDA_TOKEN="${INPUT_ANACONDA_NIGHTLY_UPLOAD_TOKEN}" +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..." + exit -1 +fi + # if the ANACONDA_TOKEN is empty, exit with status -1 # this is to prevent accidental uploads @@ -24,6 +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, 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 \ @@ -39,14 +67,14 @@ micromamba activate upload-nightly-action # trim trailing slashes from $INPUT_ARTIFACTS_PATH INPUT_ARTIFACTS_PATH="${INPUT_ARTIFACTS_PATH%/}" -# debug, print env -env - # upload wheels echo "Uploading wheels to anaconda.org..." +# Note: ${LABEL_ARGS} must not be quoted during shell parameter expansion, +# else it will be treated as a file and not additional command arguments. anaconda --token "${ANACONDA_TOKEN}" upload \ --force \ --user "${ANACONDA_ORG}" \ + ${LABEL_ARGS} \ "${INPUT_ARTIFACTS_PATH}"/*.whl echo "Index: https://pypi.anaconda.org/${ANACONDA_ORG}/simple"