Build and Publish Wheels #91
This file contains hidden or 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 and Publish Wheels | |
| on: [workflow_dispatch] | |
| env: | |
| USING_PYTHON_VERSION: '3.13.9' | |
| jobs: | |
| prepare: | |
| runs-on: tenki-standard-autoscale | |
| outputs: | |
| LATEST_TDLIB_VERSION: ${{ steps.vars.outputs.LATEST_TDLIB_VERSION }} | |
| LATEST_TDLIB_COMMIT_HASH: ${{ steps.vars.outputs.LATEST_TDLIB_COMMIT_HASH }} | |
| PYPI_RELEASE_VERSION: ${{ steps.vars.outputs.PYPI_RELEASE_VERSION }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ env.USING_PYTHON_VERSION }} | |
| - name: Install dependencies | |
| run: python -m pip install --upgrade packaging requests | |
| - name: Fetch TDLib version and commit hash | |
| id: vars | |
| run: | | |
| LATEST_TDLIB_COMMIT_HASH=$(git ls-remote https://github.com/tdlib/td.git refs/heads/master | cut -f1) | |
| LATEST_TDLIB_VERSION=$(curl -s "https://raw.githubusercontent.com/tdlib/td/$LATEST_TDLIB_COMMIT_HASH/CMakeLists.txt" | grep -oP 'project\(TDLib VERSION \K[0-9\.]+') | |
| PYPI_RELEASE_VERSION=$(python next_version.py $LATEST_TDLIB_VERSION) | |
| echo "LATEST_TDLIB_COMMIT_HASH=$LATEST_TDLIB_COMMIT_HASH" >> $GITHUB_OUTPUT | |
| echo "LATEST_TDLIB_VERSION=$LATEST_TDLIB_VERSION" >> $GITHUB_OUTPUT | |
| echo "PYPI_RELEASE_VERSION=$PYPI_RELEASE_VERSION" >> $GITHUB_OUTPUT | |
| - name: Apply version changes | |
| run: | | |
| LATEST_TDLIB_VERSION=${{ steps.vars.outputs.LATEST_TDLIB_VERSION }} | |
| PYPI_RELEASE_VERSION=${{ steps.vars.outputs.PYPI_RELEASE_VERSION }} | |
| sed -i -r "s/^__version__ = \".*\"/__version__ = \"$PYPI_RELEASE_VERSION\"/" tdjson/_version.py | |
| sed -i -r "s|(https://img.shields.io/badge/TDLib-v)[0-9\.]+(-blue)|\\1$LATEST_TDLIB_VERSION\\2|" README.md | |
| - name: Upload updated files | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: updated-files | |
| path: | | |
| tdjson/_version.py | |
| README.md | |
| linux-build: | |
| needs: prepare | |
| strategy: | |
| matrix: | |
| runner: [tenki-standard-autoscale, ubuntu-24.04-arm] | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download updated files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: updated-files | |
| path: . | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ env.USING_PYTHON_VERSION }} | |
| - name: Install dependencies | |
| run: python -m pip install --upgrade scikit-build-core nanobind build ninja cibuildwheel auditwheel | |
| - name: Build wheels | |
| run: | | |
| mkdir -p ./wheelhouse | |
| python -m cibuildwheel . --output-dir ./wheelhouse | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.runner }} | |
| path: ./wheelhouse/*.whl | |
| windows-build: | |
| needs: prepare | |
| runs-on: windows-2022 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download updated files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: updated-files | |
| path: . | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ env.USING_PYTHON_VERSION }} | |
| - name: Install Python dependencies | |
| shell: bash | |
| run: python -m pip install --upgrade cibuildwheel | |
| - name: Build TDLib | |
| shell: bash | |
| run: | | |
| git clone --depth 1 https://github.com/tdlib/td.git | |
| cd td | |
| sed -i ' | |
| /^if[[:space:]]*(NOT CMAKE_CROSSCOMPILING)[[:space:]]*$/{ | |
| N | |
| s/^if[[:space:]]*(NOT CMAKE_CROSSCOMPILING)[[:space:]]*\n[[:space:]]*add_executable(tg_cli /if (FALSE)\n add_executable(tg_cli / | |
| } | |
| ' CMakeLists.txt | |
| sed -i ' | |
| s/^[[:space:]]*add_subdirectory(benchmark)[[:space:]]*$/# add_subdirectory(benchmark)/; | |
| s/^[[:space:]]*add_subdirectory(test)[[:space:]]*$/# add_subdirectory(test)/ | |
| ' CMakeLists.txt | |
| cat << EOF > vcpkg.json | |
| { | |
| "dependencies": [ "gperf", "openssl", "zlib" ], | |
| "builtin-baseline": "afb2279ad78a7c29b5293d989b9a1a2ca00000cf", | |
| "overrides": [ | |
| { "name": "openssl", "version": "1.1.1m" } | |
| ] | |
| } | |
| EOF | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| cd vcpkg | |
| ./bootstrap-vcpkg.bat | |
| cd .. | |
| rm -rf build | |
| mkdir build | |
| cd build | |
| cmake -A x64 -DTD_ENABLE_MULTI_PROCESSOR_COMPILATION=ON -DCMAKE_INSTALL_PREFIX:PATH=../tdlib -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../vcpkg/scripts/buildsystems/vcpkg.cmake .. | |
| cmake --build . --target install --config Release -j3 | |
| cd ../.. | |
| ls -l td/tdlib | |
| echo "${{ github.workspace }}/td/tdlib/bin" >> $GITHUB_PATH | |
| - name: Build wheels | |
| shell: bash | |
| env: | |
| CMAKE_PREFIX_PATH: ${{ github.workspace }}/td/tdlib | |
| run: | | |
| mkdir -p ./wheelhouse | |
| python -m cibuildwheel . --output-dir ./wheelhouse | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-windows | |
| path: ./wheelhouse/*.whl | |
| macos-build: | |
| needs: prepare | |
| runs-on: tenki-macos-latest-small | |
| env: | |
| MACOSX_DEPLOYMENT_TARGET: "11.0" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download updated files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: updated-files | |
| path: . | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ env.USING_PYTHON_VERSION }} | |
| - name: Install Python dependencies | |
| run: python -m pip install --upgrade cibuildwheel | |
| - name: Build OpenSSL 1.1.1 | |
| run: | | |
| sudo -E git clone --depth 1 --branch OpenSSL_1_1_1-stable https://github.com/openssl/openssl.git | |
| cd openssl | |
| sudo -E perl ./Configure darwin64-arm64-cc --prefix=/usr/local --openssldir=/usr/local/openssl | |
| sudo -E make -j | |
| sudo -E make install MANDIR=/usr/local/openssl/share/man MANSUFFIX=ssl | |
| - name: Build TDLib | |
| run: | | |
| git clone https://github.com/tdlib/td.git | |
| cd td | |
| sed -i '' ' | |
| /^if[[:space:]]*(NOT CMAKE_CROSSCOMPILING)[[:space:]]*$/{ | |
| N | |
| s/^if[[:space:]]*(NOT CMAKE_CROSSCOMPILING)[[:space:]]*\n[[:space:]]*add_executable(tg_cli /if (FALSE)\n add_executable(tg_cli / | |
| } | |
| ' CMakeLists.txt | |
| sed -i '' ' | |
| s/^[[:space:]]*add_subdirectory(benchmark)[[:space:]]*$/# add_subdirectory(benchmark)/; | |
| s/^[[:space:]]*add_subdirectory(test)[[:space:]]*$/# add_subdirectory(test)/ | |
| ' CMakeLists.txt | |
| rm -rf build | |
| mkdir build | |
| cd build | |
| sudo -E cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local -DCMAKE_INSTALL_PREFIX:PATH=/usr/local -DTD_ENABLE_LTO=ON .. | |
| sudo -E cmake --build . --target install | |
| cd .. | |
| cd .. | |
| ls -l /usr/local | |
| - name: Build wheels | |
| run: | | |
| mkdir -p ./wheelhouse | |
| sudo -E python -m cibuildwheel . --output-dir ./wheelhouse | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-macos | |
| path: ./wheelhouse/*.whl | |
| publish: | |
| needs: [prepare, linux-build, windows-build] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all wheels | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: wheels-* | |
| merge-multiple: true | |
| path: ./dist | |
| - name: Download updated files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: updated-files | |
| path: . | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| - name: Commit updated files | |
| uses: EndBug/add-and-commit@v9 | |
| with: | |
| message: "Update TDLib to ${{ needs.prepare.outputs.LATEST_TDLIB_VERSION }} (tdlib/td@${{ needs.prepare.outputs.LATEST_TDLIB_COMMIT_HASH }})" | |
| add: '["README.md", "tdjson/_version.py"]' | |
| committer_name: GitHub Actions | |
| committer_email: 41898282+github-actions[bot]@users.noreply.github.com |