Skip to content

Commit dd6232b

Browse files
authored
Force --target_repo with --all (#583)
Require `--target_repo` when running with `--all`, effectively forcing folks to build the docs into a separate repo, just like jenkins.
1 parent 2a8ff0e commit dd6232b

File tree

1 file changed

+35
-43
lines changed

1 file changed

+35
-43
lines changed

build_docs.pl

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ sub build_local_pdf {
236236
#===================================
237237
sub build_all {
238238
#===================================
239+
die "--target_repo is required with --all" unless ( $Opts->{target_repo} );
240+
239241
unless ( $Opts->{rely_on_ssh_auth} ) {
240242
say "Checking GitHub username and password (or auth token for multi-factor auth)";
241243

@@ -247,11 +249,7 @@ sub build_all {
247249

248250
my $build_dir = $Conf->{paths}{build}
249251
or die "Missing <paths.build> in config";
250-
if ( $target_repo ) {
251-
$build_dir = dir("$target_repo_checkout/$build_dir");
252-
} else {
253-
$build_dir = dir($build_dir);
254-
}
252+
$build_dir = dir("$target_repo_checkout/$build_dir");
255253
$build_dir->mkpath;
256254

257255
my $contents = $Conf->{contents}
@@ -475,36 +473,32 @@ sub init_repos {
475473
die "Missing reference directory $reference_dir" unless -e $reference_dir;
476474
}
477475

478-
my $target_repo = 0;
479-
my $target_repo_checkout = 0;
480-
if ( $Opts->{target_repo} ) {
481-
# If we have a target repo check it out before the other repos so that
482-
# we can use the tracker file in that repo.
483-
$target_repo = ES::Repo->new(
484-
name => 'target_repo',
485-
dir => $repos_dir,
486-
user => $Opts->{user},
487-
url => $Opts->{target_repo},
488-
reference => $reference_dir,
489-
# intentionally not passing the tracker because we don't want to use it
490-
);
491-
delete $child_dirs{ $target_repo->git_dir->absolute };
492-
$target_repo_checkout = "$temp_dir/target_repo";
493-
$tracker_path = "$target_repo_checkout/$tracker_path";
494-
eval {
495-
$target_repo->update_from_remote();
496-
say " - Checking out: target_repo";
497-
$target_repo->checkout_to($target_repo_checkout);
498-
1;
499-
} or do {
500-
# If creds are invalid, explicitly reject them to try to clear the cache
501-
my $error = $@;
502-
if ( $error =~ /Invalid username or password/ ) {
503-
revoke_github_creds();
504-
}
505-
die $error;
506-
};
507-
}
476+
# Check out the target repo before the other repos so that
477+
# we can use the tracker file that it contains.
478+
my $target_repo = ES::Repo->new(
479+
name => 'target_repo',
480+
dir => $repos_dir,
481+
user => $Opts->{user},
482+
url => $Opts->{target_repo},
483+
reference => $reference_dir,
484+
# intentionally not passing the tracker because we don't want to use it
485+
);
486+
delete $child_dirs{ $target_repo->git_dir->absolute };
487+
my $target_repo_checkout = "$temp_dir/target_repo";
488+
$tracker_path = "$target_repo_checkout/$tracker_path";
489+
eval {
490+
$target_repo->update_from_remote();
491+
say " - Checking out: target_repo";
492+
$target_repo->checkout_to($target_repo_checkout);
493+
1;
494+
} or do {
495+
# If creds are invalid, explicitly reject them to try to clear the cache
496+
my $error = $@;
497+
if ( $error =~ /Invalid username or password/ ) {
498+
revoke_github_creds();
499+
}
500+
die $error;
501+
};
508502

509503
# check out all remaining repos in parallel
510504
my $tracker = ES::BranchTracker->new( file($tracker_path), @repo_names );
@@ -557,8 +551,8 @@ sub push_changes {
557551
#===================================
558552
my ($build_dir, $target_repo, $target_repo_checkout) = @_;
559553

560-
local $ENV{GIT_WORK_TREE} = $target_repo_checkout if $target_repo;
561-
local $ENV{GIT_DIR} = $ENV{GIT_WORK_TREE} . '/.git' if $target_repo;
554+
local $ENV{GIT_WORK_TREE} = $target_repo_checkout;
555+
local $ENV{GIT_DIR} = $ENV{GIT_WORK_TREE} . '/.git';
562556

563557
say 'Building revision.txt';
564558
$build_dir->file('revision.txt')
@@ -581,10 +575,8 @@ sub push_changes {
581575
} || '';
582576

583577
if ( sha_for('HEAD') ne $remote_sha ) {
584-
if ( $target_repo_checkout ) {
585-
say "Pushing changes to bare repo";
586-
run qw(git push origin HEAD );
587-
}
578+
say "Pushing changes to bare repo";
579+
run qw(git push origin HEAD );
588580
local $ENV{GIT_DIR} = $target_repo->git_dir if $target_repo;
589581
say "Pushing changes";
590582
run qw(git push origin HEAD );
@@ -804,12 +796,12 @@ sub usage {
804796
805797
Build docs from all repos in conf.yaml:
806798
807-
$0 --all [opts]
799+
$0 --all --target_repo <target> [opts]
808800
809801
Opts:
802+
--target_repo Repository to which to commit docs
810803
--push Commit the updated docs and push to origin
811804
--user Specify which GitHub user to use, if not your own
812-
--target_repo Repository to which to commit docs
813805
--reference Directory of `--mirror` clones to use as a local cache
814806
--rely_on_ssh_auth
815807
Skip the git auth check and translate configured repos into ssh

0 commit comments

Comments
 (0)