-
Notifications
You must be signed in to change notification settings - Fork 5
/
pkg-snapshot-version-git
executable file
·175 lines (163 loc) · 5.5 KB
/
pkg-snapshot-version-git
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
#!/bin/bash
#
# Update an Ubuntu package to a new upstream snapshot.
# Automatically generates the version based on the uppermost upstream
# tag in descending order.
#
# Rename the version with git naming convention based on specified
# version to sort *after* the git tag. The date stamp and upstream
# tip git hash will be added to the version.
#
# The script will create an upstream and pkg directory in the CWD.
# Clones git package from upstream into upstream directory.
# Clones git package from launchpad into pkg directory.
# Generates orig tarball from upstream branch and imports to package
# branch.
# Renames the tarball and imports it into package.
# Leaves you in d/changelog to edit.
#
# Note: The following needs to be in ~/.gbp.conf:
# [import-orig]
# postimport = dch -v%(version)s New upstream snapshot for OpenStack Wallaby.
#
# Examples: pkg-snapshot-version-git cinder master
#
set -ex
if [ $# -ne 2 ]
then
echo "Usage: $0 package-name branch-name"
echo " $0 cinder master"
exit
fi
package=$1
branch=$2
function calculate_snapshot_version {
# Calculate the version for snapshot
#
# The following is a quick reference of expected versions based on actual
# upstream nova git tags. In this scenario, the previous stable release
# version is 17.x.y and the development release version is unknown until
# the 18.0.0.0b1 tag is available:
#
# upstream tag expected snapshot version
# ------------ --------------------------
# 17.0.0 17.0.0+git<date>.<hash>-0ubuntu1
# 17.0.1 17.0.1+git<date>.<hash>-0ubuntu1
# 17.1.0 17.1.0+git<date>.<hash>-0ubuntu1
# 18.0.0.0b1 18.0.0~b1+git<date>.<hash>-0ubuntu1
# 18.0.0.0b2 18.0.0~b2+git<date>.<hash>-0ubuntu1
# 18.0.0.0rc1 18.0.0~rc1-0ubuntu1 # not a snapshot
# 18.0.0~rc1+git<date>.<hash>-0ubuntu1
# 18.0.0 18.0.0-0ubuntu1 # not a snapshot
# 18.0.1 18.0.1-0ubuntu1 # not a snapshot
version=$1
version=${version//./ }
major=$(echo $version | awk '{print $1}')
minor=$(echo $version | awk '{print $2}')
patch=$(echo $version | awk '{print $3}')
extra=$(echo $version | awk '{print $4}')
if [ -n "$extra" ]; then
# we're dealing with a beta or rc release
extra=${extra//0}
version_package="${major}.${minor}.${patch}~${extra}+"
else
version_package="${major}.${minor}.${patch}+"
fi
echo $version_package
}
rm -rf ~/tarballs
[ -d upstream ] || mkdir upstream
[ -d pkg ] || mkdir pkg
[ -d pkg/${package} ] && rm -rf pkg/${package}
# clone upstream branch and generate snapshot tarball
cd upstream
if [ "$package" = "gnocchi" ]
then
git clone https://github.com/gnocchixyz/gnocchi.git || true
cd gnocchi
elif [ "$package" = "networking-arista" ]
then
git clone https://opendev.org/x/networking-arista || true
cd networking-arista
elif [ "$package" = "networking-l2gw" ]
then
git clone https://opendev.org/x/networking-l2gw || true
cd networking-l2gw
elif [ "$package" = "openstack-trove" ]
then
git clone https://opendev.org/openstack/trove || true
cd trove
elif [ "$package" = "zvmcloudconnector" ]
then
git clone https://github.com/mfcloud/python-zvm-sdk || true
cd python-zvm-sdk
elif [ "$package" = "neutron-taas" ]
then
git clone https://opendev.org/x/tap-as-a-service.git || true
cd tap-as-a-service
else
git clone https://opendev.org/openstack/$package || true
cd $package
fi
git checkout $branch
git pull
# get the uppermost tag in descending order and calculate snapshot version
max_digits=3
if [ "$package" = "networking-arista" ]
then
max_digits=4
fi
git_flags="--merged $branch"
if [ "$branch" = "master" ]
then
git_flags="--list"
fi
tags=$(git tag $git_flags --sort -v:refname | grep -E "^[[:digit:]]{1,$max_digits}\.")
tag=$(git tag $git_flags --sort -v:refname | grep -E "^[[:digit:]]{1,$max_digits}\." | head -n 1)
period_count=$(echo -n "$tag" | tr -cd '.' | wc -c)
if [ "$period_count" -eq "3" ]; then
# Deal with sorting of betas and rc's before final release. If the final
# release tag exists, use it instead.
# 15.0.0.0rc2
# 15.0.0.0rc1
# 15.0.0.0b1
# 15.0.0
tag_base=$(echo $tag | sed 's|\(.*\)\..*|\1|')
set +e
tmp_tag=$(git tag $git_flags --sort -v:refname | grep -E "^[[:digit:]]{1,$max_digits}\." | grep -x $tag_base)
set -e
if [ $tmp_tag != "" ]; then
tag=$tmp_tag
fi
fi
pkgos-generate-snapshot
githash=$(git rev-parse --short HEAD)
cd ../..
version=$(calculate_snapshot_version ${tag})
# clone package branch and import snapshot tarball
cd pkg
git clone lp:~ubuntu-openstack-dev/ubuntu/+source/$package || true
cd $package
git pull
git checkout pristine-tar
git checkout upstream
git checkout $branch
date=$(date +%Y%m%d%H)
if [ "$package" = "openstack-trove" ]
then
package="trove"
fi
# rename and import snapshot tarball
if [ "$package" = "networking-arista" ]
then
mv ~/tarballs/networking_arista*.orig.tar.gz ~/tarballs/${package}_${version}git${date}.${githash}.orig.tar.gz
elif [ "$package" = "neutron-taas" ]
then
mv ~/tarballs/tap-as-a-service*.orig.tar.gz ~/tarballs/${package}_${version}git${date}.${githash}.orig.tar.gz
else
mv ~/tarballs/*${package}_*.orig.tar.gz ~/tarballs/${package}_${version}git${date}.${githash}.orig.tar.gz
fi
gbp import-orig --no-interactive --merge-mode=replace ~/tarballs/${package}_*.orig.tar.gz
cp ~/tarballs/${package}* ..
dch -i
sed -i "1s/1ubuntu1/0ubuntu1/" debian/changelog