Skip to content

PREQ-8698 Add skip build option to maven build - #348

Merged
guillaume-dequenne merged 4 commits into
masterfrom
mary/CLP-738-scan-maven
Oct 5, 2026
Merged

guillaume-dequenne merged 4 commits into
masterfrom
mary/CLP-738-scan-maven

Conversation

@mary-georgiou

@mary-georgiou mary-georgiou commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Part of CLP-466


Summary by Gitar

  • New Features:
    • Added skip-build input option to run Sonar analysis using existing target/ output without compiling, testing or deploying
  • Validations & Tests:
    • Added checks ensuring skip-build requires deploy: false and validates restored target/classes output

This will update automatically on new commits.

@mary-georgiou
mary-georgiou requested a review from a team as a code owner September 15, 2026 13:12
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Add skip build option to maven build PREQ-8698 Add skip build option to maven build Sep 15, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

PREQ-8698

Comment thread build-maven/build.sh
Comment thread build-maven/action.yml
Comment thread build-maven/build.sh Outdated
mary-georgiou added a commit that referenced this pull request Sep 15, 2026
check, tests, docs

- Enforce that skip-build:true requires deploy:false, failing loudly
  at script start instead of silently never deploying if a caller
  leaves deploy at its true default.
- Extract the build/deploy block into build_and_deploy() to isolate
  the skip-build branching from unrelated reindentation noise.
- Add check_build_output_restored(): fails loudly if no target/classes
  directory is present when skip-build is enabled and scanning, instead
  of letting the Sonar scanner silently produce a degraded analysis
  against missing/incomplete restored output.
- Document skip-build in README.md's build-maven inputs table.
- Add shellspec coverage for the new validation guard,
  check_build_output_restored(), and the skip-build path through
  build_maven(). Full suite verified locally: 40 examples, 0 failures.
@mary-georgiou
mary-georgiou force-pushed the mary/CLP-738-scan-maven branch from 7bb26d7 to b2725ea Compare September 15, 2026 13:30

@tomverin tomverin 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.

Looks good — the right shape for a scanner-only Maven consumer. The deploy: false guard, restore check, and existing Sonar orchestration are all in the right places.

Left a few non-blocking nits: harden check_build_output_restored (/usr/bin/find, drop maxdepth 4), fail or warn when skip-build would do nothing, assert the restore check is actually called from build_maven, and add a short producer/consumer example in the README.

Please rebase onto master before merge — the PR is currently behind.

Comment thread build-maven/build.sh Outdated
Comment thread build-maven/build.sh
Comment thread spec/build-maven_spec.sh
Comment thread README.md Outdated
@mary-georgiou
mary-georgiou marked this pull request as draft September 18, 2026 07:50
@mary-georgiou

mary-georgiou commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@tomverin thanks a lot! I drafted this cause we paused the sprint we are working on. I'll test it more and merge it later (later = during next week).
I'll apply your comments and reask for review. IT's a big change so I would feel more comfortable if you'd look again.

This was referenced Sep 23, 2026
Comment thread build-maven/build.sh
@guillaume-dequenne

guillaume-dequenne commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Testing follow-up against the current PR commit 02c4736: sonar-lits #177 passed its separate Build and Scan jobs (run); the Scan job downloaded the build artifact and ran Sonar without compiling, testing or deploying. The coverage comparison also passed on this commit: #179 imported JaCoCo and reported 60% new-code coverage (run), while #180 omitted -Pcoverage, imported no report and reported 0% (run). All checks on these three PRs passed. This validates the normal artifact handoff and coverage transfer; it does not directly test rerunning only the Scan job.

@guillaume-dequenne
guillaume-dequenne marked this pull request as ready for review September 28, 2026 14:27
@guillaume-dequenne

Copy link
Copy Markdown
Contributor

@tomverin I know you approved this PR already, but would you mind having another look following the latest changes from 02c4736?

mary-georgiou and others added 4 commits October 5, 2026 09:22
- Add || exit fallbacks to the new pushd/popd calls in
  build-maven_spec.sh (shellcheck SC2164).
- Shorten and re-pad the skip-build row in README.md's inputs table
  so its column widths match the rest of the table (markdownlint
  MD060 table-column-style).
@sonarqubecloud

sonarqubecloud Bot commented Oct 5, 2026

Copy link
Copy Markdown

@guillaume-dequenne
guillaume-dequenne enabled auto-merge (squash) October 5, 2026 07:48
@guillaume-dequenne
guillaume-dequenne merged commit 6246338 into master Oct 5, 2026
20 of 21 checks passed
@guillaume-dequenne
guillaume-dequenne deleted the mary/CLP-738-scan-maven branch October 5, 2026 07:49
@gitar-bot

gitar-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 4 closed / 4 findings

🟡 Medium risk · Adds a Maven scanner-only mode that skips compilation, tests, and deployment.

Adds skip-build input option to run Sonar analysis using existing target/ output without compiling, testing, or deploying. Resolved issues with silent no-ops on deploy and unanalyzed branches, missing README documentation, spec coverage gaps, and hard failures on merge_group and dogfood runs.

✅ 4 closed
✅ Edge Case: skip-build silently no-ops deploy and unanalyzed branches

📄 build-maven/build.sh:154 📄 build-maven/build.sh:192-198 📄 build-maven/build.sh:201 📄 build-maven/action.yml:19-25 📄 build-maven/action.yml:224-225 📄 build-maven/action.yml:247-248
With skip-build: true the script skips the whole build/deploy block unconditionally, so two combinations end in a silently green job with nothing done: (a) deploy left at its default true on master/maintenance/dogfood/long-lived branches — should_deploy is never consulted, deployed is never written to $GITHUB_OUTPUT, and the downstream Artifacts upload, Generate provenance attestation and deployment summary steps in action.yml all skip while the caller believes it deployed; (b) a branch where should_scan returns 1 (short-lived branch, or sonar-platform: none with shadow scans off) — the build is skipped and no scan runs, so build.sh exits 0 having performed no work at all. Guard the combination explicitly: warn (or fail) when SKIP_BUILD=true and should_deploy, and warn when SKIP_BUILD=true and should_scan is false, so a misconfigured scanner-only job is visible instead of a green no-op.

✅ Quality: New skip-build input missing from README inputs table

📄 build-maven/action.yml:19-25
The build-maven inputs table in README.md documents every other input of the action (deploy, deploy-pull-request, maven-args, provenance, ...) but the newly added skip-build is absent, so the only place it is described is action.yml. Add a row to the table (and ideally a short subsection explaining the scanner-only job pattern with deploy: false) to keep the documented input list complete.

✅ Quality: No spec coverage for the SKIP_BUILD branch

📄 build-maven/build.sh:154-168
spec/build-maven_spec.sh asserts the exact stdout line sequence for every existing branch case, but no example sets SKIP_BUILD=true, so the new branch in build_maven (no mvn deploy/install, no deployed output, scan still executed) is entirely untested and a regression that re-enables the build or drops the scan would pass CI. Add examples covering SKIP_BUILD=true on an analyzed branch (expects the skip message plus orchestrate_sonar_platforms, and no mvn deploy/mvn install) and on the default branch with DEPLOY=true (asserting no deployed=true output).

✅ Edge Case: skip-build scan job now hard-fails on merge_group and dogfood runs

📄 build-maven/build.sh:213-222 📄 README.md:379-393
This commit changed build_maven so that SKIP_BUILD=true returns 1 when should_scan is false. should_scan only passes on the default branch, branch-*, PRs and feature/long/*. The README's own workflow templates trigger on merge_group and workflow_dispatch. A merge-queue run has GITHUB_REF_NAME=gh-readonly-queue/..., and a dogfood push has dogfood-on-*, which is deployed but not scanned. For both, should_scan is false.

If someone copies the new README example (a scan job with skip-build: true and no branch/event condition) into one of those workflows, every merge-queue run and dogfood push fails with "Nothing to do". If the scan job is a required check, merges get blocked.

Fix: either document that the scan job needs a condition that matches should_scan, or make this case skip with a notice instead of failing on events that are never analyzed, such as merge queue.

Verification Repos 6 inspected

Functional validation No results

Rules No rules evaluated

Cross-repo 6 repositories inspected 0 open impacts

SonarSource/sonar-analyzer-commons Inspected
SonarSource/sonar-update-center Inspected
SonarSource/reddeer Inspected
SonarSource/nodejs-maven-plugin Inspected
SonarSource/orchestrator Inspected

1 more repository

Auto-approval Not enabled

Set up

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

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