-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpublish
More file actions
executable file
·210 lines (143 loc) · 4.32 KB
/
publish
File metadata and controls
executable file
·210 lines (143 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/perl
##############################################################################
#
# Publish latest version to GitHub pages site.
#
# Note: To generate the HTML locally and proofread the changes, just use:
#
# make html
#
# Use --help option for more details
#
use 5.010;
use strict;
use warnings;
use autodie;
use Pod::Usage;
use Getopt::Long qw(GetOptions);
use POSIX qw(strftime);
$| = 1; # turn off output buffering for prompt
my $generated_dir = 'build/html';
my $target_dir = '../perl-libxml-by-example-pages';
my(%opt);
if(!GetOptions(\%opt, 'help|?', 'message|m=s', 'dryrun|dry-run')) {
pod2usage(-exitval => 1, -verbose => 0);
}
pod2usage(-exitstatus => 0, -verbose => 2) if $opt{help};
my $message = commit_message();
check_uncommitted();
build_all();
publish_to_gh_pages($message);
exit;
sub commit_message {
if(my $message = $opt{message}) {
my $log = `git log --pretty=oneline -1`;
my($commit_id) = $log =~ m{\A(\w{12})};
return "$message\n\n Source commit: $commit_id";
}
elsif($opt{dryrun}) {
return;
}
else {
say "You must specify a commit message with -m";
say "Recent commits:";
my $mtime = (stat("$target_dir/.git/index"))[9];
$mtime = strftime('%F-%T', localtime($mtime));
my $log = `git log --pretty=format:'%h %s' \@{$mtime}..`;
if($log =~ /\S/) {
say $log;
}
else {
say "No changes in source repo";
}
exit 1;
}
}
sub check_uncommitted {
my $git_status = `git status -s`;
return unless $git_status =~ /\S/;
say "WARNING: Uncommitted changes ...\n\n$git_status";
print "Publish anyway? (y/N) ";
my $response = <STDIN>;
return if $response =~ /^y(es)?/i;
exit;
}
sub build_all {
system('make', 'html') == 0
or die "Failed to generate HTML from source\n";
local($ENV{SPHINXOPTS}) = '-a';
system('make', '-e', 'latexpdf') == 0
or die "Failed to generate PDF from source\n";
system(
'cp', 'build/latex/PerlXMLLibXMLbyExample.pdf',
'build/html/_downloads/'
) == 0
or die "Failed to copy PDF into _downloads\n";
local($ENV{SPHINXOPTS}) = '-a';
system('make', '-e', 'epub') == 0
or die "Failed to generate epub from source\n";
system(
'cp', 'build/epub/PerlXMLLibXMLbyExample.epub',
'build/html/_downloads/'
) == 0
or die "Failed to copy PDF into _downloads\n";
}
sub publish_to_gh_pages {
my($commit_message) = @_;
system(
'rsync', '-rav', '--checksum', '--delete',
'--exclude=.git',
'--exclude=.nojekyll',
'--exclude=.buildinfo',
'--exclude=.*.swp',
$generated_dir . '/',
$target_dir . '/',
) == 0 or die "Failed to sync files to gh-pages repo\n";
# Don't commit/push to GitHub pages if --dry-run was specified
if($opt{dryrun}) {
warn "Bailing out before publishing to GitHub pages due to --dry-run option\n";
return;
}
chdir($target_dir);
system('git', 'add', '--all') == 0
or die "Failed to add files to gh-pages repo\n";
system('git', 'commit', '-m', $commit_message) == 0
or die "Failed to commit changes to gh-pages repo\n";
system('git', 'push', 'origin') == 0
or die "Failed to push update to GitHub\n";
say "Site updated successfully";
}
__END__
=head1 NAME
publish - Push current version of Perl XML::LibXML by Example site to gh-pages
=head1 SYNOPSIS
publish -m <commit message>
Options:
-m <msg> set the commit message to be used
--dry-run do everything except commit and push to GitHub pages
-? detailed help message
=head1 DESCRIPTION
Generate and publish the current version of the "Perl XML::LibXML by Example"
documentation project to GitHub pages:
=over 4
=item *
check for uncommitted changes
=item *
regenerate HTML
=item *
rsync generated files to parallel checkout dir on gh-pages branch
=item *
add and commit all changes
=item *
push to GitHub
=back
=head1 OPTIONS
=over 4
=item B<< --message <msg> >> (alias: -m)
Set the text of the commit message to use on the gh-pages branch.
=item B<--dry-run>
Do everything except commit and push to GitHub pages.
=item B<--help> (alias: -?)
Display this documentation.
=back
=cut