|
1 | 1 | name: CHIP wheels build
|
2 | 2 |
|
3 |
| -on: push |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - release |
| 8 | + pull_request: |
4 | 9 |
|
5 | 10 | jobs:
|
6 | 11 | build_prepare:
|
@@ -68,18 +73,87 @@ jobs:
|
68 | 73 | name: matter-sdk-${{ github.run_id }}
|
69 | 74 | path: ./connectedhomeip.tar.zst
|
70 | 75 |
|
| 76 | + build_linux_build_container: |
| 77 | + name: Build Linux container for Python wheels |
| 78 | + runs-on: ubuntu-22.04 |
| 79 | + |
| 80 | + permissions: |
| 81 | + contents: read |
| 82 | + packages: write # Required for pushing containers to the registry |
| 83 | + |
| 84 | + outputs: |
| 85 | + container_image: ${{ steps.set_container_tag.outputs.container_image }} |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Checkout Repository |
| 89 | + uses: actions/checkout@v4 |
| 90 | + with: |
| 91 | + fetch-depth: 0 # Ensure we can compare changes |
| 92 | + |
| 93 | + - name: Determine Container Tag and Build Necessity |
| 94 | + id: set_container_tag |
| 95 | + run: | |
| 96 | + build_needed=false |
| 97 | + tag="${{ github.ref_name }}" |
| 98 | +
|
| 99 | + if [ "${{ github.event_name }}" == "push" ]; then |
| 100 | + if git diff --name-only ${{ github.event.before }} HEAD | grep -E '^Dockerfile'; then |
| 101 | + echo "Dockerfile or related files changed; building container." |
| 102 | + build_needed=true |
| 103 | + fi |
| 104 | + elif [ "${{ github.event_name }}" == "pull_request" ]; then |
| 105 | + # For pull_request, use base_ref/head_ref |
| 106 | + if [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]; then |
| 107 | + echo "Forked PR detected; using base branch container." |
| 108 | + tag="${{ github.base_ref }}" |
| 109 | + else |
| 110 | + tag="${{ github.head_ref }}" |
| 111 | + git fetch origin ${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} |
| 112 | + if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^Dockerfile'; then |
| 113 | + echo "Dockerfile or related files changed; building container." |
| 114 | + build_needed=true |
| 115 | + fi |
| 116 | + fi |
| 117 | + fi |
| 118 | +
|
| 119 | + echo "Using container with tag: ${tag}" |
| 120 | + echo "container_image=ghcr.io/${{ github.repository }}/chip-wheels-builder:${tag}" >> $GITHUB_OUTPUT |
| 121 | + echo "build_needed=${build_needed}" >> $GITHUB_ENV |
| 122 | +
|
| 123 | + - name: Log in to GitHub Container Registry |
| 124 | + if: ${{ env.build_needed == 'true' }} |
| 125 | + uses: docker/login-action@v2 |
| 126 | + with: |
| 127 | + registry: ghcr.io |
| 128 | + username: ${{ github.actor }} |
| 129 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 130 | + |
| 131 | + - name: Set up Docker Buildx |
| 132 | + uses: docker/setup-buildx-action@v3 |
| 133 | + if: ${{ env.build_needed == 'true' }} |
| 134 | + |
| 135 | + - name: Enable containerd snapshotter for multi-platform builds |
| 136 | + uses: depot/use-containerd-snapshotter-action@v1 |
| 137 | + if: ${{ env.build_needed == 'true' }} |
| 138 | + |
| 139 | + - name: Build and Push Docker Container |
| 140 | + if: ${{ env.build_needed == 'true' }} |
| 141 | + run: | |
| 142 | + image="${{ steps.set_container_tag.outputs.container_image }}" |
| 143 | + docker buildx build --platform linux/amd64,linux/arm64 -t ${image} --push . |
| 144 | +
|
71 | 145 | build_linux_python_lib:
|
72 | 146 | name: Build Python wheels for Linux (${{ matrix.arch.name }})
|
73 |
| - needs: build_prepare |
| 147 | + needs: |
| 148 | + - build_prepare |
| 149 | + - build_linux_build_container |
74 | 150 |
|
75 | 151 | strategy:
|
76 | 152 | matrix:
|
77 | 153 | arch:
|
78 | 154 | - name: x86_64
|
79 |
| - container: ghcr.io/project-chip/chip-build:81 |
80 | 155 | runner: ubuntu-22.04
|
81 | 156 | - name: aarch64
|
82 |
| - container: docker.io/agners/aarch64-chip-build:81 |
83 | 157 | runner: ARM64
|
84 | 158 |
|
85 | 159 | runs-on: ${{ matrix.arch.runner }}
|
|
91 | 165 | working-directory: ./connectedhomeip/
|
92 | 166 |
|
93 | 167 | container:
|
94 |
| - image: ${{ matrix.arch.container }} |
| 168 | + image: ${{ needs.build_linux_build_container.outputs.container_image }} |
95 | 169 | volumes:
|
96 | 170 | - "/tmp/log_output:/tmp/test_logs"
|
97 | 171 | options: --sysctl "net.ipv6.conf.all.disable_ipv6=0
|
|
0 commit comments