Skip to content

ci: scope pull-request analysis and avoid redundant compilation - #1484

Draft
joaodinissf wants to merge 4 commits into
ci/static-analysis-sariffrom
ci/spotbugs-skip
Draft

joaodinissf wants to merge 4 commits into
ci/static-analysis-sariffrom
ci/spotbugs-skip

Conversation

@joaodinissf

@joaodinissf joaodinissf commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1483 · supersedes #1485, #1486 and #1400

Why the change

Pull-request analysis now covers only the modules a change touches, and CPD no longer compiles, which shortens the lint and SpotBugs lanes while master keeps the full scan.

Special things to note

  • Coverage trade-off: unchanged downstream modules are not re-analysed on source-only pull requests, so a finding that a changed dependency causes there first shows up in master's full scan. This needs explicit reviewer acceptance.
  • A change to shared build, target, workflow or analysis configuration triggers a full scan.
  • After ci: reliable static-analysis gates and SARIF annotations #1483 merges, retarget this to master and re-run CI before merging.

Change outline

How the scope is chosen, in .github/scripts/compute-analysis-skip.sh:

files changed since the merge base (deletions and both sides of moves count)
  shared configuration changed   → full scan
  else changed reactor modules   → -pl <modules>,ddk-target -am
                                   unchanged dependencies compile but are not analysed
  no analysable module           → analysis skipped, gate passes
 lint
-  compile all modules, analyse all
+  compile changed modules and their dependencies, analyse changed modules
-  CPD after a compile pass
+  CPD without compiling
 spotbugs
-  analyse all modules
+  analyse changed modules (per-module skip)

The four commits keep the steps apart for review: SpotBugs skip selection, scoped compilation, CPD without compile, and lint scoping.

🤖 Generated with Claude Code

@joaodinissf joaodinissf changed the title ci: scope SpotBugs to the PR's changed modules (per-module skip) ci: scope SpotBugs to a PR's changed modules (per-module skip) Aug 3, 2026
joaodinissf and others added 4 commits September 26, 2026 13:28
SpotBugs' per-module analysis is the spotbugs job's long pole. A PR only needs
its changed modules scanned, so a pre-step injects <spotbugs.skip>true> into
every unchanged reactor module's pom — the plugin then skips the goal, and the
per-module JVM fork, for them. The full-reactor compile is kept (a changed
module keeps its complete aux-classpath); a build/config change falls back to a
full scan. pull_request only — master/snapshot run a full scan.

-Dspotbugs.onlyAnalyze was the cleaner-looking alternative but screens too late
(after the per-module fork), ~17% vs ~88% measured; the script header documents
the migration if an upstream SpotBugs early-exit ever lands.

- .github/scripts/compute-spotbugs-skip.sh: diff -> changed modules -> inject
  skip into the unchanged ones (idempotent; build/config change -> full scan).
- verify.yml spotbugs job: fetch-depth 0 + a scope step before compile;
  -Djgit.dirtyWorkingTree=ignore because the scope step dirties poms on purpose
  and this job releases nothing (releases/maven-verify keep =error); SARIF upload
  guarded so an empty scan set (no module scanned) doesn't fail the upload.

Validate and merge only expected SpotBugs reports. When the scope contains
no analysable modules, both merging and gating succeed without reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Export SPOTBUGS_SCOPE_ARGS with the changed modules and -am so the lane
compiles only those modules and their upstream dependencies. Unchanged
dependencies retain spotbugs.skip and provide the analysis classpath without
being analysed themselves. Include ddk-target explicitly because the target
definition is not a MANIFEST dependency that -am can discover.

Shared build/config changes retain a full reactor and scan. Export the full
expected-report list and an explicit scope state on that path. With no
analysable changed modules, skip Maven and accept no reports in the merge
and gate. Otherwise preserve shared validation for every expected report,
including failed analysis and invalid input, before counting findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CPD tokenizes sources under src/ and needs neither bytecode nor a
resolved target platform, so the second lint invocation drops its
compile goals. cpd.xml outputs are identical with and without the
compile pass, verified at the current token threshold and at the
PMD default of 100 (timestamp attributes aside).

Measured locally (warm tree, JDK 21): 6.8s vs 44.3s at the current
threshold; 4.5s vs 28.5s at threshold 100. In CI the invocation was
53s, ~40s of it redundant recompilation and JVM startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generalize compute-spotbugs-skip.sh to compute-analysis-skip.sh with a mode
argument. The lint mode injects pmd.skip, cpd.skip and checkstyle.skip into
unchanged modules and exports the expected reports and -pl/-am scope.
SpotBugs keeps its existing scoping behavior through the same script.

Compile the changed modules and their dependencies before PMD/Checkstyle
so type resolution has the complete classpath. Run CPD separately without
compilation. Shared build/config changes trigger a full scan in both lanes.

Skip the report goals, merging and gating when the scope contains no
analysable modules. Otherwise retain the common validation of every expected
SARIF report, URI bases and rule descriptors. Count CPD duplications from
the expected reports, including a single-module scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joaodinissf joaodinissf changed the title ci: scope SpotBugs to a PR's changed modules (per-module skip) ci: scope pull-request analysis and avoid redundant compilation Sep 26, 2026

This branch has not been deployed

No deployments
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.

1 participant