Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for switching books to asciidoctor #606

Merged
merged 4 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ contents:
branches: [ master ]
tags: Elastic Stack/Glossary
subject: Elastic Stack
asciidoctor: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought: Should/could this be a list of versions (akin to "branches") instead of a boolean? If so, it would give us more wiggle room if we can't convert some of the very old releases to asciidoctor builds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to do that when we figure out that we need it.

sources:
-
repo: stack-docs
Expand Down
21 changes: 18 additions & 3 deletions lib/ES/Book.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ sub new {

my $lang = $args{lang} || 'en';

# be careful about true/false here so there are no surprises.
# otherwise someone is bound to set `asciidoctor` to `false`
# and perl will evaluate that to true....
my $asciidoctor = 0;
if (exists $args{asciidoctor}) {
$asciidoctor = $args{asciidoctor};
if ($asciidoctor eq 'true') {
$asciidoctor = 1;
} elsif ($asciidoctor eq 'false') {
$asciidoctor = 0;
} else {
die 'asciidoctor must be true or false but was ' . $asciidoctor;
}
}

bless {
title => $title,
dir => $dir->subdir($prefix),
Expand All @@ -132,7 +147,7 @@ sub new {
private => $args{private} || '',
noindex => $args{noindex} || '',
lang => $lang,
asciidoctor => $args{asciidoctor} || 0,
asciidoctor => $asciidoctor,
}, $class;
}

Expand All @@ -153,7 +168,7 @@ sub build {
$Opts->{procs},
sub {
my ( $pid, $error, $branch ) = @_;
$self->source->mark_done( $title, $branch );
$self->source->mark_done( $title, $branch, $self->asciidoctor );
}
);

Expand Down Expand Up @@ -219,7 +234,7 @@ sub _build_book {
if -e $branch_dir
&& !$rebuild
&& !$template->md5_changed($branch_dir)
&& !$source->has_changed( $self->title, $branch );
&& !$source->has_changed( $self->title, $branch, $self->asciidoctor );

my ( $checkout, $first_path ) = $source->prepare($branch);

Expand Down
10 changes: 7 additions & 3 deletions lib/ES/Repo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ sub _reference_args {
sub has_changed {
#===================================
my $self = shift;
my ( $title, $branch, $path ) = @_;
my ( $title, $branch, $path, $asciidoctor ) = @_;

my $old
= $self->tracker->sha_for_branch( $self->name,
Expand All @@ -145,6 +145,7 @@ sub has_changed {
or die "Remote branch <origin/$branch> doesn't exist "
. "in repo "
. $self->name;
$new .= '|asciidoctor' if $asciidoctor;

return if $old eq $new;

Expand All @@ -162,11 +163,12 @@ sub has_changed {
sub mark_done {
#===================================
my $self = shift;
my ( $title, $branch, $path ) = @_;
my ( $title, $branch, $path, $asciidoctor ) = @_;

local $ENV{GIT_DIR} = $self->git_dir;

my $new = sha_for($branch);
$new .= '|asciidoctor' if $asciidoctor;
$self->tracker->set_sha_for_branch( $self->name,
$self->_tracker_branch(@_), $new );

Expand Down Expand Up @@ -296,7 +298,9 @@ sub all_repo_branches {
my $shas = $repo->tracker->shas_for_repo( $repo->name );

for my $branch ( sort keys %$shas ) {
my $log = run( qw(git log --oneline -1), $shas->{$branch} );
my $sha = $shas->{$branch};
$sha =~ s/\|.+$//; # Strip |asciidoctor if it is in the hash
my $log = run( qw(git log --oneline -1), $sha );
my ($msg) = ( $log =~ /^\w+\s+([^\n]+)/ );
push @out, sprintf " %-35s %s %s", $branch,
substr( $shas->{$branch}, 0, 8 ), $msg;
Expand Down
6 changes: 4 additions & 2 deletions lib/ES/Source.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ sub has_changed {
my $self = shift;
my $title = shift;
my $branch = shift;
my $asciidoctor = shift;
for my $source ( $self->_sources_for_branch($branch) ) {
return 1
if $source->{repo}->has_changed( $title, $branch, $source->{path} );
if $source->{repo}->has_changed( $title, $branch, $source->{path}, $asciidoctor );
}
return;
}
Expand All @@ -63,8 +64,9 @@ sub mark_done {
my $self = shift;
my $title = shift;
my $branch = shift;
my $asciidoctor = shift;
for my $source ( $self->_sources_for_branch($branch) ) {
$source->{repo}->mark_done( $title, $branch, $source->{path} );
$source->{repo}->mark_done( $title, $branch, $source->{path}, $asciidoctor );
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ES/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ sub build_chunked {
file('resources/website_chunked.xsl')->absolute,
"$dest/index.xml"
);
# unlink "$dest/index.xml";
unlink "$dest/index.xml";
1;
} or do { $output = $@; $died = 1; };
}
Expand Down