@@ -25,6 +25,7 @@ check: \
25
25
keep_hash \
26
26
sub_dir \
27
27
keep_hash_and_sub_dir \
28
+ multi_branch \
28
29
open_all
29
30
30
31
.PHONY : style
@@ -170,6 +171,7 @@ keep_hash:
170
171
--target_repo $(TMP)/dest.git \
171
172
--conf $(TMP)/conf.yaml \
172
173
--keep_hash | tee $(TMP)/out
174
+ $(call GREP_V,'Test book',$(TMP)/out)
173
175
$(call GREP,'No changes to push',$(TMP)/out)
174
176
175
177
# We expact the same files as the minimal because we the changes that we
@@ -196,8 +198,10 @@ sub_dir:
196
198
/docs_build/build_docs.pl --in_standard_docker --all --push \
197
199
--target_repo $(TMP)/dest.git \
198
200
--conf $(TMP)/conf.yaml \
199
- --sub_dir source:master:$(TMP)/to_sub
200
-
201
+ --sub_dir source:master:$(TMP)/to_sub | tee $(TMP)/out
202
+ $(call GREP,'Test book: Building master...',$(TMP)/out)
203
+ $(call GREP,'Test book: Finished master',$(TMP)/out)
204
+ $(call GREP,'Test book: Copying master to current',$(TMP)/out)
201
205
$(call MINIMAL_ALL_EXPECTED_FILES,'local changes')
202
206
203
207
.PHONY : keep_hash_and_sub_dir
@@ -214,7 +218,11 @@ keep_hash_and_sub_dir:
214
218
sed 's|--tmp--|$(TMP)|' two_repos_conf.yaml > $(TMP)/conf.yaml
215
219
/docs_build/build_docs.pl --in_standard_docker --all --push \
216
220
--target_repo $(TMP)/dest.git \
217
- --conf $(TMP)/conf.yaml
221
+ --conf $(TMP)/conf.yaml | tee $(TMP)/out
222
+ $(call GREP,'Test book: Building master...',$(TMP)/out)
223
+ $(call GREP,'Test book: Finished master',$(TMP)/out)
224
+ $(call GREP,'Test book: Copying master to current',$(TMP)/out)
225
+ $(call GREP,'Pushing changes',$(TMP)/out)
218
226
219
227
# Move a "bad" file into source2 so we can be sure we're not picking it up
220
228
cp ../README.asciidoc $(TMP)/source2/index.asciidoc
@@ -225,8 +233,9 @@ keep_hash_and_sub_dir:
225
233
/docs_build/build_docs.pl --in_standard_docker --all --push \
226
234
--target_repo $(TMP)/dest.git \
227
235
--conf $(TMP)/conf.yaml \
228
- --keep_hash | tee /tmp/out
229
- $(call GREP,'No changes to push',/tmp/out)
236
+ --keep_hash | tee $(TMP)/out
237
+ $(call GREP_V,'Test book',$(TMP)/out)
238
+ $(call GREP,'No changes to push',$(TMP)/out)
230
239
231
240
# Setup the directory we'd like to substitute
232
241
mkdir -p $(TMP)/to_sub/docs
@@ -237,11 +246,84 @@ keep_hash_and_sub_dir:
237
246
--target_repo $(TMP)/dest.git \
238
247
--conf $(TMP)/conf.yaml \
239
248
--keep_hash --sub_dir source1:master:$(TMP)/to_sub | tee $(TMP)/out
249
+ $(call GREP,'Test book: Building master...',$(TMP)/out)
250
+ $(call GREP,'Test book: Finished master',$(TMP)/out)
251
+ $(call GREP,'Test book: Copying master to current',$(TMP)/out)
240
252
$(call GREP,'Pushing changes',$(TMP)/out)
241
253
242
254
git clone $(TMP)/dest.git $(TMP)/dest
243
255
$(call GREP,'extra extra extra',$(TMP)/dest/html/test/current/_chapter.html)
244
256
257
+ .PHONY : multi_branch
258
+ multi_branch :
259
+ # Tests for how we rebuild books with multiple branches
260
+
261
+ # When the book hasn't been built before we build all branches
262
+ rm -rf $(TMP)
263
+ $(call INIT_REPO_WITH_FILE,$(TMP)/source,minimal.asciidoc,docs/index.asciidoc)
264
+ cd $(TMP)/source && git checkout -b prev
265
+ git init --bare $(TMP)/dest.git
266
+
267
+ sed 's|--tmp--|$(TMP)|' multi_branch.yaml > $(TMP)/conf.yaml
268
+ /docs_build/build_docs.pl --in_standard_docker --all --push \
269
+ --target_repo $(TMP)/dest.git \
270
+ --conf $(TMP)/conf.yaml | tee $(TMP)/out
271
+ $(call GREP,'Test book: Building master...',$(TMP)/out)
272
+ $(call GREP,'Test book: Finished master',$(TMP)/out)
273
+ $(call GREP,'Test book: Building prev...',$(TMP)/out)
274
+ $(call GREP,'Test book: Finished prev',$(TMP)/out)
275
+ $(call GREP,'Test book: Copying master to current',$(TMP)/out)
276
+ $(call GREP,'Test book: Writing versions TOC',$(TMP)/out)
277
+ $(call GREP,'Pushing changes',$(TMP)/out)
278
+
279
+ git clone $(TMP)/dest.git $(TMP)/dest
280
+ # The main index links to the current version
281
+ $(call GREP,'<a class="ulink" href="test/current/index.html" target="_top">Test book \[master\]</a>',$(TMP)/dest/html/index.html)
282
+ $(call GREP,'<a class="ulink" href="test/index.html" target="_top">other versions</a>',$(TMP)/dest/html/index.html)
283
+ # And the book's index links to all versions
284
+ $(call GREP,'<a class="ulink" href="current/index.html" target="_top">Test book: master (current)</a>',$(TMP)/dest/html/test/index.html)
285
+ $(call GREP,'<a class="ulink" href="prev/index.html" target="_top">Test book: prev</a>',$(TMP)/dest/html/test/index.html)
286
+ # And all versions have been built
287
+ [ -s $(TMP)/dest/html/test/current/index.html ]
288
+ [ -s $(TMP)/dest/html/test/master/index.html ]
289
+ [ -s $(TMP)/dest/html/test/prev/index.html ]
290
+
291
+ # When one of the non-current branches has changed we rebuild it but do not
292
+ # copy the current branch
293
+ cd $(TMP)/source && \
294
+ git checkout prev && \
295
+ echo "changed" >> docs/index.asciidoc && \
296
+ git add . && \
297
+ git commit -m "change"
298
+ /docs_build/build_docs.pl --in_standard_docker --all --push \
299
+ --target_repo $(TMP)/dest.git \
300
+ --conf $(TMP)/conf.yaml | tee $(TMP)/out
301
+ $(call GREP_V,'Test book: Building master...',$(TMP)/out)
302
+ $(call GREP_V,'Test book: Finished master',$(TMP)/out)
303
+ $(call GREP,'Test book: Building prev...',$(TMP)/out)
304
+ $(call GREP,'Test book: Finished prev',$(TMP)/out)
305
+ $(call GREP_V,'Test book: Copying master to current',$(TMP)/out)
306
+ $(call GREP,'Test book: Writing versions TOC',$(TMP)/out)
307
+ $(call GREP,'Pushing changes',$(TMP)/out)
308
+
309
+ # When the current branch has changed we rebuild it and copy it to the
310
+ # current branch
311
+ cd $(TMP)/source && \
312
+ git checkout master && \
313
+ echo "changed" >> docs/index.asciidoc && \
314
+ git add . && \
315
+ git commit -m "change"
316
+ /docs_build/build_docs.pl --in_standard_docker --all --push \
317
+ --target_repo $(TMP)/dest.git \
318
+ --conf $(TMP)/conf.yaml | tee $(TMP)/out
319
+ $(call GREP,'Test book: Building master...',$(TMP)/out)
320
+ $(call GREP,'Test book: Finished master',$(TMP)/out)
321
+ $(call GREP_V,'Test book: Building prev...',$(TMP)/out)
322
+ $(call GREP_V,'Test book: Finished prev',$(TMP)/out)
323
+ $(call GREP,'Test book: Copying master to current',$(TMP)/out)
324
+ $(call GREP,'Test book: Writing versions TOC',$(TMP)/out)
325
+ $(call GREP,'Pushing changes',$(TMP)/out)
326
+
245
327
.PHONY : open_all
246
328
open_all :
247
329
# Test that `--all --open` starts nginx in a usable way.
@@ -259,21 +341,6 @@ open_all:
259
341
$(call GREP,'Location: http://localhost:8000/guide/en/elasticsearch/reference/current/setup.html',$(TMP ) /guide/rdir)
260
342
kill -QUIT $$(cat /run/nginx/nginx.pid )
261
343
262
- define GREP=
263
- # grep for a string in a file, outputting the whole file if there isn't
264
- # a match.
265
- [ -e $(2 ) ] || { \
266
- echo "can't find $(2 ) "; \
267
- ls $$(dirname $(2 ) ) ; \
268
- false; \
269
- }
270
- grep $(1 ) $(2 ) > /dev/null || { \
271
- echo "Couldn't find $(1 ) in $(2 ) :"; \
272
- cat $(2 ) ; \
273
- false; \
274
- }
275
- endef
276
-
277
344
define SETUP_MINIMAL_ALL=
278
345
# First build a repository to use as the source.
279
346
$(call INIT_REPO_WITH_FILE,$(TMP ) /source,minimal.asciidoc,index.asciidoc)
@@ -292,7 +359,11 @@ define BUILD_MINIMAL_ALL=
292
359
$(SETUP_MINIMAL_ALL )
293
360
/docs_build/build_docs.pl --in_standard_docker --all --push \
294
361
--target_repo $(TMP ) /dest.git \
295
- --conf $(TMP ) /conf.yaml
362
+ --conf $(TMP ) /conf.yaml | tee $(TMP ) /out
363
+ $(call GREP,'Test book: Building master...',$(TMP ) /out)
364
+ $(call GREP,'Test book: Finished master',$(TMP ) /out)
365
+ $(call GREP,'Test book: Copying master to current',$(TMP ) /out)
366
+ $(call GREP,'Test book: Writing redirect to current branch...',$(TMP ) /out)
296
367
endef
297
368
298
369
define MINIMAL_ALL_EXPECTED_FILES=
@@ -323,13 +394,28 @@ define GREP=
323
394
# grep for a string in a file, outputting the whole file if there isn't
324
395
# a match.
325
396
[ -e $(2 ) ] || { \
326
- echo "can't find $(2 ) "; \
397
+ echo "can't find \' $(2 ) \' "; \
327
398
ls $$(dirname $(2 ) ) ; \
328
399
false; \
329
400
}
330
- grep $(1 ) $(2 ) > /dev/null || { \
331
- echo "Couldn't" find $(1 ) in $(2 ) :; \
401
+ grep -q $(1 ) $(2 ) || { \
402
+ echo "Couldn't" find \' $(1 ) \' in \' $(2 ) \' :; \
332
403
cat $(2 ) ; \
333
404
false; \
334
405
}
335
406
endef
407
+
408
+ define GREP_V=
409
+ # grep for a string in a file, outputting the whole file if there *is*
410
+ # a match.
411
+ [ -e $(2 ) ] || { \
412
+ echo "can't find \'$(2 ) \'"; \
413
+ ls $$(dirname $(2 ) ) ; \
414
+ false; \
415
+ }
416
+ grep -qv $(1 ) $(2 ) || { \
417
+ echo Found \'$(1 ) \' in \'$(2 ) \':; \
418
+ cat $(2 ) ; \
419
+ false; \
420
+ }
421
+ endef
0 commit comments