Skip to content

Commit

Permalink
Verify that all 'live' branches actually exist
Browse files Browse the repository at this point in the history
Fail if there is a branch in the 'live' list that is not also in the
'branches' list.
  • Loading branch information
gtback committed Aug 11, 2022
1 parent 5ef1bdd commit 11ed7c3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Style/TrailingCommaInArrayLiteral:
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/WordArray:
Enabled: false

Metrics/AbcSize:
Max: 20

Expand Down
21 changes: 21 additions & 0 deletions integtest/spec/all_books_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,27 @@ def self.setup_example(repo, lang, hash)
end
end

context 'when a live branch is not in the list of branches' do
convert_before do |src, dest|
repo = src.repo_with_index 'repo', 'some text'

book = src.book 'Test'
book.source repo, 'index.asciidoc'
book.branches = ['master']
book.live_branches = ['newer', 'master', 'missing']
dest.prepare_convert_all(src.conf).convert(expect_failure: true)
end
it 'fails with an appropriate error status' do
puts outputs
expect(statuses[0]).to eq(2)
end
it 'logs the missing file' do
expect(outputs[0]).to include(<<~LOG.strip)
Live branch(es) <newer, missing> not in <branches> in book <Test>
LOG
end
end

context 'when run with --announce_preview' do
target_branch = 'foo_1'
preview_location = "http://#{target_branch}.docs-preview.app.elstc.co/guide"
Expand Down
16 changes: 16 additions & 0 deletions lib/ES/Book.pm
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ sub new {
die "Current branch <$current> is not in <branches> in book <$title>"
unless $branch_titles{$current};

my $live_branches = $args{live};
# If `live` is defined, check if there are any specified branches that
# aren't in the list of branches being built.
my @difference;
foreach my $item (@$live_branches) {
push @difference, $item unless grep { $item eq $_ } @branches;
}

# print "Branches: ", join(", ", @branches), "\n";
# print "Live: ", join(", ", @$live_branches), "\n";
# print "Difference: ", join(", ", @difference), "\n";

my $missing = join ", ", @difference;
die "Live branch(es) <$missing> not in <branches> in book <$title>"
if $difference[0];

my $tags = $args{tags}
or die "No <tags> specified for book <$title>";

Expand Down
1 change: 1 addition & 0 deletions schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ book:
current: include("branch")

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

Expand Down

0 comments on commit 11ed7c3

Please sign in to comment.