Skip to content

Run on the current branch, with actual upload steps commented out, to… #209

Run on the current branch, with actual upload steps commented out, to…

Run on the current branch, with actual upload steps commented out, to… #209

Workflow file for this run

name: Build and Release
on:
push:
branches:
- master
- maintenance/*
- automatic-config-workflow
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
env:
OS_LIST_UBUNTU: '["ubuntu-latest"]'
OS_LIST_ALL: '["ubuntu-latest", "windows-latest", "macos-latest", "macos-13"]'
jobs:
configure:
name: Configure workflow run
runs-on: ubuntu-latest
outputs:
PYTHONS: ${{ steps.config.outputs.PYTHONS }}
DEFAULTPYTHON: ${{ steps.config.outputs.DEFAULTPYTHON }}
CIBW_BUILD: ${{ steps.config.outputs.CIBW_BUILD }}
PKGNAME: ${{ steps.config.outputs.PKGNAME }}
PKGVER: ${{ steps.config.outputs.PKGVER }}
PURE: ${{ steps.config.outputs.PURE }}
CONDA_BUILD_ARGS: ${{ steps.config.outputs.CONDA_BUILD_ARGS }}
BUILD_OS_LIST: ${{ steps.config.outputs.BUILD_OS_LIST }}
RELEASE: ${{ steps.config.outputs.RELEASE }}
TESTPYPI_UPLOAD: ${{ steps.config.outputs.TESTPYPI_UPLOAD }}
PYPI_UPLOAD: ${{ steps.config.outputs.PYPI_UPLOAD }}
TEST_ANACONDA_UPLOAD: ${{ steps.config.outputs.TEST_ANACONDA_UPLOAD }}
ANACONDA_UPLOAD: ${{ steps.config.outputs.ANACONDA_UPLOAD }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Configure workflow
id: config
run: |
pip install ci-helper
# Second-most recent supported Python version:
DEFAULTPYTHON=$(ci-helper defaultpython)
# All supported Python versions:
PYTHONS=$(ci-helper pythons)
# Env var for `cibuildwheel` to build for all supported CPython versions:
CIBW_BUILD=$(ci-helper pythons --cibw)
# Package name and version:
PKGNAME=$(ci-helper distinfo name .)
PKGVER=$(ci-helper distinfo version .)
# Whether the package is pure python, and whether its requirements depend
# on platform or Python version:
PURE=$(ci-helper distinfo is_pure .)
HAS_ENV_MARKERS=$(ci-helper distinfo has_env_markers .)
# List of OSs we need to run the build job on, and Python versions conda-build
# should target:
if [[ $PURE == false || $HAS_ENV_MARKERS == true ]]; then
BUILD_OS_LIST=$OS_LIST_ALL
CONDA_BUILD_ARGS="--pythons=$PYTHONS"
else
BUILD_OS_LIST=$OS_LIST_UBUNTU
CONDA_BUILD_ARGS="--noarch"
fi
# Release if a tag was pushed:
if [ ${{ contains(github.ref, '/tags') }} == true ]; then
RELEASE=true
else
RELEASE=false
fi
# What upload credentials is the repo configured with?
if [ '${{ secrets.TESTPYPI }}' != '' ]; then
HAVE_TESTPYPI_TOKEN=true
else
HAVE_TESTPYPI_TOKEN=false
fi
if [ '${{ secrets.PYPI }}' != '' ]; then
HAVE_PYPI_TOKEN=true
else
HAVE_PYPI_TOKEN=false
fi
if [ '${{ secrets.ANACONDA_API_TOKEN }}' != '' ]; then
HAVE_ANACONDA_TOKEN=true
else
HAVE_ANACONDA_TOKEN=false
fi
if [ '${{ vars.ANACONDA_USER }}' != '' ]; then
HAVE_ANACONDA_USER=true
else
HAVE_ANACONDA_USER=false
fi
if [ $HAVE_ANACONDA_USER != $HAVE_ANACONDA_TOKEN ]; then
echo "Require both vars.ANACONDA_USER and secrets.ANACONDA_API_TOKEN"
exit 1
fi
# Upload releases to PyPI and Anaconda if the repo has creds:
if [[ $RELEASE == true && $HAVE_PYPI_TOKEN == true ]]; then
PYPI_UPLOAD=true
else
PYPI_UPLOAD=false
fi
if [[ $RELEASE == true && $HAVE_ANACONDA_TOKEN == true ]]; then
ANACONDA_UPLOAD=true
else
ANACONDA_UPLOAD=false
fi
# Upload non-releases to TestPyPI and Anaconda test label if repo has creds:
if [[ $RELEASE == false && $HAVE_TESTPYPI_TOKEN == true ]]; then
TESTPYPI_UPLOAD=true
else
TESTPYPI_UPLOAD=false
fi
if [[ $RELEASE == false && $HAVE_ANACONDA_TOKEN == true ]]; then
TEST_ANACONDA_UPLOAD=true
else
TEST_ANACONDA_UPLOAD=false
fi
echo "DEFAULTPYTHON=$DEFAULTPYTHON" >> $GITHUB_OUTPUT
echo "CIBW_BUILD=$CIBW_BUILD" >> $GITHUB_OUTPUT
echo "PKGNAME=$PKGNAME" >> $GITHUB_OUTPUT
echo "PKGVER=$PKGVER" >> $GITHUB_OUTPUT
echo "PURE=$PURE" >> $GITHUB_OUTPUT
echo "CONDA_BUILD_ARGS=$CONDA_BUILD_ARGS" >> $GITHUB_OUTPUT
echo "BUILD_OS_LIST=$BUILD_OS_LIST" >> $GITHUB_OUTPUT
echo "RELEASE=$RELEASE" >> $GITHUB_OUTPUT
echo "TESTPYPI_UPLOAD=$TESTPYPI_UPLOAD" >> $GITHUB_OUTPUT
echo "PYPI_UPLOAD=$PYPI_UPLOAD" >> $GITHUB_OUTPUT
echo "TEST_ANACONDA_UPLOAD=$TEST_ANACONDA_UPLOAD" >> $GITHUB_OUTPUT
echo "ANACONDA_UPLOAD=$ANACONDA_UPLOAD" >> $GITHUB_OUTPUT
echo
echo "======================="
echo "Workflow configuration:"
echo "-----------------------"
cat $GITHUB_OUTPUT
echo "======================="
echo
build:
name: Build
runs-on: ${{ matrix.os }}
needs: configure
strategy:
matrix:
os: ${{ fromJSON(needs.configure.outputs.BUILD_OS_LIST) }}
env:
PYTHONS: ${{ needs.configure.outputs.PYTHONS }}
DEFAULTPYTHON: ${{ needs.configure.outputs.DEFAULTPYTHON }}
CIBW_BUILD: ${{ needs.configure.outputs.CIBW_BUILD }}
PURE: ${{ needs.configure.outputs.PURE }}
CONDA_BUILD_ARGS: ${{ needs.configure.outputs.CONDA_BUILD_ARGS }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULTPYTHON }}
- name: Install Python tools
run: python -m pip install --upgrade pip setuptools wheel build cibuildwheel
- name: Source distribution
if: strategy.job-index == 0
run: python -m build -s .
- name: Wheel distribution (pure)
if: env.PURE == 'true' && strategy.job-index == 0
run: python -m build -w .
- name: Wheel distribution (impure)
if: env.PURE == 'false'
run: cibuildwheel --output-dir dist
- name: Upload artifact
if: env.PURE == 'false' || strategy.job-index == 0
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.os }}
path: ./dist
if-no-files-found: error
- name: Install Miniforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: "latest"
auto-update-conda: true
conda-remove-defaults: true
auto-activate-base: true
activate-environment: ""
- name: Conda package
shell: bash -l {0}
run: |
if [ ${{ runner.os }} == Windows ]; then
# Short path to minimise odds of hitting Windows max path length
CONDA_BUILD_ARGS+=" --croot ${{ runner.temp }}\cb"
fi
conda install -c labscript-suite setuptools-conda
setuptools-conda build $CONDA_BUILD_ARGS .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: conda_packages-${{ matrix.os }}
path: ./conda_packages
if-no-files-found: error
github-release:
name: Publish release (GitHub)
runs-on: ubuntu-latest
needs: [configure, build]
if: ${{ needs.configure.outputs.RELEASE == 'true' }}
env:
PKGNAME: ${{ needs.configure.outputs.PKGNAME }}
PKGVER: ${{ needs.configure.outputs.PKGVER }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
pattern: dist*
path: ./dist
merge-multiple: true
- name: Create GitHub release and upload release asset
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.ref }}
name: ${{ env.PKGNAME }} ${{ env.PKGVER }}
draft: true
prerelease: ${{ contains(github.event.ref, 'rc') }}
files: ./dist/${{ env.PKGNAME }}-${{ env.PKGVER }}.tar.gz
testpypi-upload:
name: Publish on Test PyPI
runs-on: ubuntu-latest
needs: [configure, build]
if: ${{ needs.configure.outputs.TESTPYPI_UPLOAD == 'true' }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
pattern: dist*
path: ./dist
merge-multiple: true
# - name: Publish on TestPyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# user: __token__
# password: ${{ secrets.TESTPYPI }}
# repository-url: https://test.pypi.org/legacy/
pypi-upload:
name: Publish on PyPI
runs-on: ubuntu-latest
needs: [configure, build]
if: ${{ needs.configure.outputs.PYPI_UPLOAD == 'true' }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
pattern: dist*
path: ./dist
merge-multiple: true
# - name: Publish on PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# user: __token__
# password: ${{ secrets.PYPI }}
test-anaconda-upload:
name: Publish on Anaconda (test label)
runs-on: ubuntu-latest
needs: [configure, build]
if: ${{ needs.configure.outputs.TEST_ANACONDA_UPLOAD == 'true' }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
pattern: conda_packages-*
path: ./conda_packages
merge-multiple: true
- name: Install Miniforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: "latest"
auto-update-conda: true
conda-remove-defaults: true
auto-activate-base: true
activate-environment: ""
- name: Install Anaconda cloud client
shell: bash -l {0}
run: conda install anaconda-client
# - name: Publish to Anaconda test label
# shell: bash -l {0}
# run: |
# anaconda \
# --token ${{ secrets.ANACONDA_API_TOKEN }} \
# upload \
# --skip-existing \
# --user ${{ vars.ANACONDA_USER }} \
# --label test \
# conda_packages/*/*
anaconda-upload:
name: Publish on Anaconda
runs-on: ubuntu-latest
needs: [configure, build]
if: ${{ needs.configure.outputs.ANACONDA_UPLOAD == 'true' }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
pattern: conda_packages-*
path: ./conda_packages
merge-multiple: true
- name: Install Miniforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: "latest"
auto-update-conda: true
conda-remove-defaults: true
auto-activate-base: true
activate-environment: ""
- name: Install Anaconda cloud client
shell: bash -l {0}
run: conda install anaconda-client
# - name: Publish to Anaconda main
# shell: bash -l {0}
# run: |
# anaconda \
# --token ${{ secrets.ANACONDA_API_TOKEN }} \
# upload \
# --skip-existing \
# --user ${{ vars.ANACONDA_USER }} \
# conda_packages/*/*