-
Notifications
You must be signed in to change notification settings - Fork 345
Support --target_branch #877
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ BEGIN | |
run $Opts | ||
build_chunked build_single build_pdf | ||
proc_man | ||
sha_for | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was unused. |
||
timestamp | ||
write_html_redirect | ||
write_nginx_redirects | ||
|
@@ -462,6 +461,7 @@ sub init_repos { | |
url => $Opts->{target_repo}, | ||
reference => $reference_dir, | ||
destination => dir( $target_repo_checkout ), | ||
branch => $Opts->{target_branch} || 'master', | ||
); | ||
delete $child_dirs{ $target_repo->git_dir->absolute }; | ||
$tracker_path = "$target_repo_checkout/$tracker_path"; | ||
|
@@ -555,30 +555,23 @@ sub push_changes { | |
$build_dir->file('revision.txt') | ||
->spew( iomode => '>:utf8', ES::Repo->all_repo_branches ); | ||
|
||
say 'Preparing commit'; | ||
run qw(git add -A); | ||
|
||
if ( run qw(git status -s --) ) { | ||
# Check if there are changes before committing and save that because if | ||
# there are changes we'll commit them. Once we've committed them checking | ||
# if there are changes will say "no" because there aren't changes | ||
# *any more*. Thus we build $has_changes and $should_push here and not | ||
# in the `if` statements below. | ||
my $has_changes = $target_repo->outstanding_changes; | ||
my $should_push = $has_changes || $target_repo->new_branch; | ||
if ( $has_changes ) { | ||
say 'Preparing commit'; | ||
build_sitemap($build_dir); | ||
run qw(git add -A); | ||
say "Commiting changes"; | ||
run qw(git commit -m), 'Updated docs'; | ||
$target_repo->commit; | ||
} | ||
|
||
my $remote_sha = eval { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fairly sure we don't need to check the upstream's sha like this. This seems like it is for catching local commits and pushing them upstream while you build the docs. That made more sense when the built docs were in the same repo as the docs code but at this point I don't think it is a thing we need. It should be safe enough to reason about whether or not we should push based on if we made changes that need to be pushed. |
||
my $remote = run qw(git rev-parse --symbolic-full-name @{u}); | ||
chomp $remote; | ||
return sha_for($remote); | ||
} || ''; | ||
|
||
if ( sha_for('HEAD') ne $remote_sha ) { | ||
say "Pushing changes to bare repo"; | ||
run qw(git push origin HEAD ); | ||
local $ENV{GIT_DIR} = $target_repo->git_dir if $target_repo; | ||
if ( $should_push ) { | ||
say "Pushing changes"; | ||
run qw(git push origin HEAD ); | ||
} | ||
else { | ||
$target_repo->push_changes; | ||
} else { | ||
say "No changes to push"; | ||
} | ||
} | ||
|
@@ -760,6 +753,7 @@ sub command_line_opts { | |
'toc', | ||
# Options only compatible with --all | ||
'all', | ||
'target_branch=s', | ||
'target_repo=s', | ||
'keep_hash', | ||
'linkcheckonly', | ||
|
@@ -820,6 +814,7 @@ sub usage { | |
--sub_dir Use a directory as a branch of some repo | ||
(eg --sub_dir elasticsearch:master:~/Code/elasticsearch) | ||
--target_repo Repository to which to commit docs | ||
--target_branch Branch to which to commit docs | ||
--user Specify which GitHub user to use, if not your own | ||
|
||
General Opts: | ||
|
@@ -868,6 +863,7 @@ sub check_opts { | |
die('--reference not compatible with --doc') if $Opts->{reference}; | ||
die('--skiplinkcheck not compatible with --doc') if $Opts->{skiplinkcheck}; | ||
die('--sub_dir not compatible with --doc') if $Opts->{sub_dir}; | ||
die('--target_branch not compatible with --doc') if $Opts->{target_branch}; | ||
die('--target_repo not compatible with --doc') if $Opts->{target_repo}; | ||
die('--user not compatible with --doc') if $Opts->{user}; | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,42 +4,50 @@ | |
# Assertions about when books are rebuilt based on changes in source | ||
# repositories or the book's configuration. | ||
RSpec.describe 'building all books' do | ||
class Config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to add this as a variable to |
||
attr_accessor :target_branch | ||
|
||
def initialize | ||
@target_branch = nil | ||
end | ||
end | ||
describe 'change detection' do | ||
def self.build_twice( | ||
before_first_build:, | ||
before_second_build: ->(src) {} | ||
before_second_build: | ||
) | ||
convert_before do |src, dest| | ||
config = Config.new | ||
# Allow the caller to customize the source. | ||
before_first_build.call(src) | ||
before_first_build.call(src, config) | ||
|
||
# Convert the first time. This should build the docs. | ||
dest.convert_all src.conf | ||
dest.convert_all src.conf, target_branch: config.target_branch | ||
|
||
# Take some action between the builds. | ||
before_second_build.call(src) | ||
before_second_build.call(src, config) | ||
|
||
# Convert the second time. | ||
dest.convert_all src.conf | ||
dest.convert_all src.conf, target_branch: config.target_branch | ||
|
||
# Checkout the files so we can assert about them. | ||
dest.checkout_conversion | ||
dest.checkout_conversion branch: config.target_branch | ||
end | ||
include_context 'build one book twice' | ||
end | ||
|
||
def self.build_one_book_out_of_one_repo_twice( | ||
before_first_build: ->(src) {}, | ||
before_second_build: ->(src) {} | ||
before_first_build: ->(src, config) {}, | ||
before_second_build: ->(src, config) {} | ||
) | ||
build_twice( | ||
before_first_build: lambda do |src| | ||
before_first_build: lambda do |src, config| | ||
repo = src.repo_with_index 'repo', 'Some text.' | ||
book = src.book 'Test' | ||
book.source repo, 'index.asciidoc' | ||
|
||
# Allow the caller to customize the source | ||
before_first_build.call(src) | ||
before_first_build.call src, config | ||
end, | ||
before_second_build: before_second_build | ||
) | ||
|
@@ -50,13 +58,15 @@ def self.build_one_book_out_of_two_repos_twice( | |
before_second_build: ->(src) {} | ||
) | ||
build_twice( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figure I don't need to support |
||
before_first_build: lambda do |src| | ||
before_first_build: lambda do |src, _config| | ||
src.simple_include | ||
|
||
# Allow the caller to customize the source | ||
before_first_build.call(src) | ||
before_first_build.call src | ||
end, | ||
before_second_build: before_second_build | ||
before_second_build: lambda do |src, _config| | ||
before_second_build.call src | ||
end | ||
) | ||
end | ||
|
||
|
@@ -100,25 +110,51 @@ def self.build_one_book_out_of_two_repos_twice( | |
build_one_book_out_of_one_repo_twice | ||
include_examples 'second build is noop' | ||
end | ||
|
||
context 'because there are unrelated changes source repo' do | ||
context 'even when there are unrelated changes source repo' do | ||
build_one_book_out_of_one_repo_twice( | ||
before_second_build: lambda do |src| | ||
before_second_build: lambda do |src, _config| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love that rubocop forces me to to |
||
repo = src.repo 'repo' | ||
repo.write 'garbage', 'junk' | ||
repo.commit 'adding junk' | ||
end | ||
) | ||
include_examples 'second build is noop' | ||
end | ||
context 'even when there is a target_branch' do | ||
build_one_book_out_of_one_repo_twice( | ||
before_first_build: lambda do |_src, config| | ||
config.target_branch = 'new_target' | ||
end | ||
) | ||
include_examples 'second build is noop' | ||
end | ||
context 'even when there is a new target branch' do | ||
# Adding a new target branch will cause us to fork it from the | ||
# master branch which so we won't have to rebuild the book *but* | ||
# we push anyway so the new target branch is available. | ||
build_one_book_out_of_one_repo_twice( | ||
before_second_build: lambda do |_src, config| | ||
config.target_branch = 'new_target' | ||
end | ||
) | ||
context 'the second build' do | ||
let(:out) { outputs[1] } | ||
it "doesn't print that it is building any books" do | ||
expect(out).not_to include(': Building ') | ||
end | ||
it "doesn't print that it is commiting changes" do | ||
expect(out).not_to include('Commiting changes') | ||
end | ||
it 'prints that it is pushing changes' do | ||
expect(out).to include('Pushing changes') | ||
end | ||
end | ||
end | ||
end | ||
context "when the second build isn't a noop" do | ||
let(:latest_revision) { 'changed text' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point more than half of the examples override this so it isn't worth keeping is as the default. |
||
let(:new_text) { 'New text.' } | ||
|
||
context 'because the source repo changes' do | ||
build_one_book_out_of_one_repo_twice( | ||
before_second_build: lambda do |src| | ||
before_second_build: lambda do |src, _config| | ||
repo = src.repo 'repo' | ||
repo.write 'index.asciidoc', <<~ASCIIDOC | ||
= Title | ||
|
@@ -130,35 +166,49 @@ def self.build_one_book_out_of_two_repos_twice( | |
repo.commit 'changed text' | ||
end | ||
) | ||
let(:latest_revision) { 'changed text' } | ||
let(:new_text) { 'New text.' } | ||
include_examples 'second build is not a noop' | ||
end | ||
context 'because the book changes from asciidoc to asciidoctor' do | ||
build_one_book_out_of_one_repo_twice( | ||
before_first_build: lambda do |src| | ||
before_first_build: lambda do |src, _config| | ||
book = src.book 'Test' | ||
book.asciidoctor = false | ||
end, | ||
before_second_build: lambda do |src| | ||
before_second_build: lambda do |src, _config| | ||
book = src.book 'Test' | ||
book.asciidoctor = true | ||
end | ||
) | ||
# We didn't change the revision.... | ||
let(:latest_revision) { 'init' } | ||
# And the text hasn't changed | ||
let(:new_text) { 'Some text.' } | ||
include_examples 'second build is not a noop' | ||
end | ||
context 'because the book changes from asciidoctor to asciidoc' do | ||
build_one_book_out_of_one_repo_twice( | ||
before_second_build: lambda do |src| | ||
before_second_build: lambda do |src, _config| | ||
book = src.book 'Test' | ||
book.asciidoctor = false | ||
end | ||
) | ||
# We didn't change the revision.... | ||
let(:latest_revision) { 'init' } | ||
# And the text hasn't changed | ||
let(:new_text) { 'Some text.' } | ||
include_examples 'second build is not a noop' | ||
end | ||
context 'because we remove the target_branch' do | ||
# Removing the target branch causes us to build into the *empty* | ||
# master branch. Being empty, there aren't any books in it to | ||
# consider "already built". | ||
build_one_book_out_of_one_repo_twice( | ||
before_first_build: lambda do |_src, config| | ||
config.target_branch = 'new_target' | ||
end, | ||
before_second_build: lambda do |_src, config| | ||
config.target_branch = nil # nil means don't override | ||
end | ||
) | ||
let(:latest_revision) { 'init' } | ||
let(:new_text) { 'Some text.' } | ||
include_examples 'second build is not a noop' | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The perl is at the top of this diff and at the bottom....