summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTails developers <amnesia@boum.org>2012-02-04 11:35:31 +0100
committerTails developers <amnesia@boum.org>2012-02-04 11:35:31 +0100
commita440a29de9efe3032ac8b11fa2d8990b04d34d5e (patch)
tree3f456d6b8bb7dab1dc5569c9516007b9b33ca219
parent30ac1cfab32ffed6ea92beba6713c2fb3d23f89f (diff)
Import script that generates custom APT sources lines, and its Cucumber tests.
-rwxr-xr-xauto/scripts/tails-custom-apt-sources56
-rw-r--r--features/build.feature46
-rw-r--r--features/step_definitions/build.rb67
-rw-r--r--features/support/env.rb47
-rw-r--r--features/support/hooks.rb12
5 files changed, 228 insertions, 0 deletions
diff --git a/auto/scripts/tails-custom-apt-sources b/auto/scripts/tails-custom-apt-sources
new file mode 100755
index 0000000..7e26096
--- /dev/null
+++ b/auto/scripts/tails-custom-apt-sources
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+set -e
+
+APT_MIRROR_URL="http://deb.tails.boum.org/"
+DEFAULT_COMPONENTS="main"
+
+git_tag_exists() {
+ local tag="$1"
+
+ test -f ".git/refs/tags/$tag"
+}
+
+version_was_released() {
+ local version="$1"
+
+ git_tag_exists "$version"
+}
+
+version_in_changelog() {
+ dpkg-parsechangelog | awk '/^Version: / { print $2 }'
+}
+
+output_apt_binary_source() {
+ local suite="$1"
+ local components="${2:-$DEFAULT_COMPONENTS}"
+
+ echo "deb $APT_MIRROR_URL $suite $components"
+}
+
+current_branch() {
+ git branch | awk '/^\* / { print $2 }'
+}
+
+on_topic_branch() {
+ current_branch | grep -qE '^(feature|bug|bugfix)/'
+}
+
+branch_name_to_suite() {
+ local branch="$1"
+
+ echo "$branch" | sed -e 's,[^a-z0-9-],-,ig' | tr '[A-Z]' '[a-z]'
+}
+
+
+if version_was_released "$(version_in_changelog)"; then
+ output_apt_binary_source "$(version_in_changelog)"
+elif [ "$(current_branch)" = "testing" ]; then
+ output_apt_binary_source testing
+else
+ output_apt_binary_source devel
+fi
+
+if on_topic_branch; then
+ output_apt_binary_source "$(branch_name_to_suite $(current_branch))"
+fi
diff --git a/features/build.feature b/features/build.feature
new file mode 100644
index 0000000..7b614ac
--- /dev/null
+++ b/features/build.feature
@@ -0,0 +1,46 @@
+Feature: custom APT sources to build branches
+ As a Tails developer, when I build Tails, I'd be happy if
+ the proper APT sources were automatically picked depending
+ on which Git branch I am working on.
+
+ Scenario: build from a tagged stable branch
+ Given Tails 0.10 has been released
+ And last released version mentioned in debian/changelog is 0.10
+ And I am working on the stable branch
+ When I run tails-custom-apt-sources
+ Then I should see the '0.10' suite
+
+ Scenario: build from a bugfix branch for a stable release
+ Given Tails 0.10 has been released
+ And last released version mentioned in debian/changelog is 0.10
+ And I am working on the bugfix/disable_gdomap branch based on 0.10
+ When I run tails-custom-apt-sources
+ Then I should see the '0.10' suite
+ And I should see the 'bugfix-disable-gdomap' suite
+
+ Scenario: build from an untagged testing branch
+ Given I am working on the testing branch
+ And last released version mentioned in debian/changelog is 0.11
+ And Tails 0.11 has not been released yet
+ When I run tails-custom-apt-sources
+ Then I should see the 'testing' suite
+ And I should not see '0.11' suite
+
+ Scenario: build from a tagged testing branch
+ Given I am working on the testing branch
+ And last released version mentioned in debian/changelog is 0.11
+ And Tails 0.11 has been released
+ When I run tails-custom-apt-sources
+ Then I should see the '0.11' suite
+ And I should not see 'testing' suite
+
+ Scenario: build from the devel branch
+ Given I am working on the devel branch
+ When I run tails-custom-apt-sources
+ Then I should see the 'devel' suite
+
+ Scenario: build from a feature branch based on devel
+ Given I am working on the feature/icedove branch based on devel
+ When I run tails-custom-apt-sources
+ Then I should see the 'devel' suite
+ And I should see the 'feature-icedove' suite
diff --git a/features/step_definitions/build.rb b/features/step_definitions/build.rb
new file mode 100644
index 0000000..40fd445
--- /dev/null
+++ b/features/step_definitions/build.rb
@@ -0,0 +1,67 @@
+Given /^Tails ([[:alnum:].]+) has been released$/ do |version|
+ create_git unless git_exists?
+
+ fatal_system "git checkout --quiet stable"
+ old_entries = File.open('debian/changelog') { |f| f.read }
+ File.open('debian/changelog', 'w') do |changelog|
+ changelog.write(<<END_OF_CHANGELOG)
+tails (#{version}) stable; urgency=low
+
+ * New upstream release.
+
+ -- Tails developers <tails@boum.org> Tue, 31 Jan 2012 15:12:57 +0100
+
+#{old_entries}
+END_OF_CHANGELOG
+ end
+ fatal_system "git commit --quiet debian/changelog -m 'Release #{version}'"
+ fatal_system "git tag '#{version}'"
+end
+
+Given /^Tails ([[:alnum:].]+) has not been released yet$/ do |version|
+ !File.exists? ".git/refs/tags/#{version}"
+end
+
+Given /^last released version mentioned in debian\/changelog is ([[:alnum:].]+)$/ do |version|
+ last = `dpkg-parsechangelog | awk '/^Version: / { print $2 }'`.strip
+ raise StandardError.new('dpkg-parsechangelog failed.') if $? != 0
+
+ if last != version
+ fatal_system "debchange -v '#{version}' 'New upstream release'"
+ end
+end
+
+Given %r{I am working on the ([[:alnum:]./_-]+) branch$} do |branch|
+ create_git unless git_exists?
+
+ current_branch = `git branch | awk '/^\*/ { print $2 }'`.strip
+ raise StandardError.new('git-branch failed.') if $? != 0
+
+ if current_branch != branch
+ fatal_system "git checkout --quiet '#{branch}'"
+ end
+end
+
+Given %r{I am working on the ([[:alnum:]./_-]+) branch based on ([[:alnum:]./_-]+)$} do |branch, base|
+ create_git unless git_exists?
+
+ current_branch = `git branch | awk '/^\*/ { print $2 }'`.strip
+ raise StandardError.new('git-branch failed.') if $? != 0
+
+ if current_branch != branch
+ fatal_system "git checkout --quiet -b '#{branch}' '#{base}'"
+ end
+end
+
+When /^I run ([[:alnum:]-]+)$/ do |command|
+ @output = `#{File.expand_path("../../../auto/scripts/#{command}", __FILE__)}`
+ raise StandardError.new("#{command} failed. Exit code: #{$?}") if $? != 0
+end
+
+Then /^I should see the ['"]?([[:alnum:].-]+)['"]? suite$/ do |suite|
+ @output.should have_suite(suite)
+end
+
+Then /^I should not see ['"]?([[:alnum:].-]+)['"]? suite$/ do |suite|
+ @output.should_not have_suite(suite)
+end
diff --git a/features/support/env.rb b/features/support/env.rb
new file mode 100644
index 0000000..36ebcb3
--- /dev/null
+++ b/features/support/env.rb
@@ -0,0 +1,47 @@
+require 'rspec'
+
+def fatal_system(str)
+ unless system(str)
+ raise StandardError.new("Command exited with #{$?}")
+ end
+end
+
+def git_exists?
+ File.exists? '.git'
+end
+
+def create_git
+ Dir.mkdir 'debian'
+ File.open('debian/changelog', 'w') do |changelog|
+ changelog.write(<<END_OF_CHANGELOG)
+tails (0) stable; urgency=low
+
+ * First release.
+
+ -- Tails developers <tails@boum.org> Mon, 30 Jan 2012 01:00:00 +0000
+END_OF_CHANGELOG
+ end
+
+ fatal_system "git init --quiet"
+ fatal_system "git add debian/changelog"
+ fatal_system "git commit --quiet debian/changelog -m 'First release'"
+ fatal_system "git branch -M stable"
+ fatal_system "git branch testing stable"
+ fatal_system "git branch devel stable"
+end
+
+RSpec::Matchers.define :have_suite do |suite|
+ match do |string|
+ # e.g.: `deb http://deb.tails.boum.org/ 0.10 main contrib non-free`
+ %r{^deb +http://deb\.tails\.boum\.org/ +#{suite} main}.match(string)
+ end
+ failure_message_for_should do |string|
+ "expected the sources to include #{suite}\nCurrent sources : #{string}"
+ end
+ failure_message_for_should_not do |string|
+ "expected the sources to exclude #{suite}\nCurrent sources : #{string}"
+ end
+ description do
+ "expected an output with #{suite}"
+ end
+end
diff --git a/features/support/hooks.rb b/features/support/hooks.rb
new file mode 100644
index 0000000..32d33f8
--- /dev/null
+++ b/features/support/hooks.rb
@@ -0,0 +1,12 @@
+require 'tmpdir'
+
+Before do
+ @orig_pwd = Dir.pwd
+ @git_clone = Dir.mktmpdir 'tails-apt-tests'
+ Dir.chdir @git_clone
+end
+
+After do
+ Dir.chdir @orig_pwd
+ FileUtils.remove_entry_secure @git_clone
+end