[SCM] ci-tooling packaging branch, master, updated. be525a1bde7c499522c97d4069c8524971ab39e8
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Fri May 29 08:11:11 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=1bcf5b3
The following commit has been merged in the master branch:
commit 1bcf5b3f5a91f0ed973ee8ca02a135f871535e32
Author: Harald Sitter <sitter at kde.org>
Date: Fri May 29 10:08:53 2015 +0200
rename ppa-wait.rb to source_publisher (as is called the class inside)
also improve the code style a bit. the design in of itself is still
as terrible as it was before brrr
---
kci/ppa-wait.rb | 223 ------------------------------------------------
kci/source_publisher.rb | 201 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 201 insertions(+), 223 deletions(-)
diff --git a/kci/ppa-wait.rb b/kci/ppa-wait.rb
deleted file mode 100755
index 17cb9cc..0000000
--- a/kci/ppa-wait.rb
+++ /dev/null
@@ -1,223 +0,0 @@
-#!/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"
-
-class SourcePublisher
- def initialize(source_name, source_version, ppa = "unstable")
- @ppa = Launchpad::Rubber::from_url("https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/#{ppa}")
- @source_name = source_name
- @source_version = source_version
- end
-
- def wait
- #################################
-
- puts "------------------------- Waiting for LP Builds -------------------------"
-
- #################################
-
- # If it takes 20 minutes for the source to arrive it probably got rejected.
- fail_count = 20 # This is ~= minutes
- source = nil
- begin
- source = get_source()
- rescue RuntimeError => e # only rescue our own errors, others are fatal
- p e
- sleep(60)
- fail_count -= 1
- if fail_count <= 0
- puts 'Upload was likely rejected, we have been waiting for well over 20 minutes!'
- return false
- end
- retry
- end
- puts "Got a source, checking binaries..."
-
- #################################
-
- loop do
- sleep_time = 0
- needs_wait = false
- has_failed = false
-
- source.getBuilds().each do |build|
- state = build.buildstate
- puts "------"
- puts state
- puts source.source_package_version
- puts build.arch_tag
-
- case state
- when 'Needs building', 'Currently building', 'Uploading build', 'Cancelling build'
- needs_wait = true
- sleep_time = 60 if sleep_time < 60
- when 'Chroot problem', 'Failed to upload'
- # Can't handle retries due to lack of credentials
- has_failed = true
-# puts 'retry'
-# needs_wait = true
-# build.retry!
-# sleep_time = (60*5) if sleep_time < (60*5)
- when 'Failed to build', 'Build for superseded Source', 'Cancelled build', 'Dependency wait'
- has_failed = true
- when 'Successfully built'
- # all is cool
- else
- raise "Build state '#{build.buildstate}' is not being handled"
- end
- end
- puts "+++++"
- puts "going to fail: #{has_failed}. going to wait: #{needs_wait} (waiting for #{sleep_time})"
-
- if needs_wait
- puts "Sleeping for #{sleep_time} seconds....."
- sleep(sleep_time)
- next
- end
-
- if has_failed
- puts "Got a build failure"
- print_state(source)
- return false
- end
-
- puts 'Builds look fine, moving on to publication checks'
- break
- end
-
- while source.status == 'Pending'
- sleep(60*2)
- source = get_source() # We need a new source to get the status update.
- end
- puts 'Soure no longer pending, waiting for binaries...'
-
- loop do
- has_pending = false
- source_id = File.basename(source.self_link)
- build_summary = @ppa.getBuildSummariesForSourceIds(:source_ids => source_id)
- require 'pp'
- pp build_summary
- status = build_summary[source_id]['status']
- case status
- when 'FULLYBUILT_PENDING'
- has_pending = true
- when 'FULLYBUILT'
- has_pending = false
- else
- puts "Something very terrible happened as the overall state is #{status}, which was not expected at all"
- print_state(get_source())
- return false
- end
- if not has_pending
- puts 'All things are published, hooray!'
- break
- end
- sleep(60)
- end
-
- source = get_source()
- print_state(source)
- get_logs(source)
-
- puts 'PPA Wait done.'
- return true
- end
-
- private
- def print_state(source)
- puts "%s/%s (%s) %s" % [source.distro_series.name,
- source.source_package_name,
- source.source_package_version,
- source.status]
- build_logs = {}
- anchor_file = File.open('_anchor-chain', 'w')
- source.getBuilds().each do |build|
- puts " %s [%s] (%s) %s :: %s :: %s" % [source.source_package_name,
- build.arch_tag,
- source.source_package_version,
- build.buildstate,
- build.web_link,
- build.build_log_url]
- build_logs[build.arch_tag] = build.build_log_url
- anchor_file.write("%s %s
" % [build.arch_tag, build.build_log_url])
- end
- anchor_file.close
-
- build_log_marker = 'BUILD -'
- build_logs.each_pair do |arch, log|
- build_log_marker += " [#{arch}] (#{log})"
- end
- puts build_log_marker
-
- source.getPublishedBinaries().each do |binary|
- puts " #{binary.display_name} #{binary.status}"
- end
- end
-
- def get_logs(source)
- puts("getting logs...")
-
- log_dir = 'logs'
- FileUtils.rm_rf(log_dir)
- Dir.mkdir(log_dir)
-
- source.getBuilds().each do |build|
- uri = URI(build.build_log_url)
- begin
- Net::HTTP.start(uri.host) do |http|
- response = http.get(uri.path)
- basename = File.basename(uri.path)
- File.open("#{log_dir}/#{basename}", 'w') do |file|
- file.write(response.body)
- end
- end
- rescue => e
- p e
- retry
- end
- end
-
- archindep = source.distro_series.nominatedarchindep.architecture_tag
- if archindep
- File.open('archindep','w') do |file|
- file.write(archindep)
- end
- end
-
- puts "logs done."
- end
-
- def get_source
- p @source_name
- p @source_version
- p @ppa.getPublishedSources(:source_name => @source_name,
- :version => @source_version,
- :exact_match => false)
- source = @ppa.getPublishedSources(:source_name => @source_name,
- :version => @source_version)[0]
- raise 'got no source' if source == nil
- return source
- end
-end
-
-_version = "5.4.0"
-job_name = ARGV[0]
-ppa_name = ARGV[1]
-
-# Dir.chdir("build-area") unless File.basename(Dir.pwd) == "build-area"
-# Dir.chdir("#{job_name}-#{_version}")
-#
-# changelog = Changelog.new
-# publisher = SourcePublisher.new(changelog.name, changelog.version, ARGV[1])
-publisher = SourcePublisher.new("qtxmlpatterns-opensource-src", "5.4.0-0ubuntu1~ubuntu14.10~ppa2", ARGV[1])
-raise 'PPA Build Failed' unless publisher.wait
diff --git a/kci/source_publisher.rb b/kci/source_publisher.rb
new file mode 100755
index 0000000..9822f34
--- /dev/null
+++ b/kci/source_publisher.rb
@@ -0,0 +1,201 @@
+#!/usr/bin/env ruby
+
+require 'fileutils'
+
+require_relative 'lib/debian/changelog'
+require_relative 'lib/lp'
+
+class SourcePublisher
+ WAITING_STATES = ['Needs building', 'Currently building', 'Uploading build', 'Cancelling build']
+ FAILED_STATES = ['Chroot problem', 'Failed to upload', 'Failed to build', 'Build for superseded Source', 'Cancelled build', 'Dependency wait']
+ SUCCESS_STATES = ['Successfully built']
+
+ def initialize(source_name, source_version, ppa = 'unstable')
+ @ppa = Launchpad::Rubber.from_path("~kubuntu-ci/+archive/ubuntu/#{ppa}")
+ @source_name = source_name
+ @source_version = source_version
+ end
+
+ def wait
+ # If it takes 20 minutes for the source to arrive it probably got rejected.
+ fail_count = 20 # This is ~= minutes
+
+ until source
+ puts 'no source yet'
+ sleep(60)
+ fail_count -= 1
+ if fail_count <= 0
+ fail 'Upload was likely rejected, we have been waiting for well over 20 minutes!'
+ end
+ end
+
+ puts 'Got a source, checking binaries...'
+
+ #################################
+
+ loop do
+ sleep_time = 0
+ needs_wait = false
+ has_failed = false
+
+ source.getBuilds.each do |build|
+ state = build.buildstate
+ puts '------'
+ puts state
+ puts source.source_package_version
+ puts build.arch_tag
+
+ case state
+ when *WAITING_STATES
+ needs_wait = true
+ sleep_time = 60 if sleep_time < 60
+ when *FAILED_STATES
+ has_failed = true
+ when *SUCCESS_STATES
+ # all is cool
+ else
+ fail "Build state '#{build.buildstate}' is not being handled"
+ end
+ end
+ puts "+++++"
+ puts "going to fail: #{has_failed}. going to wait: #{needs_wait} (waiting for #{sleep_time})"
+
+ if needs_wait
+ puts "Sleeping for #{sleep_time} seconds....."
+ sleep(sleep_time)
+ next
+ end
+
+ if has_failed
+ puts "Got a build failure"
+ print_state(source)
+ return false
+ end
+
+ puts 'Builds look fine, moving on to publication checks'
+ break
+ end
+
+ sleep(60 * 2) while refresh_source!.status == 'Pending'
+ puts 'Soure no longer pending, waiting for binaries...'
+
+ loop do
+ has_pending = false
+ source_id = File.basename(source.self_link)
+ build_summary = @ppa.getBuildSummariesForSourceIds(:source_ids => source_id)
+ require 'pp'
+ pp build_summary
+ status = build_summary[source_id]['status']
+ case status
+ when 'FULLYBUILT_PENDING'
+ has_pending = true
+ when 'FULLYBUILT'
+ has_pending = false
+ else
+ # FIXME: fail?
+ puts "Something very terrible happened as the overall state is #{status}, which was not expected at all"
+ print_state(get_source())
+ return false
+ end
+ if not has_pending
+ puts 'All things are published, hooray!'
+ break
+ end
+ sleep(60)
+ end
+ puts 'Source published!'
+
+ refresh_source!
+ print_state(source)
+ get_logs(source)
+
+ puts 'PPA Wait done.'
+ true
+ end
+
+ private
+
+ def print_state(source)
+ puts "%s/%s (%s) %s" % [source.distro_series.name,
+ source.source_package_name,
+ source.source_package_version,
+ source.status]
+ build_logs = {}
+ anchor_file = File.open('_anchor-chain', 'w')
+ source.getBuilds().each do |build|
+ puts " %s [%s] (%s) %s :: %s :: %s" % [source.source_package_name,
+ build.arch_tag,
+ source.source_package_version,
+ build.buildstate,
+ build.web_link,
+ build.build_log_url]
+ build_logs[build.arch_tag] = build.build_log_url
+ anchor_file.write("%s %s
" % [build.arch_tag, build.build_log_url])
+ end
+ anchor_file.close
+
+ build_log_marker = 'BUILD -'
+ build_logs.each_pair do |arch, log|
+ build_log_marker += " [#{arch}] (#{log})"
+ end
+ puts build_log_marker
+
+ source.getPublishedBinaries().each do |binary|
+ puts " #{binary.display_name} #{binary.status}"
+ end
+ end
+
+ def get_logs(source)
+ puts("getting logs...")
+
+ log_dir = 'logs'
+ FileUtils.rm_rf(log_dir)
+ Dir.mkdir(log_dir)
+
+ source.getBuilds.each do |build|
+ uri = URI(build.build_log_url)
+ begin
+ Net::HTTP.start(uri.host) do |http|
+ response = http.get(uri.path)
+ basename = File.basename(uri.path)
+ File.open("#{log_dir}/#{basename}", 'w') do |file|
+ file.write(response.body)
+ end
+ end
+ rescue => e
+ p e
+ retry
+ end
+
+ archindep = source.distro_series.nominatedarchindep.architecture_tag
+ File.write('archindep', archindep) if archindep
+
+ puts "logs done."
+ end
+ end
+
+ def source
+ return @source if defined?(@source)
+ sources = @ppa.getPublishedSources(source_name: @source_name, version: @source_version, exact_match: true)
+ # TODO: handle too many matches, handle too few matches, handle raise
+ puts "source: #{sources[0]}"
+ Source.include_in(@source = sources[0])
+ end
+
+ def refresh_source!
+ return unless defined?(@source)
+ remove_instance_variable(:@source)
+ source
+ end
+end
+
+if __FILE__ == $PROGRAM_NAME
+ _version = "5.4.0"
+ # job_name = ARGV[0]
+ # ppa_name = ARGV[1]
+
+ # publisher = SourcePublisher.new(changelog.name, changelog.version, ARGV[1])
+ publisher = SourcePublisher.new("qtxmlpatterns-opensource-src", "5.4.0-0ubuntu1~ubuntu14.10~ppa2", 'unstable')
+ abort 'PPA Build Failed' unless publisher.wait
+ sleep(5)
+end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list