Skip to content

Commit cb2e817

Browse files
committed
Refactor workflows to use matrix.version with include pattern
Workflow changes: - Add matrix.version as primary version identifier (without product prefix) - Use matrix.include to map version to component versions for build-args - Update ESP-IDF: matrix.version: ['v5.4.1'] with idf_base_tag in include - Update PlatformIO: matrix.version: ['v6.1.18'] with pio_version in include - Product prefixes (idf-, pio-) added dynamically in tags - ESP-Matter already uses this pattern with composite version Documentation: - Update GitHub Actions standards with Matrix Version Pattern section - Document version pattern with real examples from all three workflows - Update workflow structure template to show include pattern - Clarify benefits: single source of truth, easy to expand, consistent
1 parent 1e442a1 commit cb2e817

File tree

3 files changed

+93
-16
lines changed

3 files changed

+93
-16
lines changed

.cursor/rules/github-actions-standards.mdc

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ jobs:
110110
strategy:
111111
fail-fast: false
112112
matrix:
113-
version: ['1.0.0'] # Can expand to multiple versions
113+
version: ['v1.0.0'] # Version without prefix (prefix added in tags)
114114
platform: ['linux/amd64', 'linux/arm64']
115+
include:
116+
- version: 'v1.0.0'
117+
component_version: 'v1.0.0' # Component version for build-args
115118
steps:
116119
- name: 📥 Checkout repository
117120
uses: actions/checkout@v4
@@ -147,7 +150,7 @@ jobs:
147150
cache-from: type=gha,scope=${{ env.<IMAGE_NAME> }}-${{ steps.tags.outputs.platform_tag }}
148151
cache-to: type=gha,mode=max,scope=${{ env.<IMAGE_NAME> }}-${{ steps.tags.outputs.platform_tag }}
149152
build-args: |
150-
VERSION=${{ matrix.version }}
153+
COMPONENT_VERSION=${{ matrix.component_version }}
151154

152155
<image-name>-manifest:
153156
runs-on: ubuntu-latest
@@ -160,7 +163,10 @@ jobs:
160163
strategy:
161164
fail-fast: false
162165
matrix:
163-
version: ['1.0.0']
166+
version: ['v1.0.0']
167+
include:
168+
- version: 'v1.0.0'
169+
component_version: 'v1.0.0'
164170
steps:
165171
- name: 🔐 Log in to GitHub Container Registry
166172
uses: docker/login-action@v3
@@ -203,6 +209,61 @@ jobs:
203209
- **Secure push**: `push: ${{ github.repository_owner == 'jethome-iot' && github.ref_name == 'master' }}` prevents fork pushes
204210
- **Login condition**: Must include both org and branch checks: `if: github.repository_owner == 'jethome-iot' && github.ref_name == 'master'`
205211

212+
### Matrix Version Pattern
213+
214+
**Use consistent version matrix with `include` for component versions:**
215+
216+
All workflows follow this pattern:
217+
- `matrix.version` - Primary version identifier used in tags (without product prefix)
218+
- `matrix.include` - Maps version to component version(s) needed for build-args
219+
220+
**Examples:**
221+
222+
ESP-IDF:
223+
```yaml
224+
matrix:
225+
version: ['v5.4.1']
226+
platform: ['linux/amd64', 'linux/arm64']
227+
include:
228+
- version: 'v5.4.1'
229+
idf_base_tag: 'v5.4.1'
230+
# Tags: idf-v5.4.1
231+
# Build-args: IDF_BASE_TAG=${{ matrix.idf_base_tag }}
232+
```
233+
234+
PlatformIO:
235+
```yaml
236+
matrix:
237+
version: ['v6.1.18']
238+
platform: ['linux/amd64', 'linux/arm64']
239+
include:
240+
- version: 'v6.1.18'
241+
pio_version: 'v6.1.18'
242+
# Tags: pio-v6.1.18
243+
# Build-args: PIO_VERSION=${{ matrix.pio_version }}
244+
```
245+
246+
ESP-Matter:
247+
```yaml
248+
matrix:
249+
version: ['idf-v5.4.1-matter-v1.4.2']
250+
platform: ['linux/amd64', 'linux/arm64']
251+
include:
252+
- version: 'idf-v5.4.1-matter-v1.4.2'
253+
jethome_idf_base_tag: 'v5.4.1'
254+
esp_matter_version: 'v1.4.2'
255+
# Tags: idf-v5.4.1-matter-v1.4.2
256+
# Build-args: BASE_IMAGE_TAG=idf-${{ matrix.jethome_idf_base_tag }}
257+
# ESP_MATTER_VERSION=${{ matrix.esp_matter_version }}
258+
```
259+
260+
**Benefits:**
261+
- Single source of truth for version strings
262+
- Component versions preserved for build-args (Dockerfile requirements)
263+
- Easy to add multiple versions to matrix
264+
- Consistent pattern across all workflows
265+
- Product prefix added dynamically in tags (except ESP-Matter where it's part of composite version)
266+
206267
### Fork Prevention
207268

208269
**Allow forks to test builds via workflow_dispatch, but prevent automatic builds:**
@@ -219,7 +280,11 @@ jobs:
219280
strategy:
220281
fail-fast: false
221282
matrix:
222-
version: ['1.0.0']
283+
version: ['v1.0.0']
284+
platform: ['linux/amd64', 'linux/arm64']
285+
include:
286+
- version: 'v1.0.0'
287+
component_version: 'v1.0.0'
223288
```
224289

225290
**Strengthen push and login conditions:**

.github/workflows/esp-idf.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ jobs:
4040
strategy:
4141
fail-fast: false
4242
matrix:
43-
idf_base_tag: ['v5.4.1']
43+
version: ['v5.4.1']
4444
platform: ['linux/amd64', 'linux/arm64']
45+
include:
46+
- version: 'v5.4.1'
47+
idf_base_tag: 'v5.4.1'
4548
steps:
4649
- name: 📥 Checkout repository
4750
uses: actions/checkout@v4
@@ -72,7 +75,7 @@ jobs:
7275
platforms: ${{ matrix.platform }}
7376
push: ${{ github.repository_owner == 'jethome-iot' && github.ref_name == 'master' }}
7477
tags: |
75-
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.idf_base_tag }}-${{ steps.tags.outputs.platform_tag }}
78+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.version }}-${{ steps.tags.outputs.platform_tag }}
7679
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:sha-${{ steps.tags.outputs.sha_short }}-${{ steps.tags.outputs.platform_tag }}
7780
cache-from: type=gha,scope=${{ env.ESP_IDF_IMAGE_NAME }}-${{ steps.tags.outputs.platform_tag }}
7881
cache-to: type=gha,mode=max,scope=${{ env.ESP_IDF_IMAGE_NAME }}-${{ steps.tags.outputs.platform_tag }}
@@ -90,7 +93,10 @@ jobs:
9093
strategy:
9194
fail-fast: false
9295
matrix:
93-
idf_base_tag: ['v5.4.1']
96+
version: ['v5.4.1']
97+
include:
98+
- version: 'v5.4.1'
99+
idf_base_tag: 'v5.4.1'
94100
steps:
95101
- name: 🔐 Log in to GitHub Container Registry
96102
uses: docker/login-action@v3
@@ -109,9 +115,9 @@ jobs:
109115
run: |
110116
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:latest \
111117
-t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:sha-${{ steps.tags.outputs.sha_short }} \
112-
-t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.idf_base_tag }} \
113-
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.idf_base_tag }}-linux-amd64 \
114-
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.idf_base_tag }}-linux-arm64
118+
-t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.version }} \
119+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.version }}-linux-amd64 \
120+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.ESP_IDF_IMAGE_NAME }}:idf-${{ matrix.version }}-linux-arm64
115121
116122
esp-matter-build:
117123
runs-on: [self-hosted, ubuntu-latest]

.github/workflows/platformio.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
pio_version: ['v6.1.18']
39+
version: ['v6.1.18']
4040
platform: ['linux/amd64', 'linux/arm64']
41+
include:
42+
- version: 'v6.1.18'
43+
pio_version: 'v6.1.18'
4144
steps:
4245
- name: 📥 Checkout repository
4346
uses: actions/checkout@v4
@@ -68,7 +71,7 @@ jobs:
6871
platforms: ${{ matrix.platform }}
6972
push: ${{ github.repository_owner == 'jethome-iot' && github.ref_name == 'master' }}
7073
tags: |
71-
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }}-${{ steps.tags.outputs.platform_tag }}
74+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.version }}-${{ steps.tags.outputs.platform_tag }}
7275
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:sha-${{ steps.tags.outputs.sha_short }}-${{ steps.tags.outputs.platform_tag }}
7376
cache-from: type=gha,scope=${{ env.PLATFORMIO_IMAGE_NAME }}-${{ steps.tags.outputs.platform_tag }}
7477
cache-to: type=gha,mode=max,scope=${{ env.PLATFORMIO_IMAGE_NAME }}-${{ steps.tags.outputs.platform_tag }}
@@ -86,7 +89,10 @@ jobs:
8689
strategy:
8790
fail-fast: false
8891
matrix:
89-
pio_version: ['v6.1.18']
92+
version: ['v6.1.18']
93+
include:
94+
- version: 'v6.1.18'
95+
pio_version: 'v6.1.18'
9096
steps:
9197
- name: 🔐 Log in to GitHub Container Registry
9298
uses: docker/login-action@v3
@@ -105,6 +111,6 @@ jobs:
105111
run: |
106112
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:latest \
107113
-t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:sha-${{ steps.tags.outputs.sha_short }} \
108-
-t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }} \
109-
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }}-linux-amd64 \
110-
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }}-linux-arm64
114+
-t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.version }} \
115+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.version }}-linux-amd64 \
116+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.version }}-linux-arm64

0 commit comments

Comments
 (0)