-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathztp-release.sh
executable file
·97 lines (86 loc) · 2.79 KB
/
ztp-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
#!/bin/bash
set -euf -o pipefail
TEMPDIR=
DEBUG=
FEATURE=ztpd
REDIRECT=/dev/null
GIT_REPO_DEFAULT="[email protected]:microsoft/wifi-ztp.git"
RELEASE_BRANCH_SOURCE_DEFAULT="main"
function usage() {
echo "$0 -v <version number> [-b <release source branch name>] [-r <git repo url>] [-f] [-d]"
echo
echo " -v <version number>"
echo " The numerical version, in semver format, of the release."
echo " Eg. 0.3.5"
echo " -b <release source branch name>"
echo " The name of the branch from which release source should be obtained."
echo " (default=${RELEASE_BRANCH_SOURCE_DEFAULT})"
echo " -r <git repo url>"
echo " The git repo url to use."
echo " (default=${GIT_REPO_DEFAULT})"
echo " -f"
echo " Determines whether or not release tags should be forcibly pushed."
echo " Note that this will overwrite any existing tags; use with caution."
echo " (default=disabled)"
echo " -d"
echo " Enable script debugging. This enables script output (stdout+stderr)."
echo
}
function finish() {
if [ ! -z ${TEMPDIR+x} ]; then
rm -rf ${TEMPDIR} >& ${REDIRECT}
fi
}
function main() {
local RELEASE_VERSION=
local RELEASE_BRANCH_SOURCE=${RELEASE_BRANCH_SOURCE_DEFAULT}
local FORCE=
local GIT_REPO=${GIT_REPO_DEFAULT}
while getopts ":v:b:r:fd" opt; do
case ${opt} in
v)
RELEASE_VERSION="${OPTARG}"
;;
b)
RELEASE_BRANCH_SOURCE="${OPTARG}"
;;
r)
GIT_REPO="${OPTARG}"
;;
f)
FORCE=" -f"
;;
d)
DEBUG=1
REDIRECT=/dev/tty
;;
*)
;;
esac
done
if [ -z ${RELEASE_VERSION+x} ]; then
echo "missing release version"
usage
exit 1
fi
local RELEASE_VERSION_TAG=v${RELEASE_VERSION}
local RELEASE_NAME=${FEATURE}-${RELEASE_VERSION}
local RELEASE_DIR_SOURCE=${FEATURE}-release-${RELEASE_VERSION}
local RELEASE_DIR=${RELEASE_NAME}
local RELEASE_ARCHIVE=${RELEASE_NAME}.tar.xz
TEMPDIR=$(mktemp -d)
pushd ${TEMPDIR} >& ${REDIRECT}
echo "checking out branch '${RELEASE_BRANCH_SOURCE}' from ${GIT_REPO}"
git clone ${GIT_REPO} --branch ${RELEASE_BRANCH_SOURCE} ${RELEASE_DIR_SOURCE} >& ${REDIRECT}
pushd ${RELEASE_DIR_SOURCE} >& ${REDIRECT}
echo "tagging as ${RELEASE_VERSION_TAG}"
git tag ${RELEASE_VERSION_TAG} ${FORCE} >& ${REDIRECT}
git push origin refs/tags/${RELEASE_VERSION_TAG} ${FORCE} >& ${REDIRECT}
pushd -0 && dirs -c
echo "preparing release archive"
git config tar.tar.xz.command "xz -c"
git archive --format=tar.xz --prefix=${RELEASE_NAME}/ ${RELEASE_VERSION_TAG} > ${RELEASE_ARCHIVE}
echo "created release archive ${RELEASE_ARCHIVE} -> $(sha256sum ${RELEASE_ARCHIVE} | awk '{print $1}')"
}
main "$@"
finish