summaryrefslogtreecommitdiffstats
path: root/cucumber/features/step_definitions/build.rb
blob: e02edc624ec7ef771c941a156ae0d5c03d908705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Given /^Tails ([[:alnum:]~.]+) has been released$/ do |version|
  create_git unless git_exists?

  old_branch = current_branch

  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.gsub('~', '-')}'"

  if old_branch != 'stable'
    fatal_system "git checkout --quiet '#{old_branch}'"
    fatal_system "git merge    --quiet 'stable'"
  end
end

Given /^Tails ([[:alnum:].-]+) has been tagged$/ do |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 /^the last 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 /^the last versions mentioned in debian\/changelog are ([[:alnum:]~.]+) and ([[:alnum:]~.]+)$/ do |version_a, version_b|
  step "the last version mentioned in debian/changelog is #{version_a}"
  step "the last version mentioned in debian/changelog is #{version_b}"
end

Given(/^no frozen APT snapshot is encoded in config\/APT_snapshots\.d$/) do
  ['debian', 'debian-security', 'torproject'].map do |origin|
    File.open("config/APT_snapshots.d/#{origin}/serial", 'w+') do |serial|
      serial.write("latest\n")
    end
  end
end

Given(/^frozen APT snapshots are encoded in config\/APT_snapshots\.d$/) do
  ['debian', 'torproject'].map do |origin|
    File.open("config/APT_snapshots.d/#{origin}/serial", 'w+') do |serial|
      serial.write("2016060602\n")
    end
  end
  # We never freeze debian-security
  File.open("config/APT_snapshots.d/debian-security/serial", 'w+') do |serial|
    serial.write("latest\n")
  end
end

Given %r{I am working on the ([[:alnum:]./_-]+) base branch$} do |branch|
  create_git unless git_exists?

  if current_branch != branch
    fatal_system "git checkout --quiet '#{branch}'"
  end

  File.open('config/base_branch', 'w+') do |base_branch_file|
    base_branch_file.write("#{branch}\n")
  end
end

Given %r{^I checkout the ([[:alnum:]~.-]+) tag$} do |tag|
  create_git unless git_exists?
  fatal_system "git checkout --quiet #{tag}"
end

Given %r{I am working on the ([[:alnum:]./_-]+) branch based on ([[:alnum:]./_-]+)$} do |branch, base|
  create_git unless git_exists?

  if current_branch != branch
    fatal_system "git checkout --quiet -b '#{branch}' '#{base}'"
  end

  File.open('config/base_branch', 'w+') do |base_branch_file|
    base_branch_file.write("#{base}\n")
  end
end

When /^I successfully run "?([[:alnum:] -]+)"?$/ do |command|
  @output = `#{File.expand_path("../../../auto/scripts/#{command}", __FILE__)}`
  raise StandardError.new("#{command} failed. Exit code: #{$?}") if $? != 0
end

When /^I run "?([[:alnum:] -]+)"?$/ do |command|
  @output = `#{File.expand_path("../../../auto/scripts/#{command}", __FILE__)}`
  @exit_code = $?.exitstatus
end

Then /^I should see the ['"]?([[:alnum:].-]+)['"]? suite$/ do |suite|
  @output.should have_suite(suite)
end

Then /^I should see only the ['"]?([[:alnum:].-]+)['"]? suite$/ do |suite|
  assert_equal(1, @output.lines.count)
  @output.should have_suite(suite)
end

Then /^I should not see the ['"]?([[:alnum:].-]+)['"]? suite$/ do |suite|
  @output.should_not have_suite(suite)
end

Given(/^the config\/APT_overlays\.d directory is empty$/) do
  Dir.glob('config/APT_overlays.d/*').empty? \
  or raise "config/APT_overlays.d/ is not empty"
end

Given(/^config\/APT_overlays\.d contains ['"]?([[:alnum:].-]+)['"]?$/) do |suite|
  FileUtils.touch("config/APT_overlays.d/#{suite}")
end

Then(/^it should fail$/) do
  assert_not_equal(0, @exit_code)
end

Given(/^the (config\/base_branch) file does not exist$/) do |file|
  File.delete(file)
end

Given(/^the (config\/APT_overlays\.d) directory does not exist$/) do |dir|
  Dir.rmdir(dir)
end

Given(/^the config\/base_branch file is empty$/) do
  File.truncate('config/base_branch', 0)
end

Then(/^I should see the ([[:alnum:].-]+) tagged snapshot$/) do |tag|
  @output.should have_tagged_snapshot(tag)
end

Then(/^I should see a time\-based snapshot$/) do
  @output.should have_time_based_snapshot()
end