update-deps.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # update-deps.sh: Update Go module dependencies across all modules in the repository
  4. #
  5. # This script updates dependencies for all Go modules in the external-secrets multi-module repository:
  6. # - Root module
  7. # - APIs module
  8. # - Runtime module
  9. # - E2E module
  10. # - Build tools module
  11. # - All provider modules (providers/v1/*)
  12. # - All generator modules (generators/v1/*)
  13. #
  14. # This script is used by the automated update-deps GitHub workflow, which:
  15. # 1. Runs this script to update all dependencies
  16. # 2. Runs `make check-diff` to regenerate any auto-generated files
  17. # 3. Creates a PR if there are any changes
  18. #
  19. # Note: Some dependency updates may fail due to constraints - this is expected and
  20. # the script will continue processing all modules.
  21. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  22. REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
  23. # Colors for output
  24. BLUE='\033[34m'
  25. GREEN='\033[32m'
  26. YELLOW='\033[33m'
  27. RED='\033[31m'
  28. NC='\033[0m' # No Color
  29. info() {
  30. echo -e "${BLUE}[INFO]${NC} $*"
  31. }
  32. success() {
  33. echo -e "${GREEN}[OK]${NC} $*"
  34. }
  35. warn() {
  36. echo -e "${YELLOW}[WARN]${NC} $*"
  37. }
  38. error() {
  39. echo -e "${RED}[ERROR]${NC} $*"
  40. }
  41. # Update a single module's dependencies
  42. update_module() {
  43. local module_path="$1"
  44. local module_name="$2"
  45. local package_pattern="${3:-.}"
  46. info "Updating dependencies for $module_name..."
  47. cd "$REPO_ROOT/$module_path"
  48. # Run go get -u to update dependencies
  49. # Some updates may fail due to dependency constraints - this is expected
  50. if go get -u "$package_pattern" 2>&1; then
  51. success "Updated dependencies for $module_name"
  52. else
  53. warn "Failed to update some dependencies for $module_name (continuing...)"
  54. fi
  55. # Run go mod tidy to clean up
  56. if go mod tidy 2>&1; then
  57. success "Tidied $module_name"
  58. else
  59. warn "Failed to tidy $module_name (continuing...)"
  60. return 1
  61. fi
  62. cd "$REPO_ROOT"
  63. }
  64. main() {
  65. info "Starting dependency update for all modules..."
  66. echo ""
  67. # Track failures
  68. failed_modules=()
  69. # 1. Update root module
  70. if ! update_module "." "root"; then
  71. failed_modules+=("root")
  72. fi
  73. echo ""
  74. # 2. Update APIs module
  75. if ! update_module "apis" "apis"; then
  76. failed_modules+=("apis")
  77. fi
  78. echo ""
  79. # 3. Update runtime module
  80. if ! update_module "runtime" "runtime"; then
  81. failed_modules+=("runtime")
  82. fi
  83. echo ""
  84. # 4. Update e2e module
  85. if ! update_module "e2e" "e2e"; then
  86. failed_modules+=("e2e")
  87. fi
  88. echo ""
  89. # 5. Update build tools module
  90. if ! update_module "hack/tools" "build tools" tool; then
  91. failed_modules+=("build tools")
  92. fi
  93. echo ""
  94. if ! update_module "hack/tools/golangci-lint" "golangci-lint" tool; then
  95. failed_modules+=("golangci-lint")
  96. fi
  97. echo ""
  98. # 6. Update all provider modules
  99. info "Updating provider modules..."
  100. for provider_dir in "$REPO_ROOT"/providers/v1/*/; do
  101. if [ -f "$provider_dir/go.mod" ]; then
  102. provider_name=$(basename "$provider_dir")
  103. relative_path="providers/v1/$provider_name"
  104. if ! update_module "$relative_path" "provider/$provider_name"; then
  105. failed_modules+=("provider/$provider_name")
  106. fi
  107. fi
  108. done
  109. echo ""
  110. # 7. Update all generator modules
  111. info "Updating generator modules..."
  112. for generator_dir in "$REPO_ROOT"/generators/v1/*/; do
  113. if [ -f "$generator_dir/go.mod" ]; then
  114. generator_name=$(basename "$generator_dir")
  115. relative_path="generators/v1/$generator_name"
  116. if ! update_module "$relative_path" "generator/$generator_name"; then
  117. failed_modules+=("generator/$generator_name")
  118. fi
  119. fi
  120. done
  121. echo ""
  122. # Summary
  123. echo "=================================================="
  124. if [ ${#failed_modules[@]} -eq 0 ]; then
  125. success "All modules updated successfully!"
  126. else
  127. warn "Some modules encountered issues during update:"
  128. for module in "${failed_modules[@]}"; do
  129. echo " - $module"
  130. done
  131. info "This may be expected due to dependency constraints."
  132. fi
  133. # Always return success - the workflow will check for changes with check-diff
  134. # Failures here are often expected and shouldn't block the update process
  135. return 0
  136. }
  137. # Run main function
  138. main