-
Notifications
You must be signed in to change notification settings - Fork 7
/
release-coredns
executable file
·161 lines (131 loc) · 4.13 KB
/
release-coredns
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash -e
# This release script downloads the latest Go and CoreDNS, sets things up and
# then calls into the Makefile to do the release. This script must be
# pre-configured on the (Linux) machine doing the release.
#
# Synopsis
# release-coredns [-t] [-v GOVERSION] BRANCH VERSION
#
# -t: test run, only compile, don't upload anything
# -v VERSION: use this Go version to compile CoreDNS, i.e. -v 1.13.8
PROG=$(basename $0)
GITHUB=coredns/coredns
BRANCH=master
TESTING=
GOVERSION=
while getopts "tv:" o; do
case "${o}" in
t)
TESTING=ON
;;
v)
GOVERSION="${OPTARG}"
;;
*)
echo "$PROG: Wrong flag: ${o}"
exit 1
;;
esac
done
shift $((OPTIND-1))
if [[ -z "$1" ]]; then
echo "$PROG: Need branch as first argument"
exit 1
fi
BRANCH="$1"
if [[ -z "$2" ]]; then
echo "$PROG: Need version as second argument"
exit 1
fi
WANTVERSION="$2"
if [[ "$TESTING" == "ON" ]]; then
echo "$PROG: TEST ---***--- TEST ---***--- TEST"
fi
# latestGO downloads the latest version of Go (or used a cached download from /tmp).
# The optional second parameter may specify a specific Go release to use for this release.
function latestGo {
local TEMP="$1"
local VERSION="$2"
if [[ -z "$VERSION" ]]; then
local LATEST=$(curl -sL 'https://go.dev/dl/?mode=json' | jq -r '.[0].version')
local GOLANG=https://go.dev/dl/${LATEST}.linux-amd64.tar.gz
else
local LATEST="go${VERSION}" # add 'go' prefix
local GOLANG=https://go.dev/dl/${LATEST}.linux-amd64.tar.gz
fi
TAR=$(basename $GOLANG)
( cd $TEMP
if [[ ! -e /tmp/$TAR ]]; then
echo "$PROG: Downloading: $GOLANG"
wget -q $GOLANG
cp $TAR /tmp
else
echo "$PROG: Using cached version of: $GOLANG"
cp /tmp/$TAR .
fi
)
}
# setupGo extracts Go and exports GOROOT and GOPATH to get a compile confined to the tmp dir.
function setupGo {
local TEMP="$1"
echo "$PROG: Setting up Go in $TEMP"
( cd $TEMP; tar xf $TAR )
export GOROOT=$TEMP/go
export GOPATH=$TEMP/g
export GOBIN=${GOPATH}/bin
export PATH=$GOBIN:$PATH
export PATH=$GOROOT/bin:$PATH
}
# fromGithub downloads owner/repo from Github into g/src/github.com/owner/repo.
function fromGithub {
local TEMP="$1"
local GITHUB="$2" # OWNER/REPO
local BRANCH="$3"
echo "$PROG: Getting $GITHUB (branch $BRANCH)"
( cd $TEMP
mkdir -p g/src/github.com/$(dirname $GITHUB) && \
cd g/src/github.com/$(dirname $GITHUB) && git clone -b $BRANCH --single-branch --depth 1 https://github.com/$GITHUB
)
}
function versionCheck() {
local WANTVERSION=$1
local GITHUB=$2
(cd $GITHUB;
COREVERSION=$(make -f Makefile.release version)
if [[ "$COREVERSION" != "$WANTVERSION" ]]; then
echo "$PROG: Want version $WANTVERSION, got version $COREVERSION, aborting build"
exit 1
fi
echo "$PROG: Version OK: $WANTVERSION = $COREVERSION"
)
}
if [[ "$TESTING" == "ON" ]]; then
TEMP=$(mktemp -d)
latestGo $TEMP $GOVERSION
setupGo $TEMP
fromGithub $TEMP $GITHUB $BRANCH
versionCheck $WANTVERSION $TEMP/g/src/github.com/$GITHUB
echo "$PROG: Test building $GITHUB (branch $BRANCH) in $TEMP/g/src/github.com/$GITHUB"
echo "$PROG: PATH is $PATH"
( cd $TEMP/g/src/github.com/$GITHUB
make -f Makefile.release release
)
echo "$PROG: This was a test run. Please remove $TEMP at your leisure."
echo "$PROG: TEST ---***--- TEST ---***--- TEST"
exit 0
fi
if [[ -z "$GITHUB_ACCESS_TOKEN" ]]; then
echo "$PROG: No GITHUB_ACCESS_TOKEN set"
exit 1
fi
TEMP=$(mktemp -d); function d1 { chmod -R +wx $TEMP; rm -rf $TEMP; }; trap d1 EXIT
latestGo $TEMP $GOVERSION
setupGo $TEMP
fromGithub $TEMP $GITHUB $BRANCH
versionCheck $WANTVERSION $TEMP/g/src/github.com/$GITHUB
echo "$PROG: Building $GITHUB (branch $BRANCH) in $TEMP/g/src/github.com/$GITHUB"
echo "$PROG: PATH is $PATH"
( cd $TEMP/g/src/github.com/$GITHUB
make -f Makefile.release release
make -f Makefile.release github-push
)