-
Notifications
You must be signed in to change notification settings - Fork 3
/
zanata-functions
executable file
·197 lines (173 loc) · 5.4 KB
/
zanata-functions
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
### NAME
### zanata-functions
###
### SYNOPSIS
### zanata-functions [help|exit-status-help]
###
### DESCRIPTION
### This script is basically for source (include) from other script.
###
: ${WORK_ROOT:=/tmp/zanata}
: ${REPO_LOCAL_DIR:=/tmp/maven-central-release-repo}
: ${ZANATA_GIT_URL_PREFIX:=git@github.com:zanata}
### FUNCTIONS
function zanata_script_help_header(){
shopt -s extdebug
local script=$1
[ -z "$script" ] && script=$0
sed -n -e '/^###/ {s|^###||p}' $script | sed -e '/^\s*EXIT_STATUS/,$d'
}
function zanata_script_exit_status_help(){
shopt -s extdebug
local script=$(declare -F zanata_script_exit_status_help | sed -e 's|^[^/]*||')
shopt -u extdebug
sed -n -e '/^###/ {s|^###||p}' $script | sed -e '0,/^\s*EXIT_STATUS/d'
}
function zanata_script_help(){
zanata_script_help_header $1
echo -e " EXIT_STATUS"
zanata_script_exit_status_help
}
function echo_stderr(){
echo "$@" > /dev/stderr
}
function get_git_url(){
echo "${ZANATA_GIT_URL_PREFIX}/$1.git"
}
### checkout_releasing_branch <module>
### checkout RELEASING_BRANCH, the branch that we recommend downstream to use.
function checkout_releasing_branch(){
local branchType=$1
local module=$2
local branch=$(get_releasing_branch $module)
pushd ${WORK_ROOT}/${module} >/dev/null
git fetch
git checkout ${branch}
popd >/dev/null
}
### checkout_devel_branch <module>
### checkout DEVEL_BRANCH, the branch the branch for committing new features.
function checkout_devel_branch(){
local branchType=$1
local module=$2
local branch=$(get_devel_branch $module)
pushd ${WORK_ROOT}/${module} >/dev/null
git fetch
git checkout ${branch}
popd >/dev/null
}
### ensure_repo_generic <parentDir> <module> [git_repo_url]
### Ensure repo is at <parentDir>/<module>
function ensure_repo_generic(){
local parentDir=$1
local module=$2
local git_repo_url=$3
echo_stderr "### Ensure the repo $module is at ${parentDir}/${module}"
if [ -z "$git_repo_url" ];then
git_repo_url=$(get_git_url ${module})
fi
if [ ! -d ${parentDir} ];then
mkdir -p ${parentDir}
fi
pushd ${parentDir} >/dev/null
if [ ! -d ${module} ];then
git clone "${git_repo_url}"
if [ $? -ne 0 ];then
echo_stderr "[ERROR] Failed to clone ${git_repo_url}"
exit ${EXIT_FATAL_MISSING_DEPENDENCY}
fi
fi
popd >/dev/null
}
### ensure_repo <module> [git_repo_url]
### Ensure repo is at $WORK_ROOT/<module>
function ensure_repo(){
ensure_repo_generic "$WORK_ROOT" "$1" "$2"
}
### ensure_devel_repo <module> [git_repo_url]
### Ensure repo is at $DEVEL_ROOT/<module>
function ensure_devel_repo(){
ensure_repo_generic "$DEVEL_ROOT" "$1" "$2"
}
### does_branch_exist <module> <branch>
function does_branch_exist(){
local module=$1
local branch=$2
if [ ! -d "${WORK_ROOT}/${module}" ];then
echo_stderr "[ERROR] ${WORK_ROOT}/${module} does not exist"
exit ${EXIT_FATAL_MISSING_DEPENDENCY}
fi
pushd ${WORK_ROOT}/${module} >/dev/null
echo_stderr -n "### Does ${module} has branch ${branch}?..."
if git rev-parse --verify ${branch} &>/dev/null;then
echo_stderr "yes"
return 0
else
echo_stderr "no"
return ${EXIT_RETURN_FALSE}
fi
popd >/dev/null
}
### get_releasing_branch <module>
### Determine RELEASING_BRANCH, the branch that we recommend downstream to use,
### and release process should mainly happen here.
### It is:
### 'release' if that branch exists; otherwise
### 'integration/master' if that branch exists; otherwise
### 'master'.
function get_releasing_branch(){
local module=$1
if does_branch_exist ${MODULE} origin/release ;then
echo "release"
return 0
elif does_branch_exist ${MODULE} origin/integration/master ;then
echo "integration/master"
return 0
fi
echo "master"
return 0
}
### get_devel_branch <module>
### Determine DEVEL_BRANCH, the branch for committing new features.
### It is:
### 'integration/master' if that branch exists; otherwise
### 'master'.
function get_devel_branch(){
local module=$1
if does_branch_exist ${MODULE} origin/integration/master ;then
echo "integration/master"
return 0
fi
echo "master"
return 0
}
###
### EXIT_STATUS
### Success
### EXIT_OK
declare EXIT_OK=0
### Fatal should stop immediately.
### EXIT_FATAL_UNSPECIFIED: Unspecified fatal error,
### usually indicate a bug in our scripts.
declare EXIT_FATAL_UNSPECIFIED=1
### EXIT_FATAL_INVALID_OPTIONS: Wrong options were given
declare EXIT_FATAL_INVALID_OPTIONS=3
### EXIT_FATAL_MISSING_DEPENDENCY: Cannot find dependency
declare EXIT_FATAL_MISSING_DEPENDENCY=4
### EXIT_FATAL_FAIL: Script detected that a fatal error occurred.
declare EXIT_FATAL_FAIL=5
### Error that need to stop before next step.
### EXIT_ERROT_FAIL: Script detected that an error occurred.
declare EXIT_ERROR_FAIL=20
### Return value, should not print error messages.
### EXIT_RETURN_FALSE: Script should return false
declare EXIT_RETURN_FALSE=40
case $1 in
help )
zanata_script_help $0
;;
exit-status-help )
zanata_script_exit_status_help
;;
esac