forked from helium/miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag-release.sh
executable file
·111 lines (95 loc) · 2.34 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
#!/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}'
}
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
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 git@github.com: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