-
Notifications
You must be signed in to change notification settings - Fork 1
250 lines (237 loc) · 8.35 KB
/
build.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: Build wheels
on:
push:
tags: '*'
pull_request: ~
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: false
jobs:
generate_wheels_matrix:
name: Generate wheels matrix
runs-on: ubuntu-latest
if: false
outputs:
include: ${{ steps.set-matrix.outputs.include }}
mypy_version: ${{ steps.mypy-version.outputs.mypy_version }}
mypy_sha: ${{ steps.mypy-version.outputs.mypy_sha }}
tag_version: ${{ steps.tag-version.outputs.tag_version }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.11"
- name: Install cibuildwheel and pypyp
run: |
pipx install cibuildwheel==2.21.2
pipx install pypyp==1
- id: set-matrix
run: |
MATRIX=$(
{
cibuildwheel --config-file=cibuildwheel.toml --print-build-identifiers --platform linux mypy \
| pyp 'json.dumps({"only": x, "os": "ubuntu-latest"})' \
&& cibuildwheel --config-file=cibuildwheel.toml --print-build-identifiers --platform macos mypy \
| pyp 'json.dumps({"only": x, "os": "macos-14"})' \
&& cibuildwheel --config-file=cibuildwheel.toml --print-build-identifiers --platform windows mypy \
| pyp 'json.dumps({"only": x, "os": "windows-latest"})'
} | pyp 'json.dumps(list(map(json.loads, lines)))'
)
echo "include=$MATRIX" | tee -a $GITHUB_OUTPUT
env:
CIBW_ARCHS_LINUX: x86_64
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_ARCHS_WINDOWS: AMD64
- name: Get mypy version
id: mypy-version
run: |
cd mypy
mypy_version=$(python -c "from mypy.version import __version__; print(__version__)")
mypy_sha=$(python -c "from mypy.git import git_revision as rev; print(rev('.').decode('utf-8'))")
echo "mypy_version: ${mypy_version}"
echo "mypy_version=${mypy_version}" >> $GITHUB_OUTPUT
echo "mypy_sha: ${mypy_sha}"
echo "mypy_sha=${mypy_sha}" >> $GITHUB_OUTPUT
- name: Get version tag
id: tag-version
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
echo "github_ref: ${{ github.ref }}"
tag_version=$(echo "${{ github.ref }}" | cut -d "/" -f3)
echo "tag_version: ${tag_version}"
mypy_base=$(echo "${{ steps.mypy-version.outputs.mypy_version }}" | cut -d "+" -f1)
echo "mypy_base: ${mypy_base}"
if [[ "${tag_version}" != "${mypy_base}"* ]]; then
echo "Base tag_version does not match base mypy_version!"
exit 1
fi
else
echo "Pull request or workflow dispatch"
echo "Set placeholder version"
tag_version=1.0.0
echo "tag_version: ${tag_version}"
fi
echo "tag_version=${tag_version}" >> $GITHUB_OUTPUT
build_wheels:
name: Build ${{ matrix.only }}
needs: generate_wheels_matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate_wheels_matrix.outputs.include) }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.11"
- name: Modify setup.py
run: |
pip install -U -r requirements.txt
python scripts/modify_setup.py ${{ needs.generate_wheels_matrix.outputs.tag_version }}
- uses: pypa/[email protected]
with:
config-file: cibuildwheel.toml
package-dir: mypy
only: ${{ matrix.only }}
- uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.only }}
path: ./wheelhouse/*.whl
overwrite: true
build_sdist_python_wheel:
name: sdist and python wheel
# needs: generate_wheels_matrix
runs-on: ubuntu-latest
# if: false
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.11"
- name: Modify setup.py
run: |
pip install -U -r requirements.txt
# python scripts/modify_setup.py ${{ needs.generate_wheels_matrix.outputs.tag_version }}
python scripts/modify_setup.py 1.12.0a5
- name: Build sdist and wheel
run: |
cd mypy
pip install --upgrade setuptools build
python -m build
- uses: actions/upload-artifact@v4
with:
name: dist-sdist_python_wheel
path: |
mypy/dist/*.whl
mypy/dist/*.tar.gz
overwrite: true
release:
name: Create release and upload assets
needs:
# - generate_wheels_matrix
# - build_wheels
- build_sdist_python_wheel
runs-on: ubuntu-latest
# environment:
# name: Release
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
permissions:
contents: write # Required to upload release assets
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
pattern: dist-*
path: dist
merge-multiple: true
- name: Release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// https://github.com/actions/upload-release-asset/issues/47
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
// const tagName = process.env.GITHUB_REF.split("/").pop();
// const body = (
// 'Tracking mypy version: `${{ needs.generate_wheels_matrix.outputs.mypy_version }}`'
// + '\n\n' + 'https://github.com/python/mypy/commit/${{ needs.generate_wheels_matrix.outputs.mypy_sha }}'
// );
const tagName = "1.12.0a5";
try {
const response = await github.rest.repos.getReleaseByTag({
owner, repo,
tag: tagName,
});
const assetNames = response.data.assets.map((asset) => asset.name);
console.log('Found an existing release');
} catch (error) {
const response = null;
const assetNames = [];
}
console.log('environment', process.versions);
console.log({ owner, repo, sha });
if (response == null) {
// const release = await github.rest.repos.createRelease({
// owner, repo,
// tag_name: tagName,
// target_commitish: sha,
// name: tagName,
// body: body,
// });
console.log('created release', { release });
}
for (let file of await fs.readdir('dist')) {
if (assetNames.find((name) => name == file) != undefined) {
console.log('asset already exists, skipping', file)
continue;
}
console.log('uploading', file);
continue;
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: release.data.id,
name: file,
data: await fs.readFile(`./dist/${file}`)
});
}
upload:
name: Upload release to PyPI
needs:
- release
runs-on: ubuntu-latest
if: false
environment:
name: PyPI
url: https://pypi.org/project/mypy-dev/
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
pattern: dist-*
path: dist
merge-multiple: true
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.11"
- name: Install twine
run: |
pip install twine
- name: Upload to PyPI
env:
TWINE_REPOSITORY: pypi
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload --verbose --skip-existing dist/*