-
Notifications
You must be signed in to change notification settings - Fork 158
/
update-deps
executable file
·62 lines (48 loc) · 1.8 KB
/
update-deps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_DIR="$( cd "$SCRIPT_DIR" && pwd )"
CUR_DIR="$PWD"
OTEL_VERSION="${OTEL_VERSION:-main}"
CORE_VERSION="${CORE_VERSION:-$OTEL_VERSION}"
CONTRIB_VERSION="${CONTRIB_VERSION:-$OTEL_VERSION}"
CORE_PKGS="go.opentelemetry.io/collector"
CONTRIB_PKGS="github.com/open-telemetry/opentelemetry-collector-contrib"
GONOPROXY=""
if [ "$CORE_VERSION" = "main" ]; then
CORE_VERSION=$(git ls-remote -q https://github.com/open-telemetry/opentelemetry-collector main | awk '{print $1}')
GONOPROXY=${GONOPROXY},${CORE_PKGS}/*
fi
if [ "$CONTRIB_VERSION" = "main" ]; then
CONTRIB_VERSION=$(git ls-remote -q https://github.com/open-telemetry/opentelemetry-collector-contrib main | awk '{print $1}')
GONOPROXY=${GONOPROXY},${CONTRIB_PKGS}/*
fi
# If updating to the most recent commit in the core/contrib main branch,
# bypass the proxy and download directly from github to save time.
if [ -n "$GONOPROXY" ]; then
export GONOPROXY=${GONOPROXY#,}
export GONOSUMDB=${GONOPROXY#,}
fi
trap "cd $CUR_DIR" EXIT
update_gomod() {
local gomod="$1"
local pkgs="$2"
local version="$3"
pushd "$( dirname "$gomod" )" >/dev/null
if [ -n "$(go list -f '{{if not .Indirect}}{{.Path}}{{end}}' -m ${pkgs}/... 2>/dev/null)" ]; then
echo "Updating ${pkgs}/... in $gomod to $version"
go get ${pkgs}/...@${version}
if [ -f Makefile ]; then
make tidy
else
rm -f go.sum
go mod tidy
fi
fi
popd >/dev/null
}
for gomod in $( find "$REPO_DIR" -name "go.mod" | grep -v "/examples/" | sort ); do
update_gomod "$gomod" "$CORE_PKGS" "$CORE_VERSION"
update_gomod "$gomod" "$CONTRIB_PKGS" "$CONTRIB_VERSION"
done
make -C "$REPO_DIR" for-all CMD='make tidy'