Skip to content

Commit e342d50

Browse files
committed
Merge branch 'master' into dwc2_cfg
2 parents 00b3cc5 + e73dfde commit e342d50

File tree

4 files changed

+126
-20
lines changed

4 files changed

+126
-20
lines changed

.circleci/config.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
executor: continuation/default
1010
docker:
1111
- image: cimg/base:current
12-
resource_class: small
12+
resource_class: large
1313
steps:
1414
- checkout
1515
- run:
@@ -52,8 +52,8 @@ jobs:
5252
else
5353
echo " - build:" >> .circleci/config2.yml
5454
fi
55-
5655
echo " matrix:" >> .circleci/config2.yml
56+
echo " alias: build-${build_system}-${toolchain}" >> .circleci/config2.yml
5757
echo " parameters:" >> .circleci/config2.yml
5858
echo " build-system: ['$build_system']" >> .circleci/config2.yml
5959
echo " toolchain: ['$toolchain']" >> .circleci/config2.yml
@@ -62,6 +62,9 @@ jobs:
6262
echo " build-args: ['$build_args']" >> .circleci/config2.yml
6363
}
6464
65+
# Collect all build aliases for code-metrics requires (cmake only, exclude esp-idf)
66+
BUILD_ALIASES=()
67+
6568
for build_system in "${BUILDSYSTEM_LIST[@]}"; do
6669
for toolchain in "${TOOLCHAIN_LIST[@]}"; do
6770
# make does not support these toolchains
@@ -72,9 +75,21 @@ jobs:
7275
FAMILY=$(echo $MATRIX_JSON | jq -r ".\"$toolchain\"")
7376
echo "FAMILY_${toolchain}=$FAMILY"
7477
gen_build_entry "$build_system" "$toolchain" "$FAMILY"
78+
79+
# Only add cmake builds: excluding esp-idf or build_args="--one-random" to metrics requirements
80+
if [ "$build_system" == "cmake" ] && [ "$toolchain" != "esp-idf" ] && [ "$toolchain" != "arm-iar" ]; then
81+
BUILD_ALIASES+=("build-${build_system}-${toolchain}")
82+
fi
7583
done
7684
done
7785
86+
# Add code-metrics job that requires all build jobs
87+
echo " - code-metrics:" >> .circleci/config2.yml
88+
echo " requires:" >> .circleci/config2.yml
89+
for alias in "${BUILD_ALIASES[@]}"; do
90+
echo " - $alias" >> .circleci/config2.yml
91+
done
92+
7893
- continuation/continue:
7994
configuration_path: .circleci/config2.yml
8095

.circleci/config2.yml

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,35 @@ commands:
127127
python tools/build.py -s << parameters.build-system >> $TOOLCHAIN_OPTION -j 4 << parameters.build-args >> << parameters.family >>
128128
fi
129129
130+
# Only collect and persist metrics for cmake builds (excluding esp-idf and --one-random)
131+
- when:
132+
condition:
133+
and:
134+
- equal: [ cmake, << parameters.build-system >> ]
135+
- not:
136+
equal: [ esp-idf, << parameters.toolchain >> ]
137+
- not:
138+
equal: [ arm-iar, << parameters.toolchain >> ]
139+
steps:
140+
- run:
141+
name: Collect Metrics
142+
command: |
143+
# Create unique directory per toolchain to avoid workspace conflicts
144+
METRICS_DIR="/tmp/metrics/<< parameters.toolchain >>"
145+
mkdir -p "${METRICS_DIR}"
146+
# Copy all metrics.json files
147+
for f in cmake-build/cmake-build-*/metrics.json; do
148+
if [ -f "$f" ]; then
149+
BOARD_DIR=$(dirname "$f" | xargs basename)
150+
cp "$f" "${METRICS_DIR}/${BOARD_DIR}.json"
151+
fi
152+
done
153+
154+
- persist_to_workspace:
155+
root: /tmp
156+
paths:
157+
- metrics/<< parameters.toolchain >>
158+
130159
jobs:
131160
# Build using docker
132161
build:
@@ -146,6 +175,7 @@ jobs:
146175

147176
docker:
148177
- image: cimg/base:current
178+
working_directory: ~/project/tinyusb
149179
resource_class: << parameters.resource_class >>
150180

151181
steps:
@@ -173,6 +203,7 @@ jobs:
173203

174204
machine:
175205
image: ubuntu-2404:current
206+
working_directory: ~/project/tinyusb
176207
resource_class: << parameters.resource_class >>
177208

178209
steps:
@@ -182,20 +213,79 @@ jobs:
182213
family: << parameters.family >>
183214
build-args: << parameters.build-args >>
184215

216+
# Aggregate code metrics from all builds
217+
code-metrics:
218+
docker:
219+
- image: cimg/python:3.12
220+
resource_class: large
221+
steps:
222+
- checkout
223+
- attach_workspace:
224+
at: /tmp
225+
226+
- run:
227+
name: Aggregate Code Metrics
228+
command: |
229+
python tools/get_deps.py
230+
pip install tools/linkermap/
231+
# Combine all metrics files from all toolchain subdirectories
232+
ls -R /tmp/metrics
233+
if ls /tmp/metrics/*/*.json 1> /dev/null 2>&1; then
234+
python tools/metrics.py combine -j -m -f tinyusb/src /tmp/metrics/*/*.json
235+
else
236+
echo "No metrics files found"
237+
exit 1
238+
fi
239+
240+
- store_artifacts:
241+
path: metrics.json
242+
destination: metrics.json
243+
244+
# Compare with base master metrics on PR branches
245+
- when:
246+
condition:
247+
not:
248+
equal: [ master, << pipeline.git.branch >> ]
249+
steps:
250+
- run:
251+
name: Download Base Branch Metrics
252+
command: |
253+
# Download metrics.json artifact from the latest successful build on master branch
254+
mkdir -p base-metrics
255+
# Use CircleCI API to get the latest artifact
256+
curl -s -L "https://dl.circleci.com/api/v2/project/gh/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/latest/artifacts?branch=master&filter=successful" \
257+
-H "Circle-Token: ${CIRCLE_TOKEN:-}" | \
258+
jq -r '.items[] | select(.path == "metrics.json") | .url' | \
259+
head -1 | xargs -I {} curl -s -L -o base-metrics/metrics.json {} || true
260+
261+
- run:
262+
name: Compare with Base Branch
263+
command: |
264+
if [ -f base-metrics/metrics.json ]; then
265+
python tools/metrics.py compare -f tinyusb/src base-metrics/metrics.json metrics.json
266+
cat metrics_compare.md
267+
else
268+
echo "No base metrics found, skipping comparison"
269+
cp metrics.md metrics_compare.md
270+
fi
271+
272+
- store_artifacts:
273+
path: metrics_compare.md
274+
destination: metrics_compare.md
275+
185276
workflows:
186277
build:
187278
jobs:
279+
# The jobs below are populated dynamically by config.yml set-matrix job
280+
# Example entries that will be generated:
188281
# - build:
189282
# matrix:
283+
# alias: build-cmake-arm-gcc
190284
# parameters:
191285
# toolchain: [ 'arm-gcc' ]
192286
# build-system: [ 'cmake' ]
193287
# family: [ 'nrf' ]
194288
# resource_class: ['large']
195-
# - build-vm:
196-
# matrix:
197-
# parameters:
198-
# toolchain: ['esp-idf']
199-
# build-system: ['cmake']
200-
# family: ['-bespressif_kaluga_1']
201-
# resource_class: ['large']
289+
# - code-metrics:
290+
# requires:
291+
# - build-cmake-arm-gcc

.github/workflows/build.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
path: metrics.json
112112

113113
- name: Download Base Branch Metrics
114-
if: github.event_name == 'pull_request'
114+
if: github.event_name != 'push'
115115
uses: dawidd6/action-download-artifact@v11
116116
with:
117117
workflow: build.yml
@@ -121,7 +121,7 @@ jobs:
121121
continue-on-error: true
122122

123123
- name: Compare with Base Branch
124-
if: github.event_name == 'pull_request'
124+
if: github.event_name != 'push'
125125
run: |
126126
if [ -f base-metrics/metrics.json ]; then
127127
python tools/metrics.py compare -f tinyusb/src base-metrics/metrics.json metrics.json
@@ -132,7 +132,7 @@ jobs:
132132
fi
133133
134134
- name: Post Code Metrics as PR Comment
135-
if: github.event_name == 'pull_request'
135+
if: github.event_name != 'push'
136136
uses: marocchino/sticky-pull-request-comment@v2
137137
with:
138138
header: code-metrics
@@ -203,9 +203,7 @@ jobs:
203203
# self-hosted on local VM, for attached hardware checkout HIL_JSON
204204
# ---------------------------------------
205205
hil-tinyusb:
206-
if: |
207-
github.repository_owner == 'hathach' &&
208-
(github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch')
206+
if: github.repository_owner == 'hathach' && github.event_name != 'push'
209207
needs: hil-build
210208
runs-on: [ self-hosted, X64, hathach, hardware-in-the-loop ]
211209
steps:
@@ -249,7 +247,7 @@ jobs:
249247
if: |
250248
github.repository_owner == 'hathach' &&
251249
github.event.pull_request.head.repo.fork == false &&
252-
(github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch')
250+
github.event_name != 'push'
253251
runs-on: [ self-hosted, Linux, X64, hifiphile ]
254252
env:
255253
IAR_LMS_BEARER_TOKEN: ${{ secrets.IAR_LMS_BEARER_TOKEN }}

tools/metrics.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,13 @@ def is_significant(file_row):
275275

276276
significant = []
277277
minor = []
278+
unchanged = []
278279
for f in sorted_files:
279-
# Skip files with no changes
280-
if f["total"]["diff"] == 0 and all(f["sections"][s]["diff"] == 0 for s in sections):
281-
continue
282-
(significant if is_significant(f) else minor).append(f)
280+
no_change = f["total"]["diff"] == 0 and all(f["sections"][s]["diff"] == 0 for s in sections)
281+
if no_change:
282+
unchanged.append(f)
283+
else:
284+
(significant if is_significant(f) else minor).append(f)
283285

284286
def render_table(title, rows):
285287
md_lines.append(f"## {title}")
@@ -323,6 +325,7 @@ def render_table(title, rows):
323325

324326
render_table("Changes >1% in any section", significant)
325327
render_table("Changes <1% in all sections", minor)
328+
render_table("No changes", unchanged)
326329

327330
with open(path, "w", encoding="utf-8") as f:
328331
f.write("\n".join(md_lines))

0 commit comments

Comments
 (0)