1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-22 20:35:44 +01:00
trexio/.github/workflows/build-wheels.yml
2023-05-05 17:06:15 +02:00

224 lines
7.5 KiB
YAML

# Controls when the workflow will run
on:
# Run this workflow after the TREXIO CI completed
workflow_run:
workflows: [ "TREXIO CI" ]
branches: [ master ]
types:
- completed
# Workflow to build and publish wheels.
# in the get_commit_message job: Include [wheel build] in your commit message to trigger this build.
name: Build CPython wheels
jobs:
get_commit_message:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: Get commit message
runs-on: ubuntu-20.04
outputs:
message: ${{ steps.commit_message.outputs.message }}
steps:
- name: Checkout the repo
uses: actions/checkout@v3
# Gets the correct commit message for pull request
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get commit message
id: commit_message
run: |
set -xe
COMMIT_MSG=$(git log --no-merges -1 --oneline)
echo "::set-output name=message::$COMMIT_MSG"
build_linux_wheels:
name: Build Linux wheels for different versions of CPython on manylinux_x86_64
needs: get_commit_message
if: >-
contains(needs.get_commit_message.outputs.message, '[wheel build]') ||
(github.repository == 'TREX-CoE/trexio' && startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-20.04
strategy:
matrix:
manylinux_tag: [2014_x86_64, 2_24_x86_64]
steps:
- name: Checkout the branch
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install build dependencies
run: python -m pip install -U setuptools
- name: Compute the PYTREXIO_VERSION environment variable
run: echo "PYTREXIO_VERSION=$(grep __version__ python/pytrexio/_version.py | cut -d\ -f3 | tr -d '"')" >> $GITHUB_ENV
- name: Print the PYTREXIO_VERSION
run: echo ${{ env.PYTREXIO_VERSION }}
# Conventional download-artifact action does not work for artifact produced in a different workflow,
# which is the case here (TREXIO CI produced the Python API distribution tarball)
- name: Download the Python API distribution tarball
uses: dawidd6/action-download-artifact@v2
with:
# Specify the name of the workflow file which uploaded the tarball
workflow: actions.yml
workflow_conclusion: success
name: pytrexio-source
path: python
# at the moment we have to pull the custom container with pre-installed HDF5
# the containers are built and stored in GitHub container registry ghcr.io/q-posev
- name: Pull the manylinux Docker container with HDF5
run: docker pull ghcr.io/q-posev/hdf5_1_12_on_${{ matrix.manylinux_tag }}:latest
- name: Build wheels for different versions of CPython inside the Docker container
run: >
docker run --rm
--env PLAT=manylinux${{ matrix.manylinux_tag }}
--volume `pwd`:/tmp
--workdir /tmp
ghcr.io/q-posev/hdf5_1_12_on_${{ matrix.manylinux_tag }}
/bin/bash build_manylinux_wheels.sh trexio-${{ env.PYTREXIO_VERSION }}.tar.gz
working-directory: python
- name: Upload produced wheels as artifacts
uses: actions/upload-artifact@v2
with:
name: pytrexio-manylinux-${{ matrix.manylinux_tag }}
path: ./python/wheelhouse/*.whl
build_macos_wheels:
name: Build MacOS wheels for different versions of CPython
needs: get_commit_message
if: >-
contains(needs.get_commit_message.outputs.message, '[wheel build]') ||
(github.repository == 'TREX-CoE/trexio' && startsWith(github.ref, 'refs/tags/v'))
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-12]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python --version
- name: Install HDF5
run: brew install hdf5@1.12
- name: Compute the PYTREXIO_VERSION environment variable
run: echo "PYTREXIO_VERSION=$(grep __version__ python/pytrexio/_version.py | cut -d\ -f3 | tr -d '"')" >> $GITHUB_ENV
- name: Print the PYTREXIO_VERSION
run: echo ${{ env.PYTREXIO_VERSION }}
- name: Download the Python API distribution tarball
uses: dawidd6/action-download-artifact@v2
with:
workflow: actions.yml
workflow_conclusion: success
name: pytrexio-source
path: python
- name: Extract the Python distribution
run: gzip -cd trexio-${{ env.PYTREXIO_VERSION }}.tar.gz | tar xvf -
working-directory: python
- name: Install Python dependencies
run: pip install --upgrade pip setuptools build delocate pytest
- name: Build wheel for a given version of CPython
run: |
mkdir wheelhouse/
cd trexio-${{ env.PYTREXIO_VERSION }}/
export H5_CFLAGS="-I$(brew --prefix hdf5)/include"
export H5_LDFLAGS="-L$(brew --prefix hdf5)/lib"
python -m build --wheel --outdir=./
delocate-wheel trexio-*.whl
mv trexio-*.whl ../wheelhouse/
working-directory: python
# Some issues with Python 3.10 wheels on MacOS-11
- name: Install the wheel
run: python -m pip install wheelhouse/trexio-*.whl
working-directory: python
- name: Test the wheel
run: pytest -v test_api.py
working-directory: python/test
- name: Upload produced wheels as artifacts
uses: actions/upload-artifact@v2
with:
name: pytrexio-${{ matrix.os }}
path: ./python/wheelhouse/*.whl
publish_wheels:
name: Publish all wheels on PyPI
needs: [build_linux_wheels, build_macos_wheels]
runs-on: ubuntu-20.04
steps:
- name: Checkout the branch
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install build dependencies
run: python -m pip install -U setuptools twine
- name: Download the build artifacts (wheels) of this workflow
uses: actions/download-artifact@v2
with:
path: dist
- name: Download the Python API distribution tarball
uses: dawidd6/action-download-artifact@v2
with:
workflow: actions.yml
workflow_conclusion: success
name: pytrexio-source
path: dist
# The artifacts have to be in dist/ directory so that
# pypa/gh-action-pypi-publish action can discover them
- name: Display and rearrange the downloaded artifacts
run: |
ls -R
mv pytrexio-manylinux-*/trexio-*.whl ./
mv pytrexio-macos-*/trexio-*.whl ./
rm -rf -- pytrexio-manylinux-*/ pytrexio-macos-*/
ls -sh -w 1
working-directory: dist
#- name: Publish distribution 📦 to Test PyPI
# uses: pypa/gh-action-pypi-publish@master
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
#verbose: true
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
#if: startsWith(github.ref, 'refs/tags')