Run astroquery-based tests in both orbit jobs to hit multiple astroqu… #559
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: Wheel builder and uploader | |
# Update on every push and PR to main, and upon release creation | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '**' | |
- '!*' | |
- '*.py' | |
- '!tests/**' | |
- '!doc/**' | |
- '!.github/**' | |
- '.github/workflows/wheels.yml' | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- 'doc/**' | |
release: | |
types: [created] | |
jobs: | |
build_wheels: | |
name: Build wheel for ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }} | |
runs-on: ${{ matrix.buildplat[0] }} | |
strategy: | |
# Ensure that a wheel builder finishes even if another fails | |
fail-fast: false | |
matrix: | |
# Following numpy's setup | |
buildplat: | |
- [ubuntu-22.04, manylinux, x86_64] | |
- [macos-13, macosx, x86_64] | |
- [macos-14, macosx, arm64] | |
- [windows-2019, win, amd64] | |
python: | |
- ["cp38","3.8"] | |
- ["cp39","3.9"] | |
- ["cp310","3.10"] | |
- ["cp311","3.11"] | |
- ["cp312","3.12"] | |
- ["cp313","3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install GSL (Windows / Mac OS x86_64) | |
uses: mamba-org/setup-micromamba@v2 | |
if: matrix.buildplat[1] == 'win' || matrix.buildplat[1] == 'macosx' | |
with: | |
environment-name: gsl | |
condarc: | | |
channels: | |
- conda-forge | |
create-args: gsl | |
cache-environment: true | |
cache-environment-key: gsl-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}-${{ hashFiles('.github/workflows/wheels.yml') }} | |
- name: Set GSL environment variables (Windows) | |
if: matrix.buildplat[1] == 'win' | |
shell: bash -l {0} | |
run: | | |
echo "INCLUDE=$CONDA_PREFIX\\Library\\include" >> $GITHUB_ENV | |
echo "LIB=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV | |
echo "LIBPATH=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV | |
echo "$CONDA_PREFIX\\Library\\bin" >> $GITHUB_PATH # necessary when we don't activate the environment | |
- name: Set GSL environment variables (Mac OS) | |
if: matrix.buildplat[1] == 'macosx' | |
shell: bash -l {0} | |
run: | | |
echo "CFLAGS=-I$CONDA_PREFIX/include" >> $GITHUB_ENV | |
echo "LDFLAGS=-L$CONDA_PREFIX/lib" >> $GITHUB_ENV | |
echo "REPAIR_LIBRARY_PATH=$CONDA_PREFIX/lib" >> $GITHUB_ENV # https://github.com/pypa/cibuildwheel/issues/816#issuecomment-916197079 | |
echo "$CONDA_PREFIX/bin" >> $GITHUB_PATH # necessary when we don't activate the environment | |
- name: Build wheels | |
uses: pypa/cibuildwheel@v2.22 | |
env: | |
CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}_${{ matrix.buildplat[2] }} | |
CIBW_BUILD_VERBOSITY: 1 | |
CIBW_BEFORE_BUILD_LINUX: yum -y install gsl-devel | |
CIBW_ARCHS_MACOS: ${{ matrix.buildplat[2] }} | |
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=10.13" | |
CIBW_REPAIR_WHEEL_COMMAND_MACOS: > | |
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && | |
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel -v --require-archs {delocate_archs} -w {dest_dir} {wheel} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}_${{ matrix.buildplat[2] }} | |
path: ./wheelhouse/*.whl | |
test_wheels: | |
name: Test Python ${{ matrix.python[1] }} wheels on ${{ matrix.buildplat[2] }} ${{ matrix.buildplat[0] }} | |
runs-on: ${{ matrix.buildplat[0] }} | |
needs: build_wheels | |
strategy: | |
# Ensure that tests finish even if another fails | |
fail-fast: false | |
matrix: | |
buildplat: | |
- [ubuntu-22.04, manylinux, x86_64] | |
- [macos-13, macosx, x86_64] | |
- [macos-14, macosx, arm64] | |
- [windows-2019, win, amd64] | |
python: | |
- ["cp38","3.8"] | |
- ["cp39","3.9"] | |
- ["cp310","3.10"] | |
- ["cp311","3.11"] | |
- ["cp312","3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
- run: mkdir wheelhouse | |
- uses: actions/download-artifact@v4 | |
with: | |
name: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}_${{ matrix.buildplat[2] }} | |
path: wheelhouse/ | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python[1] }} | |
allow-prereleases: true | |
- name: Install GSL (Windows) | |
uses: mamba-org/setup-micromamba@v2 | |
if: matrix.buildplat[1] == 'win' | |
with: | |
environment-name: gsl | |
condarc: | | |
channels: | |
- conda-forge | |
create-args: gsl | |
cache-environment: true | |
cache-environment-key: gsl-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}-${{ hashFiles('.github/workflows/wheels.yml') }} | |
- name: Set GSL environment variables (Windows) | |
if: matrix.buildplat[1] == 'win' | |
shell: bash -l {0} | |
run: | | |
micromamba activate gsl | |
echo "LIBPATH=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV | |
echo "$CONDA_PREFIX\\Library\\bin" >> $GITHUB_PATH # necessary when we don't activate the environment | |
- name: Install wheel | |
shell: bash | |
run: python -m pip install `ls -d "$(pwd)"/wheelhouse/*.whl` | |
- name: Test built wheel in non-conda environment | |
shell: bash | |
working-directory: ${{ runner.temp }} | |
run: | | |
pip install astropy pytest | |
pytest -v $GITHUB_WORKSPACE/tests/test_orbit.py -k "test_energy_jacobi_conservation and NFW" | |
# Test that built wheels also work in a conda environment, setup environment, install wheel, and run test | |
- name: Setup test conda environment (Linux / Mac OS) | |
if: matrix.buildplat[1] != 'win' | |
uses: mamba-org/setup-micromamba@v2 | |
with: | |
environment-name: test-wheel-conda | |
condarc: | | |
channels: | |
- conda-forge | |
create-args: python=${{ matrix.python[1] }} numpy scipy matplotlib astropy pytest | |
cache-environment: true | |
cache-environment-key: test-wheel-conda-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}-${{ hashFiles('.github/workflows/wheels.yml') }} | |
- name: Setup test conda environment (Windows) | |
if: matrix.buildplat[1] == 'win' | |
shell: bash -l {0} | |
run: | | |
micromamba create -n test-wheel-conda -c conda-forge python=${{ matrix.python[1] }} numpy scipy matplotlib astropy pytest gsl | |
micromamba activate test-wheel-conda | |
echo "LIBPATH=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV | |
- name: Install built wheel in conda environment | |
shell: bash -l {0} | |
run: | | |
micromamba activate test-wheel-conda | |
python -m pip install `ls -d "$(pwd)"/wheelhouse/*.whl` | |
- name: Test built wheel in conda environment | |
shell: bash -l {0} | |
working-directory: ${{ runner.temp }} | |
run: | | |
micromamba activate test-wheel-conda | |
pytest -v $GITHUB_WORKSPACE/tests/test_orbit.py -k "test_energy_jacobi_conservation and NFW" | |
build_sdist: | |
name: Build source directory for release | |
if: github.event_name == 'release' && github.event.action == 'created' | |
runs-on: ubuntu-latest | |
steps: | |
# check-out this repository | |
- uses: actions/checkout@v4 | |
# Setup python | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.x | |
# Install the GSL (necessary to properly include the C files) | |
- name: Install GSL | |
run: sudo apt-get install -y libgsl0-dev | |
- name: Build sdist | |
run: | | |
pip install build | |
python -m build --sdist | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: sdist | |
path: ./dist/*.tar.gz | |
# Deploy wheels and sdist to PyPI (upon release creation) | |
deploy_pypi: | |
name: Deploy to PyPI | |
needs: [build_wheels, test_wheels, build_sdist] | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | |
if: github.event_name == 'release' && github.event.action == 'created' | |
steps: | |
- uses: actions/checkout@v4 | |
- run: | | |
mkdir tmp_wheelhouse | |
mkdir wheelhouse | |
- uses: actions/download-artifact@v4 | |
with: | |
path: tmp_wheelhouse/ | |
- run: find tmp_wheelhouse/ -mindepth 2 -type f -exec mv -i '{}' wheelhouse/ ';' | |
- name: Publish distribution to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages_dir: wheelhouse/ | |
# Deploy wheels and sdist to AWS S3 (main) | |
deploy_s3: | |
name: Deploy to AWS S3 | |
needs: [build_wheels, test_wheels] | |
runs-on: ubuntu-latest | |
if: github.event_name != 'release' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- run: | | |
mkdir tmp_wheelhouse | |
mkdir wheelhouse | |
- uses: actions/download-artifact@v4 | |
with: | |
path: tmp_wheelhouse/ | |
- run: find tmp_wheelhouse/ -mindepth 2 -type f -exec mv -i '{}' wheelhouse/ ';' | |
- name: Rename wheel to 'latest' version for AWS S3 | |
run: | | |
GALPY_VERSION="$(awk '/^current_version/{print $NF}' .bumpversion.cfg)" | |
for f in wheelhouse/*$GALPY_VERSION*.whl; do mv -i -- "$f" "${f//$GALPY_VERSION/latest}"; done | |
- name: Upload to AWS S3 | |
uses: jakejarvis/s3-sync-action@v0.5.1 | |
with: | |
args: --acl public-read --follow-symlinks --delete --exclude "*emscripten*" | |
env: | |
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: 'us-east-2' | |
SOURCE_DIR: wheelhouse | |
DEST_DIR: wheelhouse |