Skip to content

BUILD-8735 refactor: modularize build functions and remove dead code#35

Merged
mikolaj-matuszny-ext-sonarsource merged 3 commits intomasterfrom
feat/mmatuszny/BUILD-8672-standarization-2
Aug 1, 2025
Merged

BUILD-8735 refactor: modularize build functions and remove dead code#35
mikolaj-matuszny-ext-sonarsource merged 3 commits intomasterfrom
feat/mmatuszny/BUILD-8672-standarization-2

Conversation

@mikolaj-matuszny-ext-sonarsource
Copy link
Copy Markdown
Contributor

@mikolaj-matuszny-ext-sonarsource mikolaj-matuszny-ext-sonarsource commented Aug 1, 2025

BUILD-8735

Summary

This PR refactors the npm and yarn build scripts to follow the same modular pattern as maven and gradle builds, making them more readable, testable, and customizable.

Key Changes

  • 🔧 Modularize npm/yarn builds: Extract complex branch logic into get_build_config() helper functions
  • 🧹 Remove dead code: Eliminate unreachable sonar scanner calls without arguments
  • 📝 Improve documentation: Add missing environment variable descriptions (GITHUB_SHA, GITHUB_OUTPUT, etc.)
  • ✅ Update tests: Modify test signatures to work with new modular function structure
  • 🔧 Fix formatting: Correct README indentation issue

Benefits

  • Customization: Users can easily replace get_build_config() with custom logic while keeping the same pipeline
  • Testing: Individual functions can be tested in isolation
  • Readability: Main build functions now show clear high-level flow
  • Maintainability: Complex logic is contained in focused helper functions

Before/After Comparison

Before (complex embedded logic):

build_npm() {
  # 80+ lines of nested conditionals embedded here
  if is_default_branch && \! is_pull_request; then
    # 20 lines of logic...
  elif is_maintenance_branch && \! is_pull_request; then
    # Another 20+ lines with nested version handling...
  # ... continues for 80+ lines
  run_standard_pipeline "$enable_sonar" "$enable_deploy" "${sonar_args[@]}"
}

After (modular design):

build_npm() {
  echo "=== NPM Build, Deploy, and Analyze ==="
  # Basic status output...
  
  set_project_version
  get_build_config      # ← Complex logic extracted
  run_standard_pipeline # ← Simple pipeline execution
  
  echo "=== Build completed successfully ==="
}

Test Results

All 136 tests pass with 0 failures across all build scripts

  • build-maven: 21 examples, 0 failures
  • build-gradle: 32 examples, 0 failures
  • build-npm: 29 examples, 0 failures
  • build-yarn: 35 examples, 0 failures
  • build-poetry: 19 examples, 0 failures

Backward Compatibility

🔒 100% backward compatible - no breaking changes:

  • All existing functionality preserved
  • API interfaces unchanged
  • Environment variable handling consistent
  • All tests continue to pass

- Extract complex branch logic into get_build_config() helper functions in npm/yarn
- Add handle_maintenance_branch_version() helper for npm maintenance branch logic
- Remove unreachable dead code in sonar scanner calls
- Improve documentation with missing environment variable descriptions
- Add proper validation for GITHUB_SHA and GITHUB_OUTPUT where used
- Update tests to work with new modular function signatures
- Fix README formatting issue with artifactory-deployer-role description

All build functions now follow the maven/gradle pattern of simple high-level calls
rather than embedding complex logic, improving readability and customization.
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title refactor: modularize build functions and remove dead code BUILD-8735 refactor: modularize build functions and remove dead code Aug 1, 2025
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Aug 1, 2025

🤖 Pull Request summary

Updates build system documentation and environment variable handling.

Documentation improvements: Restructured environment variable comments in all build scripts with clearer categorization (required inputs, GitHub auto-provided, optional customization)
Environment validation: Added mandatory checks for GITHUB_SHA and GITHUB_OUTPUT across all build scripts
Code refactoring: Split NPM and Yarn build logic by extracting get_build_config() and using environment variables instead of function parameters
Error handling improvements: Simplified JFrog CLI error handling in NPM build script, removing explicit error checks and relying on set -e
Test updates: Updated test specs to accommodate the refactored function signatures and new environment variable requirements
Minor fixes: Fixed indentation in README.md and added .claude/ to gitignore

Review focus: The refactoring of NPM/Yarn buil

💬 Please send your feedback

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@mikolaj-matuszny-ext-sonarsource mikolaj-matuszny-ext-sonarsource merged commit 7b10475 into master Aug 1, 2025
9 checks passed
@mikolaj-matuszny-ext-sonarsource mikolaj-matuszny-ext-sonarsource deleted the feat/mmatuszny/BUILD-8672-standarization-2 branch August 1, 2025 12:35
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