Skip to content

Add coverage-aware impacted-unit-test Makefile targets and run them in CGO/CJS workflows#37952

Merged
pelikhan merged 11 commits into
mainfrom
copilot/add-makefile-targets-for-tests
Jun 8, 2026
Merged

Add coverage-aware impacted-unit-test Makefile targets and run them in CGO/CJS workflows#37952
pelikhan merged 11 commits into
mainfrom
copilot/add-makefile-targets-for-tests

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR adds branch-aware Makefile targets to run only unit tests affected by current-branch changes, with separate paths for JavaScript and Go plus a combined entrypoint. Integration tests are explicitly excluded so PR checks can run a minimal relevant subset.

  • Target surface

    • Adds test-impacted-js, test-impacted-go, and test-impacted.
    • Adds BASE_REF ?= origin/main as the default comparison base.
  • Changed-file detection

    • Computes BASE_COMMIT via git merge-base $(BASE_REF) HEAD.
    • Diffs BASE_COMMIT..HEAD to detect changed files in each language path.
  • JavaScript impacted unit tests

    • Restricts change detection to actions/setup/js.
    • Runs npm run test:js -- --related ... against changed JS/TS files.
    • Excludes integration-only suites (including *.integration.test.cjs).
  • Go impacted unit tests

    • Detects changed .go files and correlates them with CI coverage data when available.
    • Downloads coverage artifacts from successful ci.yml runs on main by default (or explicit CI_RUN_ID) and maps matched coverage to impacted Go packages via test result JSON.
    • Falls back to changed-file package selection when coverage artifacts/tools are unavailable.
    • Uses go test -short to keep execution in unit-test scope.
    • Adds CI_COVERAGE_SOURCE_BRANCH ?= main to make the coverage-source branch explicit and configurable.
  • CI coverage artifact support

    • Uploads integration coverage artifacts in CI with ci-integration-coverage-* naming.
    • Includes both coverage-integration-*.out and matching test-result-integration-*.json to support local impacted-test correlation.
  • Workflow integration

    • Adds an impacted-go-tests job in cgo.yml to run make test-impacted-go.
    • Adds an impacted-js-tests job in cjs.yml to run make test-impacted-js.
    • Uses full git history in these jobs to ensure merge-base computation works reliably.
  • Discoverability

    • Updates make help with the new impacted-test targets.
BASE_REF ?= origin/main

.PHONY: test-impacted
test-impacted: test-impacted-js test-impacted-go

Copilot AI and others added 6 commits June 8, 2026 21:53
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Add Makefile targets for impacted JS and Go unit tests Add impacted-unit-test Makefile targets for Go and JavaScript Jun 8, 2026
Copilot AI requested a review from pelikhan June 8, 2026 22:06
@pelikhan

pelikhan commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@copilot use tools that leverage code coverage to correlate modified source files to impacted tests. you can download coverage data from the ci workflow runs.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan

pelikhan commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@copilot add a job in cgo.yml and cjs.yml to run these targets. Make sure the coverage artifacts comes from a workflow run in main branch.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot use tools that leverage code coverage to correlate modified source files to impacted tests. you can download coverage data from the ci workflow runs.

Implemented in 47bc2cf (with follow-up polish in b5091ed). test-impacted-go now uses CI coverage artifacts to correlate changed Go files with covered packages, downloading artifacts from the latest successful ci.yml run (or CI_RUN_ID), and falls back to changed-file package selection when coverage data/tools are unavailable. I also added CI artifact upload of coverage-integration-*.out + matching test-result JSON (ci-integration-coverage-*) so the correlation data is downloadable from workflow runs.

Copilot AI changed the title Add impacted-unit-test Makefile targets for Go and JavaScript Add coverage-aware impacted-unit-test Makefile targets for Go and JavaScript Jun 8, 2026
pelikhan and others added 3 commits June 8, 2026 15:43
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add a job in cgo.yml and cjs.yml to run these targets. Make sure the coverage artifacts comes from a workflow run in main branch.

Implemented in c101ed5. I added impacted-go-tests in .github/workflows/cgo.yml and impacted-js-tests in .github/workflows/cjs.yml to run make test-impacted-go and make test-impacted-js respectively, and updated test-impacted-go to source coverage artifacts from successful ci.yml runs on main (CI_COVERAGE_SOURCE_BRANCH, default main).

Copilot AI changed the title Add coverage-aware impacted-unit-test Makefile targets for Go and JavaScript Add coverage-aware impacted-unit-test Makefile targets and run them in CGO/CJS workflows Jun 8, 2026
@pelikhan pelikhan marked this pull request as ready for review June 8, 2026 22:49
Copilot AI review requested due to automatic review settings June 8, 2026 22:49
@pelikhan pelikhan merged commit 4d340ed into main Jun 8, 2026
53 of 71 checks passed
@pelikhan pelikhan deleted the copilot/add-makefile-targets-for-tests branch June 8, 2026 22:50
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. The PR only modifies .github/workflows/cgo.yml, .github/workflows/ci.yml, .github/workflows/cjs.yml, and Makefile — none of which are Go (_test.go) or JavaScript (.test.cjs, *.test.js) test files. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #37952 does not have the 'implementation' label and has 0 new lines of code in default business logic directories (≤100 threshold). The changed files are shell/python scripts under .github/skills and .github/workflows, which are outside the monitored business-logic paths.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer failed during the skills-based review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces “impacted unit test” Makefile targets that run a minimal subset of unit tests based on files changed on the current branch, and wires those targets into the CGO (Go) and CJS (JavaScript) workflows. It also adds CI support for uploading integration coverage artifacts so Go impacted-test selection can optionally correlate changes with CI coverage data.

Changes:

  • Adds test-impacted-js, test-impacted-go, and test-impacted Makefile targets with BASE_REF-based change detection.
  • Uploads integration coverage + matching go test -json results as CI artifacts for downstream correlation.
  • Adds new workflow jobs to run impacted JS tests in cjs.yml and impacted Go tests in cgo.yml.
Show a summary per file
File Description
Makefile Adds impacted-test targets for JS and Go, plus CI coverage correlation logic for Go.
.github/workflows/cjs.yml Adds an impacted-js-tests job invoking make test-impacted-js with full git history.
.github/workflows/ci.yml Uploads integration coverage artifacts (coverage-integration-*.out + matching test-result-integration-*.json).
.github/workflows/cgo.yml Adds an impacted-go-tests job invoking make test-impacted-go with full git history.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 5

Comment thread Makefile
exit 0; \
fi; \
echo "Running impacted JavaScript unit tests for changed files: $$CHANGED_JS_FILES"; \
cd actions/setup/js && printf '%s\n' "$$CHANGED_JS_FILES" | sed 's|^actions/setup/js/||' | tr '\n' '\0' | xargs -0 -r npm run test:js -- --no-file-parallelism --related $(JS_IMPACTED_TEST_EXCLUDES)
Comment thread Makefile
COVERAGE_SOURCE_BRANCH="$(CI_COVERAGE_SOURCE_BRANCH)"; \
RUN_ID="$(CI_RUN_ID)"; \
if [ -z "$$RUN_ID" ]; then \
RUN_ID=$$(gh run list --workflow "$(CI_WORKFLOW_FILE)" --branch "$$COVERAGE_SOURCE_BRANCH" --status success --limit 1 --json databaseId --jq '.[0].databaseId' 2>/dev/null || true); \
Comment thread Makefile
Comment on lines +301 to +307
if [ -n "$$COVERAGE_GO_PACKAGES" ]; then \
CHANGED_GO_PACKAGES="$$COVERAGE_GO_PACKAGES"; \
echo "Running impacted Go unit tests from CI coverage correlation: $$CHANGED_GO_PACKAGES"; \
else \
CHANGED_GO_PACKAGES=$$(printf '%s\n' "$$CHANGED_GO_FILES" | while IFS= read -r file; do dirname "$$file"; done | sort -u | sed 's|^|./|'); \
echo "Running impacted Go unit tests in changed-file packages: $$CHANGED_GO_PACKAGES"; \
fi; \
Comment thread Makefile
echo "Running impacted Go unit tests in changed-file packages: $$CHANGED_GO_PACKAGES"; \
fi; \
# Use -short to exclude integration tests and keep execution to unit-test scope. \
printf '%s\n' "$$CHANGED_GO_PACKAGES" | tr '\n' '\0' | xargs -0 -r go test -v -parallel=4 -timeout=10m -short
Comment thread .github/workflows/cgo.yml
Comment on lines +250 to +252
permissions:
contents: read
concurrency:
@github-actions github-actions Bot mentioned this pull request Jun 8, 2026
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.

3 participants