summaryrefslogtreecommitdiff
path: root/jenkinstool
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-08-17 21:30:36 +0100
committerLars Wirzenius <liw@liw.fi>2012-08-17 21:30:36 +0100
commit5a43e5a1e4e7f4ff1bc348616d48af54b8878894 (patch)
tree654eddcf37d3743926ed7b5ee91064bbbbf1c739 /jenkinstool
parentbc5cf51bc15c3aa7a1a445a9819a0fd845b0e9b5 (diff)
downloadjenkinstool-5a43e5a1e4e7f4ff1bc348616d48af54b8878894.tar.gz
Refactor the shell script prelude to be nicer
Diffstat (limited to 'jenkinstool')
-rwxr-xr-xjenkinstool107
1 files changed, 60 insertions, 47 deletions
diff --git a/jenkinstool b/jenkinstool
index 69f82af..bea1936 100755
--- a/jenkinstool
+++ b/jenkinstool
@@ -28,28 +28,54 @@ import simplejenkinsapi
prelude = '''
-if [ -e setup.py ]
-then
- upstream_version="$(python setup.py --version)"
-else
- echo "Can't figure out project version. Giving up." 1>&2
- exit 1
-fi
-if [ -e .bzr ]
-then
- commit_timestamp="$(bzr log -l1 --timezone=utc |
- sed -n '/^timestamp: /s///p')"
-else
- echo "Can't figure out version control system. Giving up." 1>&2
- exit 1
-fi
-commit_date=$(date --date="$commit_timestamp" +%%Y%%m%%dT%%H%%M%%S)
+upstream_version()
+{
+ if [ -e setup.py ]
+ then
+ python setup.py --version
+ else
+ echo "UNKNOWN-PROJECT-VERSION"
+ fi
+}
+
+commit_date()
+{
+ if [ -e .bzr ]
+ then
+ commit_timestamp="$(bzr log -l1 --timezone=utc |
+ sed -n '/^timestamp: /s///p')"
+ else
+ echo "UNKNOWN-COMMIT-TIME"
+ return
+ fi
+
+ date --date="$commit_timestamp" +%%Y%%m%%dT%%H%%M%%S
+}
project="%(project.name)s"
-version="${upstream_version}.vcs${commit_date}"
+version="$(upstream_version).vcs$(commit_date)"
artifacts="%(global.artifacts)s/${project}"
+project_artifacts="$artifacts/$project"
tarball="${project}-${version}.tar.gz"
+
+debianversion="${version}-1"
+debianurl="%(global.artifacts-url)s/debian"
+
+if [ -d debian ]
+then
+ sourcepkg="$(dpkg-parsechangelog | awk '/^Source:/ { print $2 }')"
+ origtgz="${sourcepkg}_${debianversion}.orig.tar.gz"
+ changes="${sourcepkg}_${debianversion}_source.changes"
+ dsc="${sourcepkg}_$debianversion.dsc"
+ case "$sourcepkg" in
+ lib*) subdir=$(echo "$sourcepkg" | cut -c1-4) ;;
+ *) subdir=$(echo "$sourcepkg" | cut -c1) ;;
+ esac
+ pooldir="pool/main/$subdir"
+ poolurl="%(global.artifacts-url)s/debian/$pooldir"
+fi
+
'''
@@ -170,21 +196,18 @@ reprepro -b "$base" export
jc.set_description(
'Create or update pbuilder base.tgz on %(host.ssh-target)s')
- jc.add_ssh_command('''
+ jc.add_ssh_command(prelude + '''
basetgz=/var/cache/pbuilder/base.tgz
-debianurl="%(global.artifacts-url)s/debian"
if [ -e "$basetgz" ]
then
- sudo pbuilder --update --override-config \
- --distribution "%(host.debian-dist)s" \
- --mirror "%(global.debian-mirror)s" \
- --othermirror "deb $debianurl %(host.debian-dist)s main"
+ opts="--update --override-config"
else
- sudo pbuilder --create \
- --distribution "%(host.debian-dist)s" \
- --mirror "%(global.debian-mirror)s" \
- --othermirror "deb $debianurl %(host.debian-dist)s main"
+ opts="--create"
fi
+sudo pbuilder $opts \
+ --distribution "%(host.debian-dist)s" \
+ --mirror "%(global.debian-mirror)s" \
+ --othermirror "deb $debianurl %(host.debian-dist)s main"
''')
return jc
@@ -225,7 +248,7 @@ fi
jc.set_description('Upgrade build environment on %(host.ssh-target)s '
'for %(project.name)s from %(project.bzr)s')
- jc.add_ssh_command('''
+ jc.add_ssh_command(prelude + '''
sudo apt-get update
sudo apt-get --no-remove --allow-unauthenticated -y upgrade
''')
@@ -280,14 +303,11 @@ mv "${tarball}" "${artifacts}/."
self.add_rsync_workspace_to_target(jc)
jc.add_ssh_command(prelude + '''\
-sourcepkg=$(dpkg-parsechangelog | awk '/^Source:/ { print $2 }')
-wget -O "../${sourcepkg}_${version}.orig.tar.gz" \
- "%(global.artifacts-url)s/$project/$tarball"
-hostname
-dch -v "${version}-1" --distribution "%(host.debian-dist)s" "CI build"
+wget -O "../$origtgz" "$project_artifacts/$tarball"
+dch -v "$debianversion" --distribution "%(host.debian-dist)s" "CI build"
dch -r ''
debuild -S -us -uc
-dput -f "%(global.dput-host)s" "../${sourcepkg}_${version}-1_source.changes"
+dput -f "%(global.dput-host)s" "../$changes"
''')
self.add_rsync_workspace_from_target(jc)
@@ -299,7 +319,7 @@ dput -f "%(global.dput-host)s" "../${sourcepkg}_${version}-1_source.changes"
host = { 'name': 'localhost' }
jc = self.create_job_config(host, project, 'incoming_' + suffix)
jc.set_description('Process reprepro incoming queue')
- jc.add_shell_command(
+ jc.add_shell_command(prelude +
'reprepro -b "%(global.repreprobase)s" processincoming default')
return jc
@@ -319,26 +339,19 @@ binopt=-b
'''
else:
script += '''
-binopt=-B
if ! grep '^Architecture:.* any' debian/control > /dev/null
then
echo No architecture specific packages to build, skipping.
exit 0
fi
+binopt=-B
'''
jc.add_ssh_command(prelude + script + '''
-sourcepkg=$(dpkg-parsechangelog | awk '/^Source:/ { print $2 }')
-poolurl="%(global.artifacts-url)s/debian/pool/main"
-case "$sourcepkg" in
- lib*) subdir=$(echo "$sourcepkg" | cut -c1-4) ;;
- *) subdir=$(echo "$sourcepkg" | cut -c1) ;;
-esac
-dsc="${sourcepkg}_${version}-1.dsc"
curdir="$(pwd)"
temp="$(mktemp -d)"
cd "$temp"
-dget -u "$poolurl/$subdir/$sourcepkg/$dsc"
+dget -u "$poolurl/$dsc"
mkdir result
sudo pbuilder --build --buildresult result --debbuildopts $binopt *.dsc
dput "%(global.dput-host)s" \
@@ -367,13 +380,13 @@ rm -rf "$temp"
return jc
def add_rsync_workspace_to_target(self, jc):
- jc.add_ssh_command('mkdir -p "%(host.directory)s"')
- jc.add_shell_command(
+ jc.add_ssh_command(prelude + 'mkdir -p "%(host.directory)s"')
+ jc.add_shell_command(prelude +
'rsync -aHS --delete-before . '
'"%(host.ssh-target)s:%(host.directory)s/."')
def add_rsync_workspace_from_target(self, jc):
- jc.add_shell_command(
+ jc.add_shell_command(prelude +
'rsync -aHS --delete-before '
'"%(host.ssh-target)s:%(host.directory)s/." .')