forked from isagalaev/ijson
-
Notifications
You must be signed in to change notification settings - Fork 53
160 lines (137 loc) · 4.71 KB
/
deploy-to-pypi.yml
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Build distributions and upload to PyPI
# Build on every branch push, tag push, and pull request change:
on:
push:
pull_request:
schedule:
# 00:00 UTC every Saturday, don't bother anyone
- cron: '0 0 * * 6'
jobs:
calculate_wheels_to_build:
name: Calculate OS/archs to build wheels on
runs-on: ubuntu-latest
env:
BUILD_TYPE: ${{ (startsWith(github.event.ref, 'refs/tags/v') || github.event.schedule == '0 0 * * 6') && 'FULL' || 'BASE' }}
ARCHS_LINUX_BASE: '["x86_64"]'
ARCHS_LINUX_FULL: '["x86_64", "i686", "aarch64"]'
ARCHS_MACOS_BASE: '["x86_64"]'
ARCHS_MACOS_FULL: '["x86_64", "arm64", "universal2"]'
ARCHS_WINDOWS_BASE: '["AMD64"]'
ARCHS_WINDOWS_FULL: '["AMD64", "x86"]'
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Calculate strategy matrix
shell: python
id: set-matrix
run: |
import json
import os
combinations = (
("ubuntu-latest", "ARCHS_LINUX"),
("macos-12", "ARCHS_MACOS"),
("windows-2019", "ARCHS_WINDOWS"),
)
build_type = os.getenv("BUILD_TYPE")
includes = [
{"os": os_name, "arch": arch}
for os_name, archs_envvar in combinations
for arch in json.loads(os.getenv(f'{archs_envvar}_{build_type}'))
]
matrix = {"include": includes}
with open(os.getenv("GITHUB_OUTPUT"), "at") as github_output:
github_output.write(f'matrix={json.dumps(matrix)}')
print(f"Calculated matrix strategy:\n{json.dumps(matrix, indent=2)}")
build_wheels:
name: Build wheels for ${{ matrix.os }} / ${{matrix.arch}}
needs: calculate_wheels_to_build
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJson(needs.calculate_wheels_to_build.outputs.matrix) }}
env:
CIBW_ARCHS: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: docker/setup-qemu-action@v3
if: ${{ matrix.arch == 'aarch64' && matrix.os == 'ubuntu-latest' }}
name: Set up QEMU
- name: Build wheels
uses: pypa/cibuildwheel@v2.21.1
with:
output-dir: wheelhouse
env:
CIBW_BEFORE_ALL: "bash -c 'cd \"{project}\"; sh .github/tools/install_yajl.sh'"
CIBW_BUILD_VERBOSITY: 1
CIBW_ENVIRONMENT_MACOS: "IJSON_EMBED_YAJL=1"
CIBW_ENVIRONMENT_WINDOWS: "IJSON_EMBED_YAJL=1"
CIBW_BEFORE_TEST: pip install -r test-requirements.txt
CIBW_TEST_COMMAND: "bash -c 'cd \"{project}\"; pytest -vv'"
# Our C extension made PyPy < 7.3.13 crash (a bug on their end)
# it doesn't make sense to build wheels for platforms not supported
# not supported by that version
CIBW_SKIP: pp{37,38,39}*
CIBW_FREE_THREADED_SUPPORT: 1
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ matrix.arch }}
path: ./wheelhouse/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.12'
- name: Install build
run: pip install build
- name: Build sdist
run: python -m build -s
- uses: actions/upload-artifact@v4
with:
name: source-dist
path: dist/*.tar.gz
test_sdist:
name: Check source distribution is usable
needs: [build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.12"
- uses: actions/download-artifact@v4
with:
name: source-dist
- name: Extract source distribution
run: tar xvf ijson*.tar.gz && rm ijson*.tar.gz
- name: Install source distribution
run: pip install ./ijson*
- name: Install test dependencies
run: pip install pytest cffi
- name: Run source distribution tests
run: cd ijson* && pytest
merge_artifacts:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: all-artifacts
upload_pypi:
needs: [merge_artifacts]
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v4
with:
name: all-artifacts
path: dist
- uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}