Commit a440a29d authored by Tails developers's avatar Tails developers
Browse files

Import script that generates custom APT sources lines, and its Cucumber tests.

parent 30ac1cfa
#!/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
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
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
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
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment