From 179562a8c6ee65b4cd59104ef8cf9475e13d93d5 Mon Sep 17 00:00:00 2001 From: WSH032 <614337162@qq.com> Date: Mon, 18 Dec 2023 05:59:08 +0800 Subject: [PATCH] build(ci): cross-build wheels by setting `env` variables in github workflows --- .github/workflows/publish.yml | 47 +++++++++++++++++++++++++++++++---- hatch_build.py | 1 + 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4dff41b..e423201 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,10 +16,46 @@ jobs: uses: ./.github/workflows/lint-test.yml secrets: inherit # IMPORTANT: sub-workflow needs secrets for uploading codecov - build-dist: + build-wheel: needs: - lint-test - name: Build distribution 📦 + name: Build wheel distribution 📦 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # keep `cross_host` consistent with `tag_4_build_enum` in `hatch_build.py` + cross_host: + - x86_64-linux-musl + - aarch64-linux-musl + - x86_64-w64-mingw32 + - i686-w64-mingw32 + env: + CROSS_HOST: ${{ matrix.cross_host }} + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install hatch + - name: Build a binary wheel + run: | + hatch build --target wheel -c + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + if-no-files-found: error + + build-sdist: + needs: + - lint-test + name: Build sdist distribution 📦 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -31,9 +67,9 @@ jobs: run: | python -m pip install --upgrade pip pip install hatch - - name: Build a binary wheel and a source tarball + - name: Build a sdist run: | - hatch build + hatch build --target sdist - name: Store the distribution packages uses: actions/upload-artifact@v4 with: @@ -43,7 +79,8 @@ jobs: publish-to-pypi: needs: - - build-dist + - build-wheel + - build-sdist name: Publish Python 🐍 distribution 📦 to PyPI runs-on: ubuntu-latest environment: diff --git a/hatch_build.py b/hatch_build.py index 94759fd..fc75dfe 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -52,6 +52,7 @@ class Tag4Build(NamedTuple): whl_platform: str +# keep all of `Tag4Build().aria2_build` consistent with `matrix.cross_host` in `.github\workflows\publish.yml` tag_4_build_enum = ( Tag4Build("x86_64-linux-musl", "linux_x86_64"), Tag4Build("aarch64-linux-musl", "linux_aarch64"),