[SCM] ci-tooling packaging branch, master, updated. 9a7ceeed5b56d3cd3cfe2b9654bc42754a47f524
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Mon Mar 23 10:55:44 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=c43fc4b
The following commit has been merged in the master branch:
commit c43fc4b5975748bd7e5ca6593d18de7bca7be2d9
Author: Harald Sitter <sitter at kde.org>
Date: Mon Mar 23 11:54:44 2015 +0100
add a class to wrap around Changelog and beat into a build version
---
lib/ci/build_version.rb | 45 +++++++++++++++++++++
.../test_all}/debian/changelog | 2 +-
.../test_bad_version}/debian/changelog | 2 +-
test/test_ci_build_version.rb | 46 ++++++++++++++++++++++
4 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/lib/ci/build_version.rb b/lib/ci/build_version.rb
new file mode 100644
index 0000000..ec7592a
--- /dev/null
+++ b/lib/ci/build_version.rb
@@ -0,0 +1,45 @@
+require 'date'
+
+require_relative '../lsb'
+
+module CI
+ # Wraps a debian changelog to construct a build specific version based on the
+ # version used in the changelog.
+ class BuildVersion
+ # Version (including epoch)
+ attr_reader :base
+ # Version (excluding epoch)
+ attr_reader :tar
+ # Version include epoch AND possibly a revision
+ attr_reader :full
+
+ def initialize(changelog)
+ @changelog = changelog
+ @suffix = sprintf('+git%s+%s',
+ DateTime.now.strftime('%Y%m%d.%H%M'),
+ LSB::DISTRIB_RELEASE)
+ @tar = "#{clean_base}#{@suffix}"
+ @base = "#{changelog.version(Changelog::EPOCH)}#{clean_base}#{@suffix}"
+ @full = "#{base}-0ubuntu0"
+ end
+
+ # Version (including epoch AND possibly a revision)
+ def to_s
+ full
+ end
+
+ private
+
+ # Removes non digits from base version string.
+ # This is to get rid of pesky alphabetic suffixes such as 5.2.2a which are
+ # lower than 5.2.2+git (which we might have used previously), as + reigns
+ # supreme. Always.
+ def clean_base
+ base = @changelog.version(Changelog::BASE)
+ base = base.chop until base.empty? || base[-1].match(/[\d\.]/)
+ return base unless base.empty?
+ fail 'Failed to find numeric version in the changelog version:' \
+ " #{@changelog.version(Changelog::BASE)}"
+ end
+ end
+end
diff --git a/test/data/test_debian_changelog/test_alphabase/debian/changelog b/test/data/test_ci_build_version/test_all/debian/changelog
similarity index 65%
copy from test/data/test_debian_changelog/test_alphabase/debian/changelog
copy to test/data/test_ci_build_version/test_all/debian/changelog
index 9df8134..9ead081 100644
--- a/test/data/test_debian_changelog/test_alphabase/debian/changelog
+++ b/test/data/test_ci_build_version/test_all/debian/changelog
@@ -1,4 +1,4 @@
-khelpcenter (4:5.2.1a-0ubuntu1) vivid; urgency=medium
+khelpcenter (4:5.2.2a-0ubuntu1) vivid; urgency=medium
* New upstream release
diff --git a/test/data/test_debian_changelog/test_alphabase/debian/changelog b/test/data/test_ci_build_version/test_bad_version/debian/changelog
similarity index 65%
copy from test/data/test_debian_changelog/test_alphabase/debian/changelog
copy to test/data/test_ci_build_version/test_bad_version/debian/changelog
index 9df8134..696ac0b 100644
--- a/test/data/test_debian_changelog/test_alphabase/debian/changelog
+++ b/test/data/test_ci_build_version/test_bad_version/debian/changelog
@@ -1,4 +1,4 @@
-khelpcenter (4:5.2.1a-0ubuntu1) vivid; urgency=medium
+khelpcenter (4:abc-0ubuntu1) vivid; urgency=medium
* New upstream release
diff --git a/test/test_ci_build_version.rb b/test/test_ci_build_version.rb
new file mode 100644
index 0000000..6e5f164
--- /dev/null
+++ b/test/test_ci_build_version.rb
@@ -0,0 +1,46 @@
+require 'test/unit'
+
+require_relative '../lib/ci/build_version'
+require_relative '../lib/debian/changelog'
+
+# Test ci/build_version
+class CIBuildVersionTest < Test::Unit::TestCase
+ def setup
+ script_base_path = File.expand_path(File.dirname(__FILE__))
+ script_name = File.basename(__FILE__, '.rb')
+ @datadir = File.join(script_base_path, 'data', script_name)
+ @previous_pwd = Dir.pwd
+ Dir.chdir(@datadir)
+ end
+
+ def teardown
+ Dir.chdir(@previous_pwd)
+ end
+
+ def data(path = nil)
+ index = 0
+ caller = ''
+ until caller.start_with?('test_')
+ caller = caller_locations(index, 1)[0].label
+ index += 1
+ end
+ File.join(*[@datadir, caller, path].compact)
+ end
+
+ def test_all
+ c = Changelog.new(data)
+ v = CI::BuildVersion.new(c)
+ suffix = v.send(:instance_variable_get, :@suffix)
+ assert_equal("4:5.2.2#{suffix}", v.base)
+ assert_equal("5.2.2#{suffix}", v.tar)
+ assert_equal("4:5.2.2#{suffix}-0ubuntu0", v.full)
+ assert_equal(v.full, v.to_s)
+ end
+
+ def test_bad_version
+ c = Changelog.new(data)
+ assert_raise RuntimeError do
+ CI::BuildVersion.new(c)
+ end
+ end
+end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list