Skip to content

Commit 7412697

Browse files
authored
Merge pull request #112 from home-assistant-libs/merge-gh-action-changes
Merge branch 'main' into release
2 parents 5b9d916 + d94133c commit 7412697

File tree

2 files changed

+119
-25
lines changed

2 files changed

+119
-25
lines changed

.github/workflows/build.yaml

+92-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: CHIP wheels build
22

3-
on: push
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release
8+
pull_request:
49

510
jobs:
611
build_prepare:
@@ -19,25 +24,19 @@ jobs:
1924
id: version
2025
shell: bash
2126
run: |
22-
version=$(echo "${{ github.ref }}" | awk -F"/" '{print $NF}')
23-
if [[ ! -z "${{ github.event.inputs.version }}" ]]; then
24-
version="${{ github.event.inputs.version }}"
25-
elif [[ "${version}" =~ (main|dev) ]]; then
26-
today="$(date --utc '+%Y-%m-%d')"
27-
midnight_timestamp="$(date --utc +%s --date=$today)"
28-
calver_date="$(date --utc --date=$today '+%Y.%-m.dev%-d')"
29-
commit_count="$(git rev-list --count --since=$midnight_timestamp HEAD)"
30-
commit_count="$(printf "%02d" ${commit_count})"
31-
version="${calver_date}${commit_count}"
32-
elif [[ "${{ github.ref }}" =~ ^refs/heads/ ]]; then
33-
today="$(date --utc '+%Y-%m-%d')"
34-
midnight_timestamp="$(date --utc +%s --date=$today)"
35-
calver_date="$(date --utc --date=$today '+%Y.%-m.dev%-d')"
36-
# Remove invalid chars
37-
localversion="${version}"
38-
localversion="${localversion//-/}"
39-
localversion="${localversion//_/}"
40-
version="${calver_date}+${localversion}"
27+
version="${{ github.ref_name }}"
28+
today="$(date --utc '+%Y-%m-%d')"
29+
midnight_timestamp="$(date --utc +%s --date=$today)"
30+
calver_date="$(date --utc --date=$today '+%Y.%-m.dev%-d')"
31+
if [ "${{ github.event_name }}" == "push" ]; then
32+
if [[ "${version}" = "main" ]]; then
33+
# Pushes to main branch are considered dev builds
34+
commit_count="$(git rev-list --count --since=$midnight_timestamp HEAD)"
35+
commit_count="$(printf "%02d" ${commit_count})"
36+
version="${calver_date}${commit_count}"
37+
fi
38+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
39+
version="${calver_date}+pr${version%%/*}"
4140
fi
4241
echo "Building version $version"
4342
echo "version=$version" >> "$GITHUB_OUTPUT"
@@ -68,18 +67,87 @@ jobs:
6867
name: matter-sdk-${{ github.run_id }}
6968
path: ./connectedhomeip.tar.zst
7069

70+
build_linux_build_container:
71+
name: Build Linux container for Python wheels
72+
runs-on: ubuntu-22.04
73+
74+
permissions:
75+
contents: read
76+
packages: write # Required for pushing containers to the registry
77+
78+
outputs:
79+
container_image: ${{ steps.set_container_tag.outputs.container_image }}
80+
81+
steps:
82+
- name: Checkout Repository
83+
uses: actions/checkout@v4
84+
with:
85+
fetch-depth: 0 # Ensure we can compare changes
86+
87+
- name: Determine Container Tag and Build Necessity
88+
id: set_container_tag
89+
run: |
90+
build_needed=false
91+
tag="${{ github.ref_name }}"
92+
93+
if [ "${{ github.event_name }}" == "push" ]; then
94+
if git diff --name-only ${{ github.event.before }} HEAD | grep -E '^Dockerfile'; then
95+
echo "Dockerfile or related files changed; building container."
96+
build_needed=true
97+
fi
98+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
99+
# For pull_request, use base_ref/head_ref
100+
if [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]; then
101+
echo "Forked PR detected; using base branch container."
102+
tag="${{ github.base_ref }}"
103+
else
104+
tag="${{ github.head_ref }}"
105+
git fetch origin ${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
106+
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^Dockerfile'; then
107+
echo "Dockerfile or related files changed; building container."
108+
build_needed=true
109+
fi
110+
fi
111+
fi
112+
113+
echo "Using container with tag: ${tag}"
114+
echo "container_image=ghcr.io/${{ github.repository }}/chip-wheels-builder:${tag}" >> $GITHUB_OUTPUT
115+
echo "build_needed=${build_needed}" >> $GITHUB_ENV
116+
117+
- name: Log in to GitHub Container Registry
118+
if: ${{ env.build_needed == 'true' }}
119+
uses: docker/login-action@v2
120+
with:
121+
registry: ghcr.io
122+
username: ${{ github.actor }}
123+
password: ${{ secrets.GITHUB_TOKEN }}
124+
125+
- name: Set up Docker Buildx
126+
uses: docker/setup-buildx-action@v3
127+
if: ${{ env.build_needed == 'true' }}
128+
129+
- name: Enable containerd snapshotter for multi-platform builds
130+
uses: depot/use-containerd-snapshotter-action@v1
131+
if: ${{ env.build_needed == 'true' }}
132+
133+
- name: Build and Push Docker Container
134+
if: ${{ env.build_needed == 'true' }}
135+
run: |
136+
image="${{ steps.set_container_tag.outputs.container_image }}"
137+
docker buildx build --platform linux/amd64,linux/arm64 -t ${image} --push .
138+
71139
build_linux_python_lib:
72140
name: Build Python wheels for Linux (${{ matrix.arch.name }})
73-
needs: build_prepare
141+
needs:
142+
- build_prepare
143+
- build_linux_build_container
74144

75145
strategy:
76146
matrix:
77147
arch:
78148
- name: x86_64
79-
container: ghcr.io/project-chip/chip-build:81
80149
runner: ubuntu-22.04
81150
- name: aarch64
82-
container: docker.io/agners/aarch64-chip-build:81
83151
runner: ARM64
84152

85153
runs-on: ${{ matrix.arch.runner }}
@@ -91,7 +159,7 @@ jobs:
91159
working-directory: ./connectedhomeip/
92160

93161
container:
94-
image: ${{ matrix.arch.container }}
162+
image: ${{ needs.build_linux_build_container.outputs.container_image }}
95163
volumes:
96164
- "/tmp/log_output:/tmp/test_logs"
97165
options: --sysctl "net.ipv6.conf.all.disable_ipv6=0
@@ -105,7 +173,6 @@ jobs:
105173
- name: Extract Matter SDK from tar
106174
working-directory: ./
107175
run: |
108-
apt-get -qq update && apt-get -qq --yes install zstd
109176
rm -rf connectedhomeip/
110177
tar -xaf ./connectedhomeip.tar.zst --use-compress-program=zstdmt .
111178
git config --global --add safe.directory "*"

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Based on integrations/docker/images/base/chip-build-minimal/Dockerfile
2+
# Use Debian 12 bookworm and install all required dependencies to build and test
3+
# the Python wheels.
4+
FROM debian:12
5+
LABEL org.opencontainers.image.source https://github.com/project-chip/connectedhomeip
6+
7+
RUN set -x \
8+
&& apt-get update \
9+
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
10+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
11+
build-essential \
12+
ca-certificates \
13+
generate-ninja \
14+
git pkg-config \
15+
ninja-build \
16+
python3-venv \
17+
&& git config --global advice.detachedHead false
18+
19+
# CHIP build dependencies
20+
RUN set -x \
21+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
22+
libssl-dev libglib2.0-dev \
23+
libnl-3-dev libnl-route-3-dev \
24+
libcairo2-dev libgirepository1.0-dev \
25+
libdbus-1-dev \
26+
python3-dev \
27+
zstd

0 commit comments

Comments
 (0)