-
Notifications
You must be signed in to change notification settings - Fork 4
/
zanata-package-fedora
executable file
·203 lines (180 loc) · 5.73 KB
/
zanata-package-fedora
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
198
199
200
201
202
#!/bin/bash -eu
set -o pipefail
LANG=C
### NAME
### zanata-package-fedora - Release package in fedora
###
### SYNOPSIS
### zanata-package-fedora [Options] <module> [version-release]
###
### ARGUMENTS
### module: module to release in Fedora. It is also the Fedora package name.
###
### version-release: (Required if -a is not specified)
### Version and SPEC release field. For example, 3.7.2-2
### This is mandatory when bumping SPEC release number.
###
### OPTIONS
### -h: Show this help.
###
### -a: Automatic detected.
### Version will be detected from latest tag from git.
### And release is 1.
###
### ENVIRONMENT
### FEDPKG_DIR
### Which directory should the fedpkg clone take place
### Default: ${HOME}/FedPkg}
: ${FEDPKG_DIR:=${HOME}/FedPkg}
###
### FEDORA_USERNAME
### Required if your Fedora username is different from $USER
### Default: ${USER}
: ${FEDORA_USER:=${USER}}
###
### MAINTAINER_EMAIL
### Required if your Fedora username is different from $USER
### Default: ${FEDORA_USER}@fedorapeople.org
: ${MAINTAINER_EMAIL:=${FEDORA_USER}@fedorapeople.org}
###
### DESCRIPTION
### This program builds and submits the latest Zanata modules
### that are not yet in supported Fedora branches.
###
### It invokes bodhi for Fedora submission check and koji for Fedora build.
### It also requests buildroot override for 30 days for non-leaf modules
### like zanata-parent, zanata-api and zanata-common.
###
### If a new version tag have been created in module source Git,
### you can use option '-a', so you don't have to enter version-release.
###
### However, if did not change source but modify spec or apply patch
### in RPM SPEC, then you cannot use '-a'
### and you need to specify version-release.
###
ScriptDir=$(dirname $(realpath $0))
FunctionScriptFile=${ScriptDir}/zanata-functions
source "$FunctionScriptFile"
trap exit_print_error EXIT
## Variables
SpecRelease=1
##=== function definitions Start ===
# is pkgBuild been built in koji
# Valid pkgBuild example: cmake-fedora-1.4.0-1.fc21
function is_branch_build_in_koji(){
local branch=$1
local bodhiBranch=$(branch_to_bodhi_branch $branch)
local pkgBuild="$Nvr.${bodhiBranch}"
print_status -n " koji: is ${pkgBuild} in? ... "
if koji buildinfo $pkgBuild | grep -qcs -i "State: COMPLETE" ;then
print_status "yes, skip"
return 0
fi
print_status "no, will submit it"
return 1
}
# is pkgBuild in bodhi
# Valid pkgBuild example: cmake-fedora-1.4.0-1.fc21
function is_branch_build_in_bodhi(){
local branch=$1
local bodhiBranch=$(branch_to_bodhi_branch $branch)
local pkgBuild="$Nvr.${bodhiBranch}"
print_status -n " bodhi: is ${pkgBuild} in? ... "
if bodhi "${pkgBuild}" | grep -qcs -i "Submit" > /dev/null;then
print_status "yes, skip"
fi
print_status "no, will submit it"
return 1
}
##=== function definitions End ===
##=== parsing Start ===
print_status -t parsing -s "Start"
ScmVersion=
SpecRelease=
AutoDetect=0
while getopts "ha" opt;do
case $opt in
h )
zanata_script_help $0
exit ${EXIT_OK}
;;
a )
AutoDetect=1
;;
* )
exit_if_failed ${EXIT_FATAL_INVALID_OPTIONS} ${EXIT_FATAL_INVALID_OPTIONS} "$opt"
;;
esac
done
shift $((OPTIND-1))
## Get Module
branch_prepare RELEASING "$@"
shift $ShiftOffset
print_status " Module=$Module"
## Get Version
if [ ${AutoDetect} -eq 0 ];then
if [ -z "${1-}" ];then
zanata_script_help $0
EXIT_MSG="Requires version-release. Please either specify version-release or use option -a"
exit ${EXIT_FATAL_INVALID_OPTIONS}
fi
VersionRelease=$1
EXIT_MSG="VersionRelease $VersionRelease is invalid"
SpecRelease=$(sed -n 's/.*-\([0-9]*\)$/\1/p' <<<$VersionRelease)
EXIT_MSG=
test -n "$SpecRelease"
exit_if_failed "$?" ${EXIT_FATAL_INVALID_OPTION} "Failed to get SPEC release from ${VersionRelease}"
ScmVersion=$(sed -e 's/-'$SpecRelease'$//' <<<$VersionRelease)
test -n "$ScmVersion"
exit_if_failed "$?" ${EXIT_FATAL_INVALID_OPTION} "Failed to get version from ${VersionRelease}"
else
## Auto detect version
Version=$(detect_module_version ${Module})
print_status " ${Module} version: $Version"
test -n "$Version"
exit_if_failed "$?" ${EXIT_FATAL_FAIL} "Failed to get version from ${Module} git repo"
SpecRelease=1
fi
print_status " Version=$Version"
print_status " SpecRelease=$SpecRelease"
##=== prepare Start ===
print_status -t prepare -s "Start"
print_status " Prepare fedpkg ${Module} git repo"
mkdir -p ${FEDPKG_DIR}
cd ${FEDPKG_DIR}
if [ -d ${Module} ];then
cd ${Module}
git reset --hard HEAD
fedpkg switch-branch master
git pull
git fetch --tags
else
fedpkg clone ${Module}
cd ${Module}
fi
##=== SRPM Start ===
print_status -t "SRPM" -s "Start"
print_status " updating SPEC"
spec_update $Module.spec $Version $SpecRelease $MAINTAINER_EMAIL
print_status " removing old zip and rpm"
rm -fv *.zip
rm -fv *.rpm
print_status " downloading files"
spectool -g $Module.spec
fedpkg srpm
git reset --hard HEAD
Srpm=$Module-$Version-$SpecRelease.fc$RawhideVersion.src.rpm
echo "$Srpm"
test -r $Srpm
exit_if_failed $? $EXIT_FATAL_FAIL " Failed to create SRPM $Srpm"
##=== Build Start ===
print_status -t "Build" -s "Start"
cmake-fedora-fedpkg $Srpm fedora
##=== Buildroot Override ===
if [ $Module != "zanata-server" ];then
print_status -t "Buildroot Override" -s "Start"
for bodhiBranch in $(cmake-fedora-koji bodhi-branch fedora | xargs );do
bodhi --buildroot-override $Module-$Version-$SpecRelease.$bodhiBranch
done
bodhi --buildroot-override
fi