Upload nightly wheels to Anaconda Cloud #239
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Upload nightly wheels to Anaconda Cloud | |
on: | |
# Run daily at 1:23 UTC to upload nightly wheels to Anaconda Cloud | |
schedule: | |
- cron: '23 1 * * *' | |
# Run on demand with workflow dispatch | |
workflow_dispatch: | |
permissions: | |
actions: read | |
jobs: | |
upload_nightly_wheels: | |
name: Upload nightly wheels to Anaconda Cloud | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
# The login shell is necessary for the provision-with-micromamba setup | |
# to work in subsequent jobs. | |
# https://github.com/mamba-org/provision-with-micromamba#important | |
shell: bash -e -l {0} | |
if: github.repository_owner == 'matplotlib' | |
steps: | |
# https://github.com/actions/download-artifact/issues/3#issuecomment-1017141067 | |
- name: Download wheel artifacts from last build on 'main' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
PROJECT_REPO="matplotlib/matplotlib" | |
BRANCH="main" | |
WORKFLOW_NAME="cibuildwheel.yml" | |
ARTIFACT_NAME="wheels" | |
gh run --repo "${PROJECT_REPO}" \ | |
list --branch "${BRANCH}" \ | |
--workflow "${WORKFLOW_NAME}" \ | |
--json event,status,conclusion,databaseId > runs.json | |
RUN_ID=$( | |
jq --compact-output \ | |
'[ | |
.[] | | |
# Filter on "push" events to main (merged PRs) ... | |
select(.event == "push") | | |
# that have completed successfully ... | |
select(.status == "completed" and .conclusion == "success") | |
] | | |
# and get ID of latest build of wheels. | |
sort_by(.databaseId) | reverse | .[0].databaseId' runs.json | |
) | |
gh run --repo "${PROJECT_REPO}" view "${RUN_ID}" | |
gh run --repo "${PROJECT_REPO}" \ | |
download "${RUN_ID}" --name "${ARTIFACT_NAME}" | |
mkdir dist | |
mv *.whl dist/ | |
ls -l dist/ | |
# N.B. anaconda-client is only maintained on the main channel | |
- name: Install anaconda-client | |
uses: mamba-org/provision-with-micromamba@v15 | |
with: | |
environment-file: false | |
environment-name: nightlies | |
extra-specs: anaconda-client=1.10.0 | |
channels: main | |
- name: Upload wheels to Anaconda Cloud as nightlies | |
run: | | |
anaconda --token ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }} upload \ | |
--user scipy-wheels-nightly \ | |
--skip-existing \ | |
dist/matplotlib-*.whl | |
- name: Remove old uploads to save space | |
run: | | |
N_LATEST_UPLOADS=5 | |
# Remove all _but_ the last "${N_LATEST_UPLOADS}" package versions | |
# N.B.: `anaconda show` places the newest packages at the bottom of | |
# the output of the 'Versions' section and package versions are | |
# preceded with a ' + '. | |
anaconda show scipy-wheels-nightly/matplotlib &> >(grep '+') | \ | |
sed 's/.* + //' | \ | |
head --lines "-${N_LATEST_UPLOADS}" > remove-package-versions.txt | |
while LANG=C IFS= read -r package_version ; do | |
echo "Removing scipy-wheels-nightly/matplotlib/${package_version}" | |
anaconda --token ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }} remove \ | |
--force \ | |
"scipy-wheels-nightly/matplotlib/${package_version}" | |
done <remove-package-versions.txt |