From 02a17868b882e9a2c5596191e0e5edc444ba64e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Mon, 1 Dec 2025 19:43:39 +0100 Subject: [PATCH] Use unpublished local wheels during PR builds Refactor wheel building to use the new `local-wheels-repo-path` and move wheels building into a separate CI job. Wheels are only published on published (i.e. release or merged dev), for PR builds they are passed as artifacts to the build job instead. --- .dockerignore | 1 + .github/workflows/builder.yml | 103 ++++++++++++++++++++++++++-------- .gitignore | 5 +- Dockerfile | 12 +++- wheels/.gitkeep | 0 5 files changed, 97 insertions(+), 24 deletions(-) create mode 100644 wheels/.gitkeep diff --git a/.dockerignore b/.dockerignore index 50bda0041..93e0427ef 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ # General files .git .github +.gitkeep .devcontainer .vscode diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml index c54ed7433..e9864fcce 100644 --- a/.github/workflows/builder.yml +++ b/.github/workflows/builder.yml @@ -78,13 +78,80 @@ jobs: - name: Check if requirements files changed id: requirements run: | - if [[ "${{ steps.changed_files.outputs.all }}" =~ (requirements.txt|build.yaml) ]]; then + if [[ "${{ steps.changed_files.outputs.all }}" =~ (requirements.txt|build.yaml|builder.yml) ]]; then echo "changed=true" >> "$GITHUB_OUTPUT" fi + build_wheels: + name: Build wheels for ${{ matrix.arch }} + needs: init + if: needs.init.outputs.requirements == 'true' + runs-on: ${{ matrix.runs-on }} + strategy: + matrix: + arch: ${{ fromJson(needs.init.outputs.architectures) }} + include: + - runs-on: ubuntu-24.04 + - arch: aarch64 + runs-on: ubuntu-24.04-arm + + env: + ABI: cp313 + TAG: musllinux_1_2 + APK_DEPS: "libffi-dev;openssl-dev;yaml-dev" + SKIP_BINARY: aiohttp + steps: + - name: Checkout the repository + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + + - name: Write env-file + run: | + ( + # Fix out of memory issues with rust + echo "CARGO_NET_GIT_FETCH_WITH_CLI=true" + ) > .env_file + + - name: Build and publish wheels + if: needs.init.outputs.publish == 'true' + uses: home-assistant/wheels@e5742a69d69f0e274e2689c998900c7d19652c21 # 2025.12.0 + with: + wheels-key: ${{ secrets.WHEELS_KEY }} + abi: ${{ env.ABI }} + tag: ${{ env.TAG }} + arch: ${{ matrix.arch }} + apk: ${{ env.APK_DEPS }} + skip-binary: ${{ env.SKIP_BINARY }} + env-file: true + requirements: "requirements.txt" + + - name: Build local wheels + uses: home-assistant/wheels@e5742a69d69f0e274e2689c998900c7d19652c21 # 2025.12.0 + if: needs.init.outputs.publish == 'false' + with: + wheels-host: "" + wheels-user: "" + wheels-key: "" + local-wheels-repo-path: "wheels" + abi: ${{ env.ABI }} + tag: ${{ env.TAG }} + arch: ${{ matrix.arch }} + apk: ${{ env.APK_DEPS }} + skip-binary: ${{ env.SKIP_BINARY }} + env-file: true + requirements: "requirements.txt" + + - name: Upload local wheels artifact + if: needs.init.outputs.publish == 'false' + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: wheels-${{ matrix.arch }} + path: wheels + retention-days: 1 + build: name: Build ${{ matrix.arch }} supervisor - needs: init + needs: [init, build_wheels] + if: ${{ !cancelled() && !failure() }} runs-on: ubuntu-latest permissions: contents: read @@ -99,27 +166,12 @@ jobs: with: fetch-depth: 0 - - name: Write env-file - if: needs.init.outputs.requirements == 'true' - run: | - ( - # Fix out of memory issues with rust - echo "CARGO_NET_GIT_FETCH_WITH_CLI=true" - ) > .env_file - - # home-assistant/wheels doesn't support sha pinning - - name: Build wheels - if: needs.init.outputs.requirements == 'true' - uses: home-assistant/wheels@2025.11.0 + - name: Download local wheels artifact + if: needs.init.outputs.requirements == 'true' && needs.init.outputs.publish == 'false' + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 with: - abi: cp313 - tag: musllinux_1_2 - arch: ${{ matrix.arch }} - wheels-key: ${{ secrets.WHEELS_KEY }} - apk: "libffi-dev;openssl-dev;yaml-dev" - skip-binary: aiohttp - env-file: true - requirements: "requirements.txt" + name: wheels-${{ matrix.arch }} + path: wheels - name: Set version if: needs.init.outputs.publish == 'true' @@ -208,6 +260,13 @@ jobs: - name: Checkout the repository uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + - name: Download local wheels artifact + if: needs.init.outputs.requirements == 'true' && needs.init.outputs.publish == 'false' + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 + with: + name: wheels-amd64 + path: wheels + # home-assistant/builder doesn't support sha pinning - name: Build the Supervisor if: needs.init.outputs.publish != 'true' diff --git a/.gitignore b/.gitignore index c2fe5c403..c6fc15a3c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,9 @@ var/ .installed.cfg *.egg +# Local wheels +wheels/**/*.whl + # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. @@ -102,4 +105,4 @@ ENV/ /.dmypy.json # Mac -.DS_Store \ No newline at end of file +.DS_Store diff --git a/Dockerfile b/Dockerfile index 979dd3681..c07578f1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,17 @@ RUN \ # Install requirements RUN \ --mount=type=bind,source=./requirements.txt,target=/usr/src/requirements.txt \ - uv pip install --compile-bytecode --no-cache --no-build -r requirements.txt + --mount=type=bind,source=./wheels,target=/usr/src/wheels \ + if ls /usr/src/wheels/musllinux/* >/dev/null 2>&1; then \ + LOCAL_WHEELS=/usr/src/wheels/musllinux; \ + echo "Using local wheels from: $LOCAL_WHEELS"; \ + else \ + LOCAL_WHEELS=; \ + echo "No local wheels found"; \ + fi && \ + uv pip install --compile-bytecode --no-cache --no-build \ + -r requirements.txt \ + ${LOCAL_WHEELS:+--find-links $LOCAL_WHEELS} # Install Home Assistant Supervisor COPY . supervisor diff --git a/wheels/.gitkeep b/wheels/.gitkeep new file mode 100644 index 000000000..e69de29bb