-
Notifications
You must be signed in to change notification settings - Fork 14
/
bump-onos-deps
executable file
·80 lines (67 loc) · 2.81 KB
/
bump-onos-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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
#
# SPDX-License-Identifier: Apache-2.0
# Poor-man's tool to bump the onosproject dependencies for a project:
# 1) "go get -u" on the dependencies with the new tag
# 2) create a branch
# 3) push to git
# The tool requires the user to have the authorization to:
# 1) push tag to the upstream repo
# Also, the following conditions must be met:
# 1) repo must have upstream (or origin) remote push enabled via ssh
# If no version is given use "latest" - this will get the latest tagged release of
# the go module, which is the whole point of running the procedure. To get the
# most recent non-tagged versions in git, use "master". To get older versions use
# a version number e.g. v0.6.0, but this will be applied across all onosproject modules
version=${VERSION:-"latest"}
NAMEBASE=github.com/onosproject
MPBASE="$NAMEBASE/config-models/modelplugin"
MPBASELEN=`expr length "$MPBASE"`
TODAY=$(date +"%Y%m%d")
# Validate upstream (or origin) push URL is via SSH...
git remote -v | grep upstream | grep -q push && upstream="upstream" || upstream="origin"
! git remote -v | grep $upstream | grep push | cut -f2 | cut -d\ -f1 | grep -q 'git@github.com:' && \
echo "Upstream remote not setup with SSH push URL" >&2 && exit 1
# Validate we are on master
! git status -b | grep "On branch" | cut -d\ -f3 | grep -q master && \
echo "Not on master branch" >&2 && exit 1
! git status -b | grep -q "nothing to commit, working tree clean" && \
echo "There are modified files" >&2 && exit 1
# Validate we are in an "onosproject"
! grep -q "module $NAMEBASE" go.mod && \
echo "Unexpected module in go.mod. Must contain '$NAMEBASE'" >&2 && exit 1
#Start the commit message
commitmsg="Bump version of $NAMEBASE dependencies to $version"
commitmsg+=("") # Blank line
nochanges=1
candidates=($(grep $NAMEBASE go.mod | grep -v module | grep -v $version | grep -v indirect | grep -v $MPBASE | cut -d\ -f1 | cut -f2))
# 1) Run "go get -u" - if the candidate is not in the exception list
for candidate in ${candidates[@]}; do
skipped=0
for exception in "$@"; do
exfq=$NAMEBASE/$exception
if [[ $exfq == $candidate ]]; then
commitmsg+=("Skipping: $candidate")
skipped=1
continue
fi
done
if [ $skipped -eq 0 ]; then
commitmsg+=("Updating: $candidate to $version")
nochanges=0
! GO111MODULE=on go get -u $candidate@$version && exit 1
fi
done
msg=$(printf "%s\n" "${commitmsg[@]}")
if [ "$nochanges" -eq 1 ]; then
echo "No changes necessary to go.mod"
exit 0
fi
! GO111MODULE=on go build -v ./... && exit 1
! GO111MODULE=on go mod tidy && exit 1
# 2) Create a branch and push it
git checkout -b onosdeps-$version-$TODAY && \
git add go.mod go.sum && \
git commit -m"$msg" && \
git push upstream