Skip to content

Commit 11ed7c3

Browse files
committed
Verify that all 'live' branches actually exist
Fail if there is a branch in the 'live' list that is not also in the 'branches' list.
1 parent 5ef1bdd commit 11ed7c3

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Style/TrailingCommaInArrayLiteral:
1717
Style/TrailingCommaInHashLiteral:
1818
EnforcedStyleForMultiline: comma
1919

20+
Style/WordArray:
21+
Enabled: false
22+
2023
Metrics/AbcSize:
2124
Max: 20
2225

integtest/spec/all_books_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,27 @@ def self.setup_example(repo, lang, hash)
718718
end
719719
end
720720

721+
context 'when a live branch is not in the list of branches' do
722+
convert_before do |src, dest|
723+
repo = src.repo_with_index 'repo', 'some text'
724+
725+
book = src.book 'Test'
726+
book.source repo, 'index.asciidoc'
727+
book.branches = ['master']
728+
book.live_branches = ['newer', 'master', 'missing']
729+
dest.prepare_convert_all(src.conf).convert(expect_failure: true)
730+
end
731+
it 'fails with an appropriate error status' do
732+
puts outputs
733+
expect(statuses[0]).to eq(2)
734+
end
735+
it 'logs the missing file' do
736+
expect(outputs[0]).to include(<<~LOG.strip)
737+
Live branch(es) <newer, missing> not in <branches> in book <Test>
738+
LOG
739+
end
740+
end
741+
721742
context 'when run with --announce_preview' do
722743
target_branch = 'foo_1'
723744
preview_location = "http://#{target_branch}.docs-preview.app.elstc.co/guide"

lib/ES/Book.pm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ sub new {
117117
die "Current branch <$current> is not in <branches> in book <$title>"
118118
unless $branch_titles{$current};
119119

120+
my $live_branches = $args{live};
121+
# If `live` is defined, check if there are any specified branches that
122+
# aren't in the list of branches being built.
123+
my @difference;
124+
foreach my $item (@$live_branches) {
125+
push @difference, $item unless grep { $item eq $_ } @branches;
126+
}
127+
128+
# print "Branches: ", join(", ", @branches), "\n";
129+
# print "Live: ", join(", ", @$live_branches), "\n";
130+
# print "Difference: ", join(", ", @difference), "\n";
131+
132+
my $missing = join ", ", @difference;
133+
die "Live branch(es) <$missing> not in <branches> in book <$title>"
134+
if $difference[0];
135+
120136
my $tags = $args{tags}
121137
or die "No <tags> specified for book <$title>";
122138

schema.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ book:
6666
current: include("branch")
6767

6868
# List of branches shown by default in the dropdown (and are still receiving updates)
69+
# All items in this list must also be in `branches`.
6970
# TODO: Change this to be a list of versions.
7071
live: list(include("branch"), required=False)
7172

0 commit comments

Comments
 (0)