xref: /libCEED/.github/workflows/python-wheels.yml (revision e735508cdfa08f2ead7f8e6e8f825d0fa851c858)
1dd8ab4d9SJed Brownname: Python Wheels
2dd8ab4d9SJed Brown
3dd8ab4d9SJed Brown# Build on every branch push, tag push, and pull request change:
4dd8ab4d9SJed Brownon: [push, pull_request]
5dd8ab4d9SJed Brown# Alternatively, to publish when a (published) GitHub Release is created, use the following:
6dd8ab4d9SJed Brown# on:
7dd8ab4d9SJed Brown#   push:
8dd8ab4d9SJed Brown#   pull_request:
9dd8ab4d9SJed Brown#   release:
10dd8ab4d9SJed Brown#     types:
11dd8ab4d9SJed Brown#       - published
12dd8ab4d9SJed Brown
13dd8ab4d9SJed Brownjobs:
14dd8ab4d9SJed Brown  build_wheels:
15dd8ab4d9SJed Brown    name: Build wheels on ${{ matrix.os }}
16dd8ab4d9SJed Brown    if: >-
17dd8ab4d9SJed Brown      (github.event_name == 'pull_request' &&
18dd8ab4d9SJed Brown      contains(github.event.pull_request.labels.*.name, 'release preparation')) ||
19dd8ab4d9SJed Brown      github.event_name == 'workflow_dispatch' ||
20dd8ab4d9SJed Brown      (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
21dd8ab4d9SJed Brown    runs-on: ${{ matrix.os }}
22dd8ab4d9SJed Brown    strategy:
23dd8ab4d9SJed Brown      matrix:
24dd8ab4d9SJed Brown        # windows-2019, macos-11
25dd8ab4d9SJed Brown        os: [ubuntu-20.04]
26dd8ab4d9SJed Brown
27dd8ab4d9SJed Brown    steps:
28*e735508cSJeremy L Thompson      - uses: actions/checkout@v4
29dd8ab4d9SJed Brown
30dd8ab4d9SJed Brown      - name: Build wheels
31dd8ab4d9SJed Brown        uses: pypa/cibuildwheel@v2.11.3
32dd8ab4d9SJed Brown
33*e735508cSJeremy L Thompson      - uses: actions/upload-artifact@v4
34dd8ab4d9SJed Brown        with:
35dd8ab4d9SJed Brown          path: ./wheelhouse/*.whl
36dd8ab4d9SJed Brown
37dd8ab4d9SJed Brown  build_sdist:
38dd8ab4d9SJed Brown    name: Build source distribution
39dd8ab4d9SJed Brown    if: >-
40dd8ab4d9SJed Brown      (github.event_name == 'pull_request' &&
41dd8ab4d9SJed Brown      contains(github.event.pull_request.labels.*.name, 'release preparation')) ||
42dd8ab4d9SJed Brown      github.event_name == 'workflow_dispatch' ||
43dd8ab4d9SJed Brown      (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
44dd8ab4d9SJed Brown    runs-on: ubuntu-latest
45dd8ab4d9SJed Brown    steps:
46*e735508cSJeremy L Thompson      - uses: actions/checkout@v4
47dd8ab4d9SJed Brown
48dd8ab4d9SJed Brown      - name: Build sdist
49dd8ab4d9SJed Brown        run: pipx run build --sdist
50dd8ab4d9SJed Brown
51*e735508cSJeremy L Thompson      - uses: actions/upload-artifact@v4
52dd8ab4d9SJed Brown        with:
53dd8ab4d9SJed Brown          path: dist/*.tar.gz
54dd8ab4d9SJed Brown
55dd8ab4d9SJed Brown  upload_pypi:
56dd8ab4d9SJed Brown    needs: [build_wheels, build_sdist]
57dd8ab4d9SJed Brown    runs-on: ubuntu-latest
58dd8ab4d9SJed Brown    # upload to PyPI on every tag starting with 'v'
59dd8ab4d9SJed Brown    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
60dd8ab4d9SJed Brown    # alternatively, to publish when a GitHub Release is created, use the following rule:
61dd8ab4d9SJed Brown    # if: github.event_name == 'release' && github.event.action == 'published'
62dd8ab4d9SJed Brown    steps:
63*e735508cSJeremy L Thompson      - uses: actions/download-artifact@v4
64dd8ab4d9SJed Brown        with:
65dd8ab4d9SJed Brown          # unpacks default artifact into dist/
66dd8ab4d9SJed Brown          # if `name: artifact` is omitted, the action will create extra parent dir
67dd8ab4d9SJed Brown          name: artifact
68dd8ab4d9SJed Brown          path: dist
69dd8ab4d9SJed Brown
70*e735508cSJeremy L Thompson      - uses: pypa/gh-action-pypi-publish@v1
71dd8ab4d9SJed Brown        with:
72dd8ab4d9SJed Brown          user: __token__
73dd8ab4d9SJed Brown          password: ${{ secrets.PYPI_TOKEN }}
74dd8ab4d9SJed Brown          # To test: repository_url: https://test.pypi.org/legacy/
75