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