Build wheels #3284
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build wheels | |
on: [push, pull_request, workflow_dispatch] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
generate_wheels_matrix: | |
name: Generate wheels matrix | |
runs-on: ubuntu-latest | |
outputs: | |
include: ${{ steps.set-matrix.outputs.include }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Checkout mypy | |
shell: bash | |
# use a commit hash checked into a file to get the mypy revision to build. | |
# submodules prove problematic since .git is outside cibuildwheel's manylinux container | |
run: | | |
git clone https://github.com/python/mypy.git --recurse-submodules | |
git -C mypy checkout $(cat mypy_commit) | |
- name: Install cibuildwheel and pypyp | |
run: | | |
pipx install cibuildwheel==2.22.0 | |
pipx install pypyp==1.2.0 | |
- 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-latest"})' \ | |
&& 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 | |
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 | |
- name: Checkout mypy | |
shell: bash | |
# use a commit hash checked into a file to get the mypy revision to build. | |
# submodules prove problematic since .git is outside cibuildwheel's manylinux container | |
run: | | |
git clone https://github.com/python/mypy.git --recurse-submodules | |
git -C mypy checkout $(cat mypy_commit) | |
- uses: pypa/cibuildwheel@v2.22.0 | |
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 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
name: Install Python | |
with: | |
python-version: "3.9" | |
- name: Checkout mypy | |
shell: bash | |
run: | | |
COMMIT=$(cat mypy_commit) | |
git clone https://github.com/python/mypy.git | |
cd mypy | |
git checkout $COMMIT | |
git submodule update --init --recursive | |
- name: Run check-manifest | |
run: | | |
cd mypy | |
pip install check-manifest | |
check-manifest -v | |
- 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 | |
build_wasm_wheel: | |
name: WASM wheel for 3.10 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
name: Install Python | |
with: | |
python-version: "3.10" | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 18.5.0 # pyodide tests with this version | |
- name: Install emscripten | |
id: install_emsdk | |
run: | | |
git clone https://github.com/emscripten-core/emsdk.git | |
cd emsdk | |
# Version of Emscripten pyodide 0.21.0 uses. | |
./emsdk install 3.1.14 | |
./emsdk activate 3.1.14 | |
# We need the location of emscripten when we use pyodide-build | |
echo "EMSCRIPTEN_DIR=$(pwd)" >> $GITHUB_OUTPUT | |
- name: Checkout mypy | |
shell: bash | |
run: | | |
COMMIT=$(cat mypy_commit) | |
git clone https://github.com/python/mypy.git | |
cd mypy | |
git checkout $COMMIT | |
git submodule update --init --recursive | |
- name: Install pyodide-build | |
run: | | |
python -m pip install "pyodide-build==0.21.0" | |
- name: Build wasm wheels | |
env: | |
MYPY_USE_MYPYC: "1" | |
MYPYC_OPT_LEVEL: "3" | |
EMSCRIPTEN_DIR: ${{ steps.install_emsdk.outputs.EMSCRIPTEN_DIR }} | |
run: | | |
cd mypy | |
source $EMSCRIPTEN_DIR/emsdk_env.sh | |
pyodide build --exports pyinit | |
- name: Install pyodide for WASM test | |
run: | | |
npm install pyodide@0.21.3 | |
- name: Run WASM smoke test | |
run: | | |
node wasm_test.js | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: dist-wasm_wheel | |
path: | | |
mypy/dist/*.whl | |
overwrite: true | |
release: | |
name: create release | |
needs: [build_wheels, build_sdist_python_wheel, build_wasm_wheel] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: dist-* | |
path: dist | |
merge-multiple: true | |
- name: Release | |
if: ${{ github.event_name != 'pull_request' }} | |
# https://github.com/actions/upload-release-asset/issues/47 | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs').promises; | |
const { repo: { owner, repo }, sha } = context; | |
console.log('environment', process.versions); | |
console.log({ owner, repo, sha }); | |
const release = await github.rest.repos.createRelease({ | |
owner, repo, | |
// if GITHUB_REF just appears to be a branch, use tag-{commit} as the tag | |
tag_name: process.env.GITHUB_REF.includes("refs/heads/") ? "tag-" + sha : process.env.GITHUB_REF.split("/").pop(), | |
target_commitish: sha | |
}); | |
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}`) | |
}); | |
} |