#!/usr/bin/env ruby
ENV['PATH'] = '/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin'
if Process.uid == 0
File.open('/etc/apt/apt.conf.d/apt-cacher', 'w') { |file| file.puts('Acquire::http { Proxy "http://10.0.3.1:3142"; };') }
exit 1 unless system("apt-get update")
exit 1 unless system("apt-get install -y ruby ruby-dev")
exit 1 unless system("gem install jenkins_api_client oauth")
end
require "fileutils"
require_relative "lib/debian/changelog"
require_relative "lib/lp"
eval %x[grep VERSION_ID /etc/os-release].strip
DISTRIB_CODENAME = %x[grep DISTRIB_CODENAME /etc/lsb-release].strip.split("=")[-1]
_version = "5.4.0"
job_dist = ARGV[0]
job_type = ARGV[1]
job_name = ARGV[2]
source_name = nil
Dir.chdir("packaging") do
changelog = Changelog.new
source_name = changelog.name
end
ppa = Launchpad::Rubber::from_url("https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/stage")
distro_series = Launchpad::Rubber::from_url("https://api.launchpad.net/devel/ubuntu/#{DISTRIB_CODENAME}")
begin
source = ppa.getPublishedSources(:source_name => source_name,
:distro_series => distro_series)[0] # This is sorted
rescue
# no source in ppa yet
puts "Found no previous upload in PPA..."
source = nil
end
Dir.mkdir("build-area") unless File.exist?("build-area")
Dir.chdir("build-area") do
# cleanup previous builds - drop changes, that way we can retain the packages
# while avoiding conflicts with debsign/dput wildcards.
Dir.glob("*.changes").each { |c| File.delete(c) }
# Get orig tar.
tar = "#{job_name}-#{_version}.tar.xz"
unless File.exist?(tar)
raise "tar download failed" unless system("wget http://download.qt-project.org/official_releases/qt/5.4/#{_version}/submodules/#{job_name}-#{_version}.tar.xz")
end
base = File.basename(tar, ".tar.xz")
split_base = base.split("-")
version = split_base.pop
name = split_base.join("-")
orig_tar= "#{name}_#{version}.orig.tar.xz"
File.delete(orig_tar) if File.exist?(orig_tar)
raise "failed to symlink orig tar" unless system("ln -s #{tar} #{orig_tar}")
end
# Figure out the version to use
pkg_version = nil
# FIXME: _version needs to be compared with what is in the PPA to bump it
if source
ppa_too_old = system("dpkg --compare-versions #{_version} gt #{source.source_package_version}")
unless ppa_too_old
pkg_version = source.source_package_version
match = pkg_version.match(/(.*~ppa)(\d+)/)
# Bump the ppa revision.
pkg_version = match[1] + (match[2].to_i + 1).to_s
end
end
if pkg_version.nil? # Fallback
pkg_version = "#{_version}-0ubuntu1~ubuntu#{VERSION_ID}~ppa1"
end
Dir.chdir("build-area") do
FileUtils.rm_rf("#{job_name}-#{_version}")
Dir.mkdir("#{job_name}-#{_version}")
`tar -xf "#{job_name}_#{_version}.orig.tar.xz" -C #{job_name}-#{_version} --strip-components 1`
`cp -rv ../packaging/* #{job_name}-#{_version}/`
Dir.chdir("#{job_name}-#{_version}") do
FileUtils.rm_rf(".bzr")
FileUtils.rm_rf(".git")
raise unless system({'DEBFULLNAME' => 'Kubuntu CI',
'DEBEMAIL' => 'kubuntu-ci@lists.launchpad.net'},
"dch -v #{pkg_version} -D #{DISTRIB_CODENAME} -b 'PPA Build'")
raise unless system("dpkg-buildpackage -S -us -uc -sa")
end
end
# Source package now exist in build-area/.
# Yield back to jenkins script to do host things...