Skip to content

Commit f619bc8

Browse files
committed
ci(build): dynamically create the build matrix
Dynamically create the build matrix for all platforms that have the required config fragments. Signed-off-by: Randolph Sapp <rs@ti.com>
1 parent 1a48e30 commit f619bc8

File tree

2 files changed

+112
-43
lines changed

2 files changed

+112
-43
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,31 @@ defaults:
1414
shell: bash
1515

1616
jobs:
17+
collect:
18+
runs-on: ubuntu-latest
19+
container:
20+
image: ghcr.io/texasinstruments/processor-sdk-doc:latest
21+
options: --entrypoint /bin/bash
22+
outputs:
23+
build-matrix: "${{ steps.matrix.outputs.matrix }}"
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Create build matrix
29+
id: matrix
30+
run: |
31+
./bin/build_matrix.py
32+
1733
build:
1834
name: Build Linux Documents
1935
runs-on: ubuntu-latest
2036
container:
2137
image: ghcr.io/texasinstruments/processor-sdk-doc:latest
2238
options: --entrypoint /bin/bash
39+
needs: collect
2340
strategy:
24-
matrix:
25-
os: [linux]
26-
device:
27-
- AM335X
28-
- AM437X
29-
- AM57X
30-
- AM62AX
31-
- AM62LX
32-
- AM62PX
33-
- AM62X
34-
- AM64X
35-
- AM65X
36-
- AM67
37-
- AM68
38-
- AM69
39-
- CORESDK
40-
- DRA821A
41-
- J7200
42-
- J721E
43-
- J721S2
44-
- J722S
45-
- J742S2
46-
- J784S4
47-
- AM62DX
48-
include:
49-
- os: android
50-
device: AM62PX
51-
- os: android
52-
device: AM62X
53-
- os: buildroot
54-
device: AM62X
55-
- os: buildroot
56-
device: AM62LX
57-
- os: debian
58-
device: AM62X
59-
- os: debian
60-
device: AM62PX
61-
- os: debian
62-
device: AM64X
63-
- os: debian
64-
device: AM62LX
65-
- os: edgeai
66-
device: AM62AX
41+
matrix: "${{ fromJSON(needs.collect.outputs.build-matrix) }}"
6742

6843
steps:
6944
- name: Checkout

bin/build_matrix.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python3
2+
3+
"""Tool to create a build matrix for the current tree
4+
5+
SPDX-License-Identifier: MIT
6+
Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com
7+
"""
8+
9+
import json
10+
import logging
11+
import os
12+
from pathlib import Path
13+
14+
CONFIG_PATH = Path("configs/")
15+
GITHUB_PATH = Path(os.environ.get("GITHUB_OUTPUT", "test_output.txt"))
16+
REQUIRED_CONFIG_FRAGMENTS = {"config.txt", "tags.py", "toc.txt"}
17+
logger = logging.getLogger(__name__)
18+
19+
20+
def output_matrix(matrix):
21+
"""Write the output of the matrix to the GitHub CI managed file
22+
23+
:param matrix: List of dictionaries of valid os and platform combinations
24+
"""
25+
matrix_string = json.dumps(matrix)
26+
logging.info("Writing matrix data to: %s", GITHUB_PATH)
27+
with GITHUB_PATH.open("a", encoding="utf-8") as file:
28+
file.write(f"matrix='{matrix_string}'\n")
29+
30+
31+
def unpack_os_set(platform, os_set):
32+
"""Produce a list of dictionaries of valid platform to os mappings.
33+
34+
:param platform: String name of platform to use
35+
:param os_set: Set of string os names supported
36+
:return: List of dictionaries with os and platform mappings
37+
"""
38+
platform_matrix = []
39+
for name in os_set:
40+
platform_matrix.append({"device": platform, "os": name})
41+
return platform_matrix
42+
43+
44+
def valid_os_set(platform):
45+
"""Get a set of valid OS options for a give platform path. This is a little more complex than it
46+
needs to be so that we can produce some more verbose warnings.
47+
48+
:param platform: Pathlib path to platform config directory
49+
:return: Set of valid OS options
50+
"""
51+
config_fragments = set()
52+
for fragment in REQUIRED_CONFIG_FRAGMENTS:
53+
config_fragments |= {
54+
x.name for x in platform.glob(f"{platform.stem}_*_{fragment}")
55+
}
56+
57+
os_names = set()
58+
for name in config_fragments:
59+
os_names.add(name.split("_")[1])
60+
61+
valid_os = set()
62+
for name in os_names:
63+
invalid = False
64+
for fragment in REQUIRED_CONFIG_FRAGMENTS:
65+
required_file = f"{platform.stem}_{name}_{fragment}"
66+
if required_file not in config_fragments:
67+
invalid = True
68+
logging.warning("Missing the required file: %s", required_file)
69+
70+
if invalid:
71+
logging.warning("Skipping the invalid OS: %s", name)
72+
else:
73+
valid_os.add(name)
74+
75+
return valid_os
76+
77+
78+
def main():
79+
"""Main processing loop"""
80+
logging.basicConfig(level=logging.INFO)
81+
82+
matrix_list = []
83+
for platform in CONFIG_PATH.glob("*/"):
84+
if not platform.is_dir():
85+
continue
86+
logging.info("Parsing platform at: %s", platform)
87+
os_set = valid_os_set(platform)
88+
matrix_list.extend(unpack_os_set(platform.stem, os_set))
89+
90+
output_matrix(matrix_list)
91+
92+
93+
if __name__ == "__main__":
94+
main()

0 commit comments

Comments
 (0)