Skip to content

Commit 0c795ff

Browse files
committed
feat(cpp-matrix): sort entries by historical failure rate
1 parent 4a7fa05 commit 0c795ff

File tree

20 files changed

+330
-25
lines changed

20 files changed

+330
-25
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
extra-values: |
5959
vcpkg-packages: {{#if (not fetch-content)}}fmt{{/if}}
6060
address-model: {{#if (eq arch 'x86')}}32{{else}}64{{/if}}
61+
github-token: ${{ secrets.GITHUB_TOKEN }}
6162

6263
build:
6364
needs: cpp-matrix

boost-clone/dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

boost-clone/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmake-workflow/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmake-workflow/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpp-matrix/action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,44 @@ inputs:
707707
required: false
708708
default: 'true'
709709

710+
# -----------------------------------------------------------------
711+
# Failure rate sorting
712+
# -----------------------------------------------------------------
713+
sort-by-failure-rate:
714+
description: |
715+
Sort matrix entries by historical failure rate.
716+
717+
The action fetches recent workflow run history and calculates the failure rate
718+
for each matrix entry based on job name matching. Entries with higher failure rates are
719+
sorted first (stable sort preserving existing order for equal rates).
720+
721+
This is useful when combined with `max-parallel` or limited runners, as it ensures jobs
722+
most likely to fail run first, providing faster feedback.
723+
724+
When enabled, the summary table includes a "Failure Rate" column.
725+
726+
Requires `github-token` to be set for API access. If failure rates cannot be calculated
727+
(no token, no history, API errors), the action continues gracefully without error.
728+
required: false
729+
default: 'true'
730+
731+
failure-rate-runs:
732+
description: |
733+
Number of recent workflow runs to analyze when calculating failure rates.
734+
735+
Only used when `sort-by-failure-rate` is enabled.
736+
required: false
737+
default: '20'
738+
739+
github-token:
740+
description: |
741+
GitHub token for API access when fetching workflow run history for failure rate calculation.
742+
743+
Required when `sort-by-failure-rate` is enabled. Pass `${{ secrets.GITHUB_TOKEN }}` or
744+
`${{ github.token }}`. Alternatively, set the `GITHUB_TOKEN` environment variable in your
745+
workflow step.
746+
required: false
747+
default: ''
710748

711749
outputs:
712750
matrix:

cpp-matrix/dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpp-matrix/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpp-matrix/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"license": "Boost Software License 1.0",
1616
"dependencies": {
1717
"@actions/core": "^1.11.1",
18+
"@actions/http-client": "^3.0.0",
1819
"handlebars": "^4.7.8",
1920
"semver": "^7.7.3",
2021
"setup-program": "*",

cpp-matrix/src/index.test.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ describe('generateMatrix', () => {
188188
output_file: undefined,
189189
log_matrix: false,
190190
generate_summary: false,
191-
trace_commands: false
191+
trace_commands: false,
192+
sort_by_failure_rate: false,
193+
failure_rate_runs: 20,
194+
github_token: ''
192195
};
193196
const matrix = await generateMatrix(inputs);
194197
expect(matrix.length === 0).toBe(false);
@@ -225,7 +228,10 @@ describe('generateMatrix', () => {
225228
output_file: undefined,
226229
log_matrix: false,
227230
generate_summary: false,
228-
trace_commands: false
231+
trace_commands: false,
232+
sort_by_failure_rate: false,
233+
failure_rate_runs: 20,
234+
github_token: ''
229235
};
230236
try {
231237
await generateMatrix(inputs);
@@ -268,7 +274,10 @@ test('msvc x86 entries prefer arch metadata over /m32 flags', async () => {
268274
output_file: undefined,
269275
log_matrix: false,
270276
generate_summary: false,
271-
trace_commands: false
277+
trace_commands: false,
278+
sort_by_failure_rate: false,
279+
failure_rate_runs: 20,
280+
github_token: ''
272281
};
273282
const matrix = await generateMatrix(inputs);
274283
const msvcX86Entry = matrix.find(entry => entry.compiler === 'msvc' && entry.x86 === true);
@@ -310,7 +319,10 @@ test('non-x86 entries default arch to x64 unless overridden', async () => {
310319
output_file: undefined,
311320
log_matrix: false,
312321
generate_summary: false,
313-
trace_commands: false
322+
trace_commands: false,
323+
sort_by_failure_rate: false,
324+
failure_rate_runs: 20,
325+
github_token: ''
314326
};
315327
const matrix = await generateMatrix(inputs);
316328
const gccEntry = matrix.find(entry => entry.compiler === 'gcc');
@@ -353,7 +365,10 @@ test('generates entries for compilers with no known versions', async () => {
353365
output_file: undefined,
354366
log_matrix: false,
355367
generate_summary: false,
356-
trace_commands: false
368+
trace_commands: false,
369+
sort_by_failure_rate: false,
370+
failure_rate_runs: 20,
371+
github_token: ''
357372
};
358373
const warnSpy = jest.spyOn(core, 'warning').mockImplementation(() => { });
359374
try {

0 commit comments

Comments
 (0)