-
Notifications
You must be signed in to change notification settings - Fork 1
204 lines (193 loc) · 6.86 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
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
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/[email protected]
with:
submodules: recursive
- uses: actions/[email protected]
name: Install Python
with:
python-version: "3.11"
- name: Install cibuildwheel and pypyp
run: |
pipx install cibuildwheel==2.16.5
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)
else
echo "Pull request or workflow dispatch"
echo "Set placeholder version"
tag_version=1.0.0
fi
echo "tag_version: ${tag_version}"
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/[email protected]
with:
submodules: recursive
- uses: actions/[email protected]
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/[email protected]
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
steps:
- uses: actions/[email protected]
with:
submodules: recursive
- uses: actions/[email protected]
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 }}
- name: Build sdist and wheel
run: |
cd mypy
pip install --upgrade setuptools build
python -m build
- uses: actions/[email protected]
with:
name: dist-sdist_python_wheel
path: |
mypy/dist/*.whl
mypy/dist/*.tar.gz
overwrite: true
release:
name: Upload release to PyPI
needs:
- generate_wheels_matrix
- build_wheels
- build_sdist_python_wheel
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
environment:
name: TestPyPI
url: https://test.pypi.org/project/mypy-dev/
permissions:
contents: write # Required to upload release assets
steps:
- name: Download artifact
uses: actions/[email protected]
with:
pattern: dist-*
path: dist
merge-multiple: true
- uses: actions/[email protected]
name: Install Python
with:
python-version: "3.11"
- name: Install twine
run: |
pip install twine
- 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 }}'
);
console.log('environment', process.versions);
console.log({ owner, repo, sha });
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')) {
console.log('uploading', file);
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: release.data.id,
name: file,
data: await fs.readFile(`./dist/${file}`)
});
}
- name: Upload to TestPyPI
env:
TWINE_REPOSITORY: testpypi
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
twine upload --verbose dist/*