summaryrefslogtreecommitdiff
path: root/.github/workflows/create-wheels.yaml
blob: e560ef644afb16f7e201351f66b8b7f988f2e9da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Create wheel

on:
  # run when a release has been created
  release:
    types: [created]
  # push:
  #   branches:
  #     - "go_wheel_*"

# env:
#   # comment TWINE_REPOSITORY_URL to use the real pypi. NOTE: change also the secret used in TWINE_PASSWORD
#   TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/

jobs:
  build_wheels:
    name: ${{ matrix.wheel_mode }} wheels ${{ matrix.python }} on ${{ matrix.os }} ${{ matrix.os == 'ubuntu-22.04' && matrix.linux_archs || '' }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        # emulated wheels on linux take too much time, split wheels into multiple runs
        python:
          - "cp37-* cp38-*"
          - "cp39-* cp310-*"
          - "cp311-*"
        wheel_mode:
          - compiled
        os:
          - "windows-2022"
          - "macos-12"
          - "ubuntu-22.04"
        linux_archs:
          # this is only meaningful on linux. windows and macos ignore exclude all but one arch
          - "aarch64"
          - "x86_64"

        include:
          # create pure python build
          - os: ubuntu-22.04
            wheel_mode: pure-python
            python: "cp-311*"

        exclude:
          - os: "windows-2022"
            linux_archs: "aarch64"
          - os: "macos-12"
            linux_archs: "aarch64"

      fail-fast: false

    steps:
      - uses: actions/checkout@v3

      - name: Remove tag_build from setup.cfg
        # sqlalchemy has `tag_build` set to `dev` in setup.cfg. We need to remove it before creating the weel
        # otherwise it gets tagged with `dev0`
        shell: pwsh
        # This is equivalent to the sed commands:
        # `sed -i '/tag_build=dev/d' setup.cfg`
        # `sed -i '/tag_build = dev/d' setup.cfg`

        # `-replace` uses a regexp match
        # alternative form: `(get-content setup.cfg) | foreach-object{$_ -replace "tag_build.=.dev",""} | set-content setup.cfg`
        run: |
          (cat setup.cfg) | %{$_ -replace "tag_build.?=.?dev",""} | set-content setup.cfg

      # See details at https://cibuildwheel.readthedocs.io/en/stable/faq/#emulation
      - name: Set up QEMU on linux
        if: ${{ runner.os == 'Linux' }}
        uses: docker/setup-qemu-action@v2
        with:
          platforms: all

      - name: Build compiled wheels
        if: ${{ matrix.wheel_mode == 'compiled' }}
        uses: pypa/cibuildwheel@v2.12.3
        env:
          CIBW_ARCHS_LINUX: ${{ matrix.linux_archs }}
          CIBW_BUILD: ${{ matrix.python }}
          # setting it here does not work on linux
          # PYTHONNOUSERSITE: "1"


      - name: Set up Python for twine and pure-python wheel
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: Build pure-python wheel
        if: ${{ matrix.wheel_mode == 'pure-python' && runner.os == 'Linux' }}
        run: |
          python -m pip install --upgrade pip
          pip --version
          pip install build
          pip list
          DISABLE_SQLALCHEMY_CEXT=y python -m build --wheel --outdir ./wheelhouse

      # - uses: actions/upload-artifact@v3
      #   with:
      #     path: ./wheelhouse/*.whl

      - name: Upload wheels to release
        # upload the generated wheels to the github release
        uses: sqlalchemyorg/upload-release-assets@sa
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          files: './wheelhouse/*.whl'

      - name: Publish wheel
        # the action https://github.com/marketplace/actions/pypi-publish runs only on linux and we cannot specify
        # additional options
        env:
          TWINE_USERNAME: __token__
          # replace TWINE_PASSWORD with token for real pypi
          # TWINE_PASSWORD: ${{ secrets.test_pypi_token }}
          TWINE_PASSWORD: ${{ secrets.pypi_token }}
        run: |
          pip install -U twine
          twine upload --skip-existing ./wheelhouse/*