-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathcheckMajorUpdates.sh
More file actions
executable file
·56 lines (48 loc) · 1.58 KB
/
Copy pathcheckMajorUpdates.sh
File metadata and controls
executable file
·56 lines (48 loc) · 1.58 KB
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
#!/usr/bin/env bash
# Check direct go.mod dependencies for newer major versions
# (e.g., /v3 -> /v4, or unversioned -> /v2).
#
# Dependabot proposes these automatically, but this script is useful for
# quick manual audits.
set -euo pipefail
FLAGS="-tags=linux,libsqlite3,sqlite_fts5,gomailnotpl"
echo "Checking direct dependencies for newer major versions..."
echo
# Compute the candidate path for "current major + offset".
# offset=0 means the very next major after the current one.
next_path() {
local path="$1" offset="$2"
if [[ "$path" =~ ^(.+)/v([0-9]+)$ ]]; then
echo "${BASH_REMATCH[1]}/v$(( BASH_REMATCH[2] + 1 + offset ))"
elif [[ "$path" =~ ^(gopkg\.in/.+)\.v([0-9]+)$ ]]; then
echo "${BASH_REMATCH[1]}.v$(( BASH_REMATCH[2] + 1 + offset ))"
else
echo "${path}/v$(( 2 + offset ))"
fi
}
# Direct dependencies (path only)
deps=$(GOFLAGS=$FLAGS go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all)
found=0
for path in $deps; do
latest=""
for offset in 0 1 2; do
probe=$(next_path "$path" "$offset")
output=$(GOFLAGS=$FLAGS go list -m -versions "$probe" 2>/dev/null || true)
# Output is "<path> v1 v2 ..." if versions exist, just "<path>" otherwise.
if [[ -n "$output" ]] && [[ "$(echo "$output" | awk '{print NF}')" -gt 1 ]]; then
latest="$probe"
else
break
fi
done
if [[ -n "$latest" ]]; then
echo " $path -> $latest"
found=$(( found + 1 ))
fi
done
echo
if [[ "$found" -eq 0 ]]; then
echo "No newer major versions found."
else
echo "Found $found dependency/dependencies with newer major versions."
fi