PREQ-8698 Add skip build option to maven build - #348
mary-georgiou wants to merge 2 commits into
Conversation
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.
7bb26d7 to
b2725ea
Compare
- 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).
Code Review ✅ Approved 3 resolved / 3 findingsAdds a skip-build option to the Maven build action. Skip-build silently no-ops deploy and unanalyzed branches, the README inputs table now documents the new input, and test coverage includes the SKIP_BUILD branch. No issues remain. ✅ 3 resolved✅ Edge Case: skip-build silently no-ops deploy and unanalyzed branches
✅ Quality: New skip-build input missing from README inputs table
✅ Quality: No spec coverage for the SKIP_BUILD branch
Review coverageFunctional validation 3 of 5 objectives covered Implementation Status ◻️ 3 of 5 objectives covered◻️ CLP-738 - 3 of 5 objectives coveredThis PR adds the skip-build option to the maven build action to separate build artifact production from scanning consumption. Other objectives on this issue, possibly covered elsewhere:
✅ 3 covered here
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
tomverin
left a comment
There was a problem hiding this comment.
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.
| check_build_output_restored() { | ||
| if ! find . -mindepth 1 -maxdepth 4 -type d -path '*/target/classes' 2>/dev/null | grep -q .; then |
There was a problem hiding this comment.
Nit: this file already uses /usr/bin/find in export_built_artifacts so Windows runners do not pick up FIND.EXE — worth matching that here.
maxdepth 4 also misses a/b/c/target/classes (depth 5). The check is “any module”, so this only false-fails when every compiled module is deeper than 4, but the cutoff is arbitrary. Prefer /usr/bin/find … -print -quit without a depth cap.
find | grep -q under set -o pipefail is also a known GNU-find SIGPIPE hazard on Linux runners. Specs only create one target/classes, so they would not catch it.
| else | ||
| echo "Skipping Maven compile/test/deploy (skip-build enabled) - analyzing previously built output restored on disk." | ||
| fi |
There was a problem hiding this comment.
When skip-build is on and should_scan is false (short-lived branch, or sonar-platform: none), this job exits 0 having done no build and no scan. The normal action still runs mvn verify in that case.
The deploy: false guard covers the original deploy footgun; this remaining combination is now an explicit spec (skips the build output check when analysis is disabled). Prefer ::error + exit 1 here, or at least a warning, so a misconfigured scanner-only job is not silently green.
| Describe 'skip-build' | ||
| Mock check_build_output_restored | ||
| true | ||
| End |
There was a problem hiding this comment.
This mock means the skip-build examples never assert that build_maven actually calls check_build_output_restored. The function is unit-tested in isolation, but a regression that drops the call would still pass. Worth one example without the mock (or a spy) that expects the missing-output error when analysis is on and no target/classes exists.
| | `artifactory-deployer-role` | Suffix for the Artifactory deployer role in Vault | `qa-deployer` for private repos, `public-deployer` for public repos | | ||
| | `deploy` | Whether to deploy on master, maintenance, dogfood and long-lived branches | `true` | | ||
| | `deploy-pull-request` | Whether to also deploy for pull requests. If deploy is false, this has no effect. | `false` | | ||
| | `skip-build` | If `true`, skip compile/test/deploy and only run Sonar analysis against restored `target/` output. Requires `deploy: false`. | `false` | |
There was a problem hiding this comment.
A short producer/consumer example would help the first callers: upload the full target/ tree (classes and surefire/jacoco if the quality gate expects coverage), download it in the scanner job, then skip-build: true and deploy: false.
The restore check only looks for a target/classes directory — an empty dir passes, and coverage reports are not validated.
|
@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). |



Part of CLP-466
Summary by Gitar
skip-buildinput toaction.ymlandbuild.shto run Sonar analysis against pre-builttarget/output without compiling or deployingskip-buildcannot be enabled unlessdeployis set tofalsecheck_build_output_restoredvalidation to fail early if expectedtarget/classesoutput is missing on diskThis will update automatically on new commits.