update-deps.sh 4.1 KB

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