~openstack-ubuntu-testing/+junk/jenkins-scripts

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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash -xe
# vi: ts=4 noexpandtab
#
#    tarball.sh - script for creating openstack packages from github
#
#    Copyright (C) 2011 Canonical Ltd.
#
#    Authors: Chuck Short <chuck.short@canonical.com>,
#             James Page <james.page@canonical.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


function prep_package()
{
	echo "Preparing tarball and packaging..."
	if [ ! -d tarball ]; then
		mkdir tarball
	fi
	case "$project" in
		nova|glance|keystone|horizon|quantum|swift|python-novaclient|python-keystoneclient|keystone-ksl|python-quantumclient)
			echo "$project - project is valid..."
			;;
		*)
			echo "$project - project is invalid..."
			exit 1
			;;
		esac
}

function generate_tarball()
{
	echo "Generating tarball"
	# Check to see if local git clone has already been prepared
	# this is used for the pre-commit testing for stable upstream
	# branches where the clone is assembled by Jenkins using gerrit
	if [ -n "$local_clone" ]; then
		# This is normally the root of the workspace
		# so we need to handle the creation of the tarball 
		# a bit differently.
		cd $local_clone
		{
			generate_changelog
			if [ "$project" = "horizon" ]; then
				git archive $git_branch --format=tar \
					--prefix=$project-$release_date/ \
					| gzip > tarball/${project}_${release_date}+git$date.orig.tar.gz
			else
				python setup.py sdist
				mv dist/$project-$release_date.tar.gz tarball/${project}_${release_date}+git$date.orig.tar.gz
			fi
		}
	# If running under jenkins then its likely the source
	# code trigger will have already checked out the git repo
	# so we can use that instead.
	elif [ -d $project ]; then
		cd $project
		{
		    echo "Checking out $git_branch"
			git checkout $git_branch
			git pull --ff
			generate_changelog
			if [ "$project" = "horizon" ]; then
				git archive $git_branch --format=tar \
                --prefix=$project-$release_date/ \
                | gzip > ../tarball/${project}_${release_date}+git$date.orig.tar.gz
		  	else
				python setup.py sdist
		    	mv dist/$project-$release_date.tar.gz ../tarball/${project}_${release_date}+git$date.orig.tar.gz
		  	fi
		}
		cd ..
	# Probably running standalone - revert to pulling project
	# into tarball directory
	else
		cd tarball 
		{
			git clone $git_repo/$project.git
			cd $project	
			{
				git checkout $git_branch
				generate_changelog
				if [ "$project" = "horizon" ]; then
					git archive $git_branch --format=tar \
					--prefix=$project-$release_date/ \
					| gzip > ../${project}_${release_date}+git$date.orig.tar.gz
				else
					python setup.py sdist
					mv dist/$project-$release_date.tar.gz ../${project}_${release_date}+git$date.orig.tar.gz
				fi
			}
			cd ..
		}
		cd ..
	fi
}

function generate_changelog()
{
	current_commit=`git log -n1 --no-merges --pretty=format:"%H"`
	# See if we have a previous commit
	if [ -f ${top_level_dir}/previous.commit ]; then
		previous_commit=`cat ${top_level_dir}/previous.commit`
		if [ "$previous_commit" == "$current_commit" ]; then 
			# Rebuild
			changelog_detail="No change rebuild."
		else
			# Use the previous commit if found
			changelog_detail=`git log $previous_commit..HEAD --no-merges --oneline --format="[%h] %s"`
		fi
	else
		# Default to last 5 commits
		changelog_detail=`git log -n5 --no-merges --oneline --format="[%h] %s"`
	fi
}

function store_current_commit()
{
	echo $current_commit > ${top_level_dir}/previous.commit
}

function generate_debian_package()
{

	if [ ! -d debian ]; then
		mkdir -p debian
	fi

	cd debian
	{
		if [ "$project" = "swift" ]; then
		   changelog_version="$release_date~git$date-0ubuntu1"
		else
		   changelog_version="$release_date+git$date-0ubuntu1"
		fi

		# Generate the debian package
		echo "Creating debian packages.."
		cp ../tarball/${project}_${release_date}+git$date.orig.tar.gz .

		bzr branch $bzr_repo $bzr_branch_name
		cd $bzr_branch_name
		bzr merge $bzr_testing_repo --force
		dch -b -D $ubuntu_release \
			--newversion $release_date+git$date-0ubuntu1 \
			"$changelog_detail"
		debcommit
		cd ..

		# Update the changelog
		tar zxvf ${project}_${release_date}+git$date.orig.tar.gz

		cd $project-${release_date}
		cp -rp ../$bzr_branch_name/debian .
		debuild -S -sa -k${gpg_key}

		cd ..
		# Build locally
		sbuild -d $ubuntu_release -n -A *.dsc

		# Install to local archive
		reprepro -Vb /var/lib/jenkins/www/apt include \
			$ubuntu_release *_amd64.changes

		cd $bzr_branch_name
		bzr push $bzr_testing_repo
		cd ..

		echo "Uploading to ppa.."
		dput $ppa_url *_source.changes
	}
	cd ../..
}

function cleanup_package()
{
	echo "Cleaning up package and tarball.."
	rm -rf tarball debian
}

project="$1"
release="$2"
local_clone="$3"

export DEBEMAIL="openstack-ubuntu-testing@lists.launchpad.net"
export DEBFULLNAME="Openstack Ubuntu Testing Bot"

date=`date +%Y%m%d%H%M`
changelog_detail=""
top_level_dir=`pwd`

prep_package

case "$release" in
	diablo)
		echo "Generating diablo packaging..."
		git_branch="stable/$release"
		ubuntu_release="oneiric"
		release_date="2011.3.2"
		ppa_url="ppa:openstack-ubuntu-testing/openstack-stable-testing"
	    bzr_branch_name="diablo"
		;;
	essex)
		echo "Generating essex pacaging..."
		git_branch="master"
		ubuntu_release="precise"
        bzr_branch_name="essex"
        if [ "$project" = "swift" ]; then
		  release_date="1.4.8"
	    else
		  release_date="2012.1"
        fi
	    if [ "$project" = "python-quantumclient" ]; then
            bzr_repo="lp:~ubuntu-server-dev/quantum/python-quantumclient"
            bzr_testing_repo="lp:~openstack-ubuntu-testing/quantum/python-quantumclient"
            bzr_branch_name="python-quantumclient"
        fi
		ppa_url="ppa:openstack-ubuntu-testing/openstack-trunk-testing"
		;;
	*)
		echo "Not a valid choice"
		exit 1;
esac

git_repo="https://github.com/openstack"
bzr_repo="lp:~openstack-ubuntu-testing/$project/${ubuntu_release}-${release}-proposed"
bzr_testing_repo="lp:~openstack-ubuntu-testing/$project/$release"
gpg_key="9935ACDC"

generate_tarball
generate_debian_package
cleanup_package
# Only do this if we get this far....
store_current_commit