Skip to content

feat(ci): affected-only unit test matrix using Nx#34

Draft
so0k wants to merge 2 commits intomainfrom
ci/affected-packages-optimization
Draft

feat(ci): affected-only unit test matrix using Nx#34
so0k wants to merge 2 commits intomainfrom
ci/affected-packages-optimization

Conversation

@so0k
Copy link
Contributor

@so0k so0k commented Feb 17, 2026

Summary

  • Adds a determine-affected job to pr-unit.yml that uses nx show projects --affected to dynamically build the test matrix, skipping packages not impacted by a PR
  • Introduces tools/affected-packages.sh helper script with safe fallback to all 8 packages if Nx fails
  • Supports ci/run-all-unit label override to force full test coverage
  • Includes RFCs/CI-IMPROVEMENTS.md with design rationale and expected impact

Expected impact: Docs-only PRs run 0 unit test jobs instead of 16; leaf-package PRs run 2 instead of 16.

Details

  1. tools/affected-packages.sh (new) - Shell script that:
  • Runs npx nx show projects --affected to detect changed packages
  • Filters to only the 8 testable packages
  • Falls back to all packages if Nx fails
  • Outputs [] when nothing is affected
  1. .github/workflows/pr-unit.yml - Added determine-affected job:
  • Runs before all_unit_tests (~30s on ubuntu-latest)
  • Handles ci/run-all-unit label override → all 8 packages
  • Handles both pull_request and merge_group events for base SHA
  • all_unit_tests now uses dynamic fromJSON() matrix and skips entirely when has_packages == false
  • results job includes determine-affected in its needs list

Verified locally:

  • origin/main → [] (no package changes on this branch)
  • HEAD~3 → ["cdktn-cli","@cdktn/cli-core"] (correct transitive deps)
  • HEAD~10 → all 8 packages

Test plan

  • Run bash tools/affected-packages.sh origin/main locally on various branches
  • Open a docs-only PR and confirm 0 unit test jobs run
  • Open a PR touching @cdktn/commons and confirm only dependents are tested
  • Apply ci/run-all-unit label and confirm all 16 jobs run
  • Verify results job still correctly reports pass/fail

🤖 Generated with Claude Code

vincenthsh and others added 2 commits February 17, 2026 20:12
Use `nx show projects --affected` to dynamically build the PR unit test
matrix, skipping packages not impacted by the change. Adds a
`determine-affected` job and a `tools/affected-packages.sh` helper with
safe fallback to all packages. Override with `ci/run-all-unit` label.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
@so0k
Copy link
Contributor Author

so0k commented Feb 25, 2026

is this superseeded by #41 @irfn ?

i'll rebase this after #41 is merged and see if it provides benefits still

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants