forked from helium/miner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtag-release.sh
executable file
·130 lines (111 loc) · 2.97 KB
/
tag-release.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
set -e
usage() {
echo "Usage: $0 [-h] [-n <NAMED_TAG>] <SHA>"
}
dep_hash() {
local MINER=$1
local DEP=$2
git show "${MINER}:rebar.lock" | grep -A2 "${DEP}" | sed -e "s/.*\"\(.*\)\".*/\1/" | tr '\n' ' ' | awk '{print $3}'
}
val_tag() {
local VAL_VERSION
local MAJ
local MIN
local PATCH
VAL_VERSION=$(sed -n "/^version() ->$/,/\.$/p" src/miner.erl | grep -o -E '[0-9]{10}')
MAJ=$(echo $VAL_VERSION | awk '{print substr( $0, 1, 3 )}')
MIN=$(echo $VAL_VERSION | awk '{print substr( $0, 4, 3 )}')
PATCH=$(echo $VAL_VERSION | awk '{print substr( $0, 7, 4 )}')
echo "validator$((10#$MAJ)).$((10#$MIN)).$((10#$PATCH))"
}
declare -r repos="blockchain libp2p sibyl ecc508 relcast dkg hbbft helium_proto"
declare NAMED_TAG
TAG_NAME=$(date +%Y.%m.%d)
TAG_NUMBER=0
while getopts ":hn:" opt; do
case ${opt} in
h )
usage
exit 0
;;
n )
NAMED_TAG=$OPTARG
;;
\? )
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ $# -ne 1 ]; then
usage
exit 1
fi
MINER_HASH=$1
if [[ ! -z $NAMED_TAG ]]; then
VAL_VERSION_TO_TAG=$(val_tag)
if [[ ! $VAL_VERSION_TO_TAG == $NAMED_TAG ]]; then
echo "tag doesnt match committed version; should be ${VAL_VERSION_TO_TAG} per miner.erl!"
exit 1
fi
RELEASE_TAG=$NAMED_TAG
else
while git tag -l | grep -q "${TAG_NAME}.${TAG_NUMBER}"; do
TAG_NUMBER=`expr $TAG_NUMBER + 1`
done
RELEASE_TAG=${TAG_NAME}.${TAG_NUMBER}
fi
if [ ! -d .repos ]; then
mkdir .repos
fi
cd .repos
echo "updating repos"
for repo in $repos; do
case $repo in
"blockchain")
realname="blockchain-core"
;;
"helium_proto")
realname="proto"
;;
"libp2p")
realname="erlang-libp2p"
;;
"hbbft")
realname="erlang-hbbft"
;;
"dkg")
realname="erlang-dkg"
;;
*)
realname=$repo
;;
esac
if [ ! -d $repo ]; then
git clone -q [email protected]:helium/$realname.git $repo
else
$(cd $repo && git fetch -q origin)
fi
done
cd ..
echo -e "done\n"
echo -e "publishing ${RELEASE_TAG} tag\n"
git tag -a ${RELEASE_TAG} ${MINER_HASH} -m "${RELEASE_TAG} release"
git push origin "${RELEASE_TAG}"
for repo in $repos; do
REPO_HASH=$(dep_hash $MINER_HASH $repo)
cd .repos/$repo
TAG_REF=$(git show-ref ${RELEASE_TAG} | awk '{print $1}')
if [[ -z $TAG_REF ]]; then
echo -e "tagging ${repo} ${REPO_HASH}\n"
git tag -a ${RELEASE_TAG} ${REPO_HASH} -m "${RELEASE_TAG} miner release"
git push origin "${RELEASE_TAG}"
elif [[ $TAG_REF == $REPO_HASH ]]; then
echo -e "tag already present on ${repo} at desired hash ${REPO_HASH}\n"
else
echo -e "tag already present on ${repo} at another hash ${TAG_REF}; skipping"
fi
cd ../../
done