forked from Rax-io-CI-CD/Rax-io-build
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild-raxio
149 lines (131 loc) · 4.11 KB
/
build-raxio
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
#!/bin/bash -ex
# This script requires a "downstream" remote that points to
# [email protected]:Rax-io-CI-CD/OpenStackProjectDownstream.git and an "upstream" remote that
# points to [email protected]:Rax-io-CI-CD/OpenStackProject.git
# downstream-patches.txt should be in the format:
# <git-remote> <remote-branch>
# <git-remote> <remote-branch>
# ...
usage="Usage: ./build-raxio -h HEAD -m MILESTONE -r REPO [-d DOWNSTREAM_VERSION] [-n] [-p PATCHES_FILE] [-o OUT_FILE] [-t]
Required arguments.
-d Downstream version of upstream version (used to tag the release).
-h Upstream git SHA1 to base release off of. Uses latest HEAD by default.
-m Upstream release milestone (eg. \"h2\" for Havana, milestone 2).
-n Don't push to remote. Just build locally.
-o File to write the generated branch/tag name to.
-p File with a list of patches to include (optional).
-x File with commands to remove unsupported resources
-r Path to upstream raxio git repository.
-t Run unit tests (optional).
-8 Run pep8.
-e Previous version for generating a changelog.
-i SSH key for gerrit reviews
Examples:
./build-raxio -h feeae7f -m h2 -d 1 -r ~/github/raxio -p ~/github/raxio-build/downstream-patches.txt -o /tmp/raxio_version
./build-raxio -h feeae7f -m h2 -r ~/github/raxio -o /tmp/raxio_version
"
push=1
release_head="latest"
checkout=$(pwd)
# Parse command-line options
while getopts "i:d:h:m:no:p:r:tv8z:e:" opt; do
case "$opt" in
d) downstream_version=$OPTARG
;;
h) release_head=$OPTARG
;;
m) milestone=$OPTARG
;;
n) push=0
;;
o) out_file=$OPTARG
;;
p) downstream_patches=$OPTARG
;;
x) remove_resources=$OPTARG
;;
r) raxio_repo=$OPTARG
;;
t) run_tests=1
;;
8) run_pep=1
;;
e) previous_version=$OPTARG
;;
i) ssh_key=$OPTARG
;;
\?) echo "Invalid option: -$OPTARG" >&2
echo -e "$usage"
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Make sure all required options have been given
if ! [[ $milestone && $raxio_repo && $downstream_patches && $downstream_version ]]
then
echo -e "The -m, -r -p,and -d options are required.\n"
echo -e "$usage"
exit 1
fi
tox_tests() {
if [[ $run_tests ]]; then
if ! tox -e py27; then
echo "Tests failed"
exit 1
fi
fi
if [[ $run_pep ]]; then
if ! tox -e pep8; then
echo "Pep8 failed"
exit 2
fi
fi
}
# Construct upstream version string
cd $raxio_repo
git fetch upstream
if [[ $release_head == "latest" ]]; then
sha1=$(git rev-parse upstream/master | cut -c1-7)
else
sha1=$release_head
fi
upstream_version=$milestone-$(date '+%Y%m%d')-g$sha1
branch=$upstream_version-$downstream_version
# Delete branch if it already exists
if git show-ref builds/$branch; then
git checkout upstream/master
git branch -D builds/$branch
fi
# Create a branch at upstream SHA1
git branch builds/$branch $sha1
git checkout builds/$branch
# Run git commands in downstream-patches (merge/cherry-pick code)
if [[ -e $downstream_patches ]]; then
bash -ex $downstream_patches || exit 1
fi
# Generate changelog
python $checkout/scripts/changelog.py --output changelog ${previous_version} builds/${branch}
git add changelog
git commit -m "Add release changelog for ${branch}"
# Run unit tests
tox_tests
# Remove unsupported resources
if [[ -e $checkout/supported_resources.txt ]]; then
python $checkout/scripts/remove_unsupported.py $checkout/supported_resources.txt ./heat/engine/resources
git commit -a -m "Remove unsupported resources."
fi
# Build docs
#tox -e docs
#git add -f doc/build/html/
#git commit -am "Add generated html docs for supported resources"
# Create a branch for the release type
if [[ $push -eq 1 ]]; then
git push -f internal_repo builds/$branch:refs/heads/$branch
fi
if [[ $out_file ]]; then
echo $branch > $out_file
fi