From 72a7fc9fd03a6758edd554ae2ae5f3c668e7bada Mon Sep 17 00:00:00 2001 From: agners <34061+agners@users.noreply.github.com> Date: Wed, 20 Nov 2024 04:44:51 +0000 Subject: [PATCH 1/3] Update Matter SDK to `c197bc2db8` --- connectedhomeip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectedhomeip b/connectedhomeip index d8ededa..c197bc2 160000 --- a/connectedhomeip +++ b/connectedhomeip @@ -1 +1 @@ -Subproject commit d8ededa4ada21149867032d96fab50c76e52ec9e +Subproject commit c197bc2db8c2079aa2af78c55fc647d048a70b5b From 7685c8df2f26a5e4bf804556da0f31f0212fd871 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 26 Nov 2024 13:41:42 +0100 Subject: [PATCH 2/3] Use minimal Debian 12 build container --- .github/workflows/build.yaml | 116 +++++++++++++++++++++++++++-------- Dockerfile | 26 ++++++++ 2 files changed, 118 insertions(+), 24 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 731ea5e..c1dbb20 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,11 @@ name: CHIP wheels build -on: push +on: + push: + branches: + - main + - release + pull_request: jobs: build_prepare: @@ -19,25 +24,19 @@ jobs: id: version shell: bash run: | - version=$(echo "${{ github.ref }}" | awk -F"/" '{print $NF}') - if [[ ! -z "${{ github.event.inputs.version }}" ]]; then - version="${{ github.event.inputs.version }}" - elif [[ "${version}" =~ (main|dev) ]]; then - today="$(date --utc '+%Y-%m-%d')" - midnight_timestamp="$(date --utc +%s --date=$today)" - calver_date="$(date --utc --date=$today '+%Y.%-m.dev%-d')" - commit_count="$(git rev-list --count --since=$midnight_timestamp HEAD)" - commit_count="$(printf "%02d" ${commit_count})" - version="${calver_date}${commit_count}" - elif [[ "${{ github.ref }}" =~ ^refs/heads/ ]]; then - today="$(date --utc '+%Y-%m-%d')" - midnight_timestamp="$(date --utc +%s --date=$today)" - calver_date="$(date --utc --date=$today '+%Y.%-m.dev%-d')" - # Remove invalid chars - localversion="${version}" - localversion="${localversion//-/}" - localversion="${localversion//_/}" - version="${calver_date}+${localversion}" + version="${{ github.ref_name }}" + today="$(date --utc '+%Y-%m-%d')" + midnight_timestamp="$(date --utc +%s --date=$today)" + calver_date="$(date --utc --date=$today '+%Y.%-m.dev%-d')" + if [ "${{ github.event_name }}" == "push" ]; then + if [[ "${version}" = "main" ]]; then + # Pushes to main branch are considered dev builds + commit_count="$(git rev-list --count --since=$midnight_timestamp HEAD)" + commit_count="$(printf "%02d" ${commit_count})" + version="${calver_date}${commit_count}" + fi + elif [ "${{ github.event_name }}" == "pull_request" ]; then + version="${calver_date}+pr${version%%/*}" fi echo "Building version $version" echo "version=$version" >> "$GITHUB_OUTPUT" @@ -68,18 +67,87 @@ jobs: name: matter-sdk-${{ github.run_id }} path: ./connectedhomeip.tar.zst + build_linux_build_container: + name: Build Linux container for Python wheels + runs-on: ubuntu-22.04 + + permissions: + contents: read + packages: write # Required for pushing containers to the registry + + outputs: + container_image: ${{ steps.set_container_tag.outputs.container_image }} + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensure we can compare changes + + - name: Determine Container Tag and Build Necessity + id: set_container_tag + run: | + build_needed=false + tag="${{ github.ref_name }}" + + if [ "${{ github.event_name }}" == "push" ]; then + if git diff --name-only ${{ github.event.before }} HEAD | grep -E '^Dockerfile'; then + echo "Dockerfile or related files changed; building container." + build_needed=true + fi + elif [ "${{ github.event_name }}" == "pull_request" ]; then + # For pull_request, use base_ref/head_ref + if [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]; then + echo "Forked PR detected; using base branch container." + tag="${{ github.base_ref }}" + else + tag="${{ github.head_ref }}" + git fetch origin ${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} + if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^Dockerfile'; then + echo "Dockerfile or related files changed; building container." + build_needed=true + fi + fi + fi + + echo "Using container with tag: ${tag}" + echo "container_image=ghcr.io/${{ github.repository }}/chip-wheels-builder:${tag}" >> $GITHUB_OUTPUT + echo "build_needed=${build_needed}" >> $GITHUB_ENV + + - name: Log in to GitHub Container Registry + if: ${{ env.build_needed == 'true' }} + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + if: ${{ env.build_needed == 'true' }} + + - name: Enable containerd snapshotter for multi-platform builds + uses: depot/use-containerd-snapshotter-action@v1 + if: ${{ env.build_needed == 'true' }} + + - name: Build and Push Docker Container + if: ${{ env.build_needed == 'true' }} + run: | + image="${{ steps.set_container_tag.outputs.container_image }}" + docker buildx build --platform linux/amd64,linux/arm64 -t ${image} --push . + build_linux_python_lib: name: Build Python wheels for Linux (${{ matrix.arch.name }}) - needs: build_prepare + needs: + - build_prepare + - build_linux_build_container strategy: matrix: arch: - name: x86_64 - container: ghcr.io/project-chip/chip-build:81 runner: ubuntu-22.04 - name: aarch64 - container: docker.io/agners/aarch64-chip-build:81 runner: ARM64 runs-on: ${{ matrix.arch.runner }} @@ -91,7 +159,7 @@ jobs: working-directory: ./connectedhomeip/ container: - image: ${{ matrix.arch.container }} + image: ${{ needs.build_linux_build_container.outputs.container_image }} volumes: - "/tmp/log_output:/tmp/test_logs" options: --sysctl "net.ipv6.conf.all.disable_ipv6=0 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b98390 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Based on integrations/docker/images/base/chip-build-minimal/Dockerfile +# Use Debian 12 bookworm and install all required dependencies to build and test +# the Python wheels. +FROM debian:12 +LABEL org.opencontainers.image.source https://github.com/project-chip/connectedhomeip + +RUN set -x \ + && apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + generate-ninja \ + git pkg-config \ + ninja-build \ + python3-venv \ + && git config --global advice.detachedHead false + +# CHIP build dependencies +RUN set -x \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libssl-dev libglib2.0-dev \ + libnl-3-dev libnl-route-3-dev \ + libcairo2-dev libgirepository1.0-dev \ + libdbus-1-dev \ + python3-dev From ae4baf947e121b696a5f6ca9e4916bc5c127aeb2 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 27 Nov 2024 17:24:40 +0100 Subject: [PATCH 3/3] Include zstd into the build container --- .github/workflows/build.yaml | 1 - Dockerfile | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c1dbb20..4a07126 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -173,7 +173,6 @@ jobs: - name: Extract Matter SDK from tar working-directory: ./ run: | - apt-get -qq update && apt-get -qq --yes install zstd rm -rf connectedhomeip/ tar -xaf ./connectedhomeip.tar.zst --use-compress-program=zstdmt . git config --global --add safe.directory "*" diff --git a/Dockerfile b/Dockerfile index 1b98390..f1da389 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,5 @@ RUN set -x \ libnl-3-dev libnl-route-3-dev \ libcairo2-dev libgirepository1.0-dev \ libdbus-1-dev \ - python3-dev + python3-dev \ + zstd