Skip to content

Improvements for book sources #1250

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

Merged
merged 8 commits into from
Oct 4, 2019

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Oct 3, 2019

This adds two features that are sort of interlinked in their
implementation but not so much in their use. We want them both though, I
think:

  1. Allows books to explictly depend on files in the docs repo so they
    are rebuilt when those files are changed.
  2. Create attributes for the "root" of each repository. This should make
    a lot of the ../../../../ paths unneeded.

So the second feature allows you to write includes like:

include::{elasticsearch-root}/docs/reference/glossary.asciidoc[]

instead of:

include::{docdir}/../../../../elasticsearch/docs/reference/glossary.asciidoc[]

The first feature combined with the second feature lets you write this
to include the shared files:

include::{docs-root}/shared/versions/stack/{source_branch}.asciidoc[]
include::{docs-root}/shared/attributes.asciidoc[]

instead of:

include::{asciidoc-dir}/../../shared/versions/stack/{source_branch}.asciidoc[]
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]

Which is nice. In addition, the first feature lets you write:

              -
                repo:   docs
                path:   shared/attributes.asciidoc
              -
                repo:   docs
                path:   shared/versions/stack/{version}.asciidoc

in conf.yaml to cause a book to be rebuilt if either:

  • attributes.asciidoc changes
  • shared/versions/stack/master.asciidoc changes. Assuming we're
    building the master branch of the book. It'll be 7.x.asciidoc if we're
    building 7.x, etc.

You can also declare a dependency on
shared/versions/stack/current.asciidoc and we'll cause a rebuild if
either current.asciidoc changes to point to a new file or the file
that it points to changes.

This adds two features that are sort of interlinked in their
implementation but not so much in their use. We want them both though, I
think:

1. Allows books to explictly depend on files in the docs repo so they
are rebuilt when those files are changed.
2. Create attributes for the "root" of each repository. This should make
a lot of the `../../../../` paths unneeded.

So the second feature allows you to write includes like:
```
include::{elasticsearch-root}/docs/reference/glossary.asciidoc[]
```

instead of:
```
include::{docdir}/../../../../elasticsearch/docs/reference/glossary.asciidoc[]
```

The first feature combined with the second feature lets you write this
to include the shared files:
```
include::{docs-root}/shared/versions/stack/{source_branch}.asciidoc[]
include::{docs-root}/shared/attributes.asciidoc[]
```

instead of:
```
include::{asciidoc-dir}/../../shared/versions/stack/{source_branch}.asciidoc[]
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
```

Which is nice. In addition, the first feature lets you write:
```
              -
                repo:   docs
                path:   shared/attributes.asciidoc
              -
                repo:   docs
                path:   shared/versions/stack/{version}.asciidoc
```

in `conf.yaml` to cause a book to be rebuilt if either:
* `attributes.asciidoc` changes
* `shared/versions/stack/master.asciidoc` changes. Assuming we're
building the master branch of the book. It'll be `7.x.asciidoc` if we're
building `7.x`, etc.

You can also declare a dependency on
`shared/versions/stack/current.asciidoc` and we'll cause a rebuild if
either `current.asciidoc` changes to point to a new file *or* the file
that it points to changes.
@nik9000 nik9000 requested a review from olksdr October 3, 2019 20:39
@nik9000
Copy link
Member Author

nik9000 commented Oct 3, 2019

@olksdr, I'm going to try and work through the last NOCOMMITs this afternoon. But I figure because this one is all OO-perl you're the best reviewer we have for it. There is a fair bit of ruby too but I think it is pretty uncontroversial stuff.

@nik9000
Copy link
Member Author

nik9000 commented Oct 4, 2019

The error is real. I'll get to it in the morning. Instead of checking the NOCOMMIT I did #1252. It almost cuts the time to run the tests in half.

@nik9000
Copy link
Member Author

nik9000 commented Oct 4, 2019

@lcawl, I think you should also have a look at this one, at last the README changes and the description.

@nik9000
Copy link
Member Author

nik9000 commented Oct 4, 2019

OK @olksdr, I think this is ready for you when you have time.

Copy link
Contributor

@olksdr olksdr left a comment

Choose a reason for hiding this comment

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

Left few comments and questions but otherwise everything LGTM :shipit:

@@ -531,7 +555,7 @@ sub init_target_repo {
my ( $repos_dir, $temp_dir, $reference_dir ) = @_;

my $target_repo = ES::TargetRepo->new(
dir => $repos_dir,
git_dir => $repos_dir->subdir('target_repo.git'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Thins name target_repo.git is hardcoded. Can it be either supplied into the init_target_repo sub or maybe better randomly generated ?

maybe something like

my $repo_name = sub { join"", @_[ map{ rand @_ } 1 .. shift ] }->(10, "a".."z") . ".git";
# $repo_name should contain something like "cbhbprlxye.git"

because I kind of never trust those hard coded names which can lead to some strange race conditions in the future if you want to run things in parallel

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 this case we really prefer to keep this in a stable place because it prevents us from having to pull as much.

Long before I got to it build_docs --all sacrificed being run in parallel for less git traffic. For the most part we don't want to run it in parallel anyway because its job is to commit to a particular repository.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Thanks for the explanation! Then it doesn't really matter 😄

@@ -34,7 +32,7 @@ sub new {

return bless {
name => $name,
git_dir => $dir->subdir("$name.git"),
git_dir => $args{git_dir},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to check that git_dir is definitely provided (the same like with name and url)?

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 haven't found that to be too useful, but sure!

keep_hash => 0,
);
$self->{dir} = $dir;
return $self;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you still need to bless the instance before returning it. Something like

return bless $self, $class;

But can be that it gets blessed from the parent

Copy link
Member Author

Choose a reason for hiding this comment

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

The parent blesses it, yeah.

lib/ES/Repo.pm Outdated
"Remote branch <origin/$branch> doesn't exist in repo "
. $self->name);
}
my $new_info = $new;
$new_info .= '|asciidoctor' if $asciidoctor;
say "ASDFADF " . $self->{name} . " $branch $path $old_info -> $new_info";
Copy link
Contributor

Choose a reason for hiding this comment

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

debug say?

Copy link
Member Author

Choose a reason for hiding this comment

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

++

@nik9000
Copy link
Member Author

nik9000 commented Oct 4, 2019

Let's get this in!

Thanks @olksdr!

@nik9000 nik9000 merged commit b3fd445 into elastic:master Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants