|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2022 The CloudEvents Authors |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# update-deps.sh - Updates Go dependencies in all directories with go.mod files |
| 5 | +# |
| 6 | +# This script: |
| 7 | +# 1. Finds all directories containing go.mod files |
| 8 | +# 2. Goes into each directory and runs go get -u to update dependencies |
| 9 | +# 3. Runs go mod tidy to clean up the go.mod and go.sum files |
| 10 | + |
| 11 | +set -euo pipefail |
| 12 | + |
| 13 | +# Print script banner |
| 14 | +echo "=====================================" |
| 15 | +echo "Go Dependencies Update Script" |
| 16 | +echo "=====================================" |
| 17 | + |
| 18 | +# Find all directories with go.mod files |
| 19 | +# TODO (@embano1): currently ignores samples/http due to broken deps |
| 20 | +echo "Finding all directories with go.mod files..." |
| 21 | +DIRS=$(find . -name "go.mod" -not -path "./samples/http/*" -exec dirname {} \;) |
| 22 | +if [ -z "$DIRS" ]; then |
| 23 | + echo "No go.mod files found!" |
| 24 | + exit 0 |
| 25 | +fi |
| 26 | + |
| 27 | +# Count the number of directories |
| 28 | +DIR_COUNT=$(echo "$DIRS" | wc -l | tr -d ' ') |
| 29 | +echo "Found $DIR_COUNT directories with go.mod files" |
| 30 | +echo |
| 31 | + |
| 32 | +# Process each directory |
| 33 | +COUNTER=1 |
| 34 | +for DIR in $DIRS; do |
| 35 | + echo "[$COUNTER/$DIR_COUNT] Processing $DIR" |
| 36 | + |
| 37 | + # Change to the directory |
| 38 | + pushd "$DIR" >/dev/null |
| 39 | + |
| 40 | + # disable go toolchain switching |
| 41 | + export GOTOOLCHAIN=local |
| 42 | + |
| 43 | + echo " - Updating dependencies..." |
| 44 | + go get -u ./... |
| 45 | + |
| 46 | + echo " - Running go mod tidy..." |
| 47 | + go mod tidy |
| 48 | + |
| 49 | + # Return to the original directory |
| 50 | + popd >/dev/null |
| 51 | + |
| 52 | + echo " - Done" |
| 53 | + echo |
| 54 | + |
| 55 | + COUNTER=$((COUNTER + 1)) |
| 56 | +done |
| 57 | + |
| 58 | +echo "All dependencies updated successfully!" |
0 commit comments