11name : CHIP wheels build
22
3- on : push
3+ on :
4+ push :
5+ branches :
6+ - main
7+ - release
8+ pull_request :
49
510jobs :
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 }}
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 "*"
0 commit comments