Skip to content

Commit d7ed9e5

Browse files
justin808claude
andcommitted
Refactor examples workflow to use dynamic matrix configuration
Replace problematic include/exclude approach with setup-matrix job that generates different matrices based on branch and trigger context. The previous approach using conditional expressions in exclude with empty strings ('') didn't work reliably - GitHub Actions can't truly conditionally exclude matrix entries this way. New approach: - Add setup-matrix job that evaluates conditions and outputs JSON matrix - examples job uses fromJson() to consume the dynamic matrix - On PRs: runs 1 job (Ruby 3.4 + latest) for fast feedback - On master/workflow_dispatch/force_run/full-ci: runs 2 jobs for full coverage Benefits: - Actually works (no empty string workarounds) - Clear and maintainable (explicit bash conditions) - Debuggable (matrix output visible in logs) - Flexible (easy to add more conditions) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6fc7d32 commit d7ed9e5

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

.github/workflows/examples.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,34 @@ jobs:
5757
script/ci-changes-detector "$BASE_REF"
5858
shell: bash
5959

60-
examples:
60+
setup-matrix:
6161
needs: detect-changes
62+
runs-on: ubuntu-22.04
63+
outputs:
64+
matrix: ${{ steps.set-matrix.outputs.matrix }}
65+
steps:
66+
- id: set-matrix
67+
run: |
68+
# Determine if we should run full matrix (master, workflow_dispatch, force_run, or full-ci label)
69+
if [[ "${{ github.ref }}" == "refs/heads/master" ]] || \
70+
[[ "${{ github.event_name }}" == "workflow_dispatch" ]] || \
71+
[[ "${{ inputs.force_run }}" == "true" ]] || \
72+
[[ "${{ needs.detect-changes.outputs.has_full_ci_label }}" == "true" ]]; then
73+
# Full matrix: test both latest and minimum supported versions
74+
echo 'matrix={"include":[{"ruby-version":"3.4","dependency-level":"latest"},{"ruby-version":"3.2","dependency-level":"minimum"}]}' >> $GITHUB_OUTPUT
75+
else
76+
# PR matrix: test only latest versions for fast feedback
77+
echo 'matrix={"include":[{"ruby-version":"3.4","dependency-level":"latest"}]}' >> $GITHUB_OUTPUT
78+
fi
79+
80+
examples:
81+
needs: [detect-changes, setup-matrix]
6282
# Run on master, workflow_dispatch, OR when generators needed
6383
if: |
6484
github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.run_generators == 'true'
6585
strategy:
6686
fail-fast: false
67-
matrix:
68-
include:
69-
# Always run: Latest versions (fast feedback on PRs)
70-
- ruby-version: '3.4'
71-
dependency-level: 'latest'
72-
# Master and workflow_dispatch: Minimum supported versions (full coverage)
73-
- ruby-version: '3.2'
74-
dependency-level: 'minimum'
75-
exclude:
76-
# Skip minimum dependency matrix on regular PRs (run only on master/workflow_dispatch/force_run/full-ci label)
77-
- ruby-version: ${{ github.event_name == 'pull_request' && github.ref != 'refs/heads/master' && inputs.force_run != true && needs.detect-changes.outputs.has_full_ci_label != 'true' && '3.2' || '' }}
78-
dependency-level: ${{ github.event_name == 'pull_request' && github.ref != 'refs/heads/master' && inputs.force_run != true && needs.detect-changes.outputs.has_full_ci_label != 'true' && 'minimum' || '' }}
87+
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
7988
env:
8089
SKIP_YARN_COREPACK_CHECK: 0
8190
BUNDLE_FROZEN: ${{ matrix.dependency-level == 'minimum' && 'false' || 'true' }}

0 commit comments

Comments
 (0)