-
Notifications
You must be signed in to change notification settings - Fork 17
/
go-get-update.sh
executable file
·58 lines (47 loc) · 1.4 KB
/
go-get-update.sh
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
#!/bin/bash
# TODO automate
GO_VERSION=1.21.13
FAIL_LOG="go-get-upgrade.fail.log"
if [ -f ${FAIL_LOG} ]; then
rm ${FAIL_LOG}
fi
while read dep
do
path=$(echo "${dep}" | jq -r .Path)
if [ -z "${path}" ]; then
echo " Error: Cannot process ${dep}"
echo
continue
fi
main=$(echo "${dep}" | jq -r .Main)
if [ "${main}" == "true" ]; then
# Do not update ourselves
echo
continue
fi
update=$(echo "${dep}" | jq -r '.Update | select( . != null )')
if [ -z "${update}" ]; then
continue
fi
deprecated=$(echo "${dep}" | jq -r '.Deprecated | select( . != null )')
if [ -n "${deprecated}" ]; then
echo "Error: ${path} is deprecated. Please upgrade manually."
echo "Deprecated ---> ${path}" >> ${FAIL_LOG}
echo
continue
fi
echo "Dependency to be updated: ${path}"
curr=$(echo "${dep}" | jq -r '.Version | select( . != null )')
new=$(echo "${dep}" | jq -r '.Update.Version | select( . != null )')
echo "Updating ${path}: ${curr} ---> ${new}"
# Stops the version of go installed from being automatically updated
export GOTOOLCHAIN=local
result=$(go get -t -u "${path}@${new}" 2>&1)
if [ "${?}" != "0" ]; then
echo "Error: ${path} failed to update. Please upgrade manually."
echo "Failed to update ---> ${path}" >> ${FAIL_LOG}
echo "${result}" >> ${FAIL_LOG}
echo >> ${FAIL_LOG}
fi
echo
done < <(cat gomod-list.json | jq -c '.[]')