@@ -25,6 +25,7 @@ check: \
2525 keep_hash \
2626 sub_dir \
2727 keep_hash_and_sub_dir \
28+ multi_branch \
2829 open_all
2930
3031.PHONY : style
@@ -170,6 +171,7 @@ keep_hash:
170171 --target_repo $(TMP)/dest.git \
171172 --conf $(TMP)/conf.yaml \
172173 --keep_hash | tee $(TMP)/out
174+ $(call GREP_V,'Test book',$(TMP)/out)
173175 $(call GREP,'No changes to push',$(TMP)/out)
174176
175177 # We expact the same files as the minimal because we the changes that we
@@ -196,8 +198,10 @@ sub_dir:
196198 /docs_build/build_docs.pl --in_standard_docker --all --push \
197199 --target_repo $(TMP)/dest.git \
198200 --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)
201205 $(call MINIMAL_ALL_EXPECTED_FILES,'local changes')
202206
203207.PHONY : keep_hash_and_sub_dir
@@ -214,7 +218,11 @@ keep_hash_and_sub_dir:
214218 sed 's|--tmp--|$(TMP)|' two_repos_conf.yaml > $(TMP)/conf.yaml
215219 /docs_build/build_docs.pl --in_standard_docker --all --push \
216220 --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)
218226
219227 # Move a "bad" file into source2 so we can be sure we're not picking it up
220228 cp ../README.asciidoc $(TMP)/source2/index.asciidoc
@@ -225,8 +233,9 @@ keep_hash_and_sub_dir:
225233 /docs_build/build_docs.pl --in_standard_docker --all --push \
226234 --target_repo $(TMP)/dest.git \
227235 --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)
230239
231240 # Setup the directory we'd like to substitute
232241 mkdir -p $(TMP)/to_sub/docs
@@ -237,11 +246,84 @@ keep_hash_and_sub_dir:
237246 --target_repo $(TMP)/dest.git \
238247 --conf $(TMP)/conf.yaml \
239248 --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)
240252 $(call GREP,'Pushing changes',$(TMP)/out)
241253
242254 git clone $(TMP)/dest.git $(TMP)/dest
243255 $(call GREP,'extra extra extra',$(TMP)/dest/html/test/current/_chapter.html)
244256
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+
245327.PHONY : open_all
246328open_all :
247329 # Test that `--all --open` starts nginx in a usable way.
@@ -259,21 +341,6 @@ open_all:
259341 $(call GREP,'Location: http://localhost:8000/guide/en/elasticsearch/reference/current/setup.html',$(TMP ) /guide/rdir)
260342 kill -QUIT $$(cat /run/nginx/nginx.pid )
261343
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-
277344define SETUP_MINIMAL_ALL=
278345 # First build a repository to use as the source.
279346 $(call INIT_REPO_WITH_FILE,$(TMP ) /source,minimal.asciidoc,index.asciidoc)
@@ -292,7 +359,11 @@ define BUILD_MINIMAL_ALL=
292359 $(SETUP_MINIMAL_ALL )
293360 /docs_build/build_docs.pl --in_standard_docker --all --push \
294361 --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)
296367endef
297368
298369define MINIMAL_ALL_EXPECTED_FILES=
@@ -323,13 +394,28 @@ define GREP=
323394 # grep for a string in a file, outputting the whole file if there isn't
324395 # a match.
325396 [ -e $(2 ) ] || { \
326- echo "can't find $(2 ) "; \
397+ echo "can't find \' $(2 ) \' "; \
327398 ls $$(dirname $(2 ) ) ; \
328399 false; \
329400 }
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 ) \' :; \
332403 cat $(2 ) ; \
333404 false; \
334405 }
335406endef
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