Fix PDF generation, exit code from make and parallelization#1002
Fix PDF generation, exit code from make and parallelization#1002lzap merged 2 commits intotheforeman:masterfrom
Conversation
f0e5b3c to
a5ce20e
Compare
14769b7 to
34396e3
Compare
Signed-off-by: Lukas Zapletal <lzap+git@redhat.com>
|
So added Anyway, my main goal was to fix how exit codes are handled and also PDFs were not generating at all. |
| github.repository_owner == 'theforeman' && | ||
| (github.ref == 'refs/heads/master' || | ||
| startsWith(github.ref, 'refs/heads/2.') || | ||
| startsWith(github.ref, 'refs/heads/3.')) |
There was a problem hiding this comment.
I moved this down, we now build one PDF version for PR CI and all for deploy commits.
| gem 'asciidoctor' | ||
| gem 'asciidoctor-pdf' | ||
| # missing dependency for asciidoctor-pdf | ||
| gem 'matrix' |
There was a problem hiding this comment.
This was causing Ruby to fail.
| clean: | ||
| @for DIR in $(SUBDIRS) ; do \ | ||
| $(MAKE) -s --directory="$$DIR" clean ; \ | ||
| done |
There was a problem hiding this comment.
This is completely simplified, it now properly calls make so recursive option does work.
| $(MAKE) --directory="$$DIR" clean ; \ | ||
| done | ||
| serve: | ||
| python -m http.server --directory ./build 8813 |
There was a problem hiding this comment.
The same target is in the common Makefile, I use this for testing.
| $(DEST_DIR)/$(BUILD).css: $(BUILD_DIR)/default.css | ||
| cp $< $@ | ||
| $(DEST_DIR)/$(BUILD).css: $(CSS_SOURCES) | ||
| bundle exec sass --cache-location $(DEST_DIR)/sass-cache --style $(CSS_STYLE) -I $(COMMON_DIR)/css $(COMMON_DIR)/css/default.scss $@ |
There was a problem hiding this comment.
Because sass command is a bit slow, previously it built into a common BUILD_DIR just once and other guides could simply copy the generated file quickly over to the destination. With parallel option this is no longer possible (I was hitting problems). So now sass needs to be executed for each guide separately, which is a bit slower. I implemented cache option, but that does not speeds things up on CI (where we start from a clean state anyway). Later on, we can migrate to Dart-SCSS.
| cp $? $(IMAGES_DIR)/ | ||
| pushd "$(IMAGES_DIR)" >/dev/null && for IMG in *.*; do ln -fs ../../images/$$IMG ../common/images/$$IMG; done && popd >/dev/null | ||
| cp -lrf $? $(IMAGES_DIR) | ||
| @touch $(IMAGES_TS) |
There was a problem hiding this comment.
This was dodgy, now images are properly copied (if they are new).
|
|
||
| $(DEST_PDF): $(SOURCES) $(IMAGES) $(DEPENDENCIES) | ||
| bundle exec asciidoctor-pdf -a build=$(BUILD) -d book --trace -o $@ $< 2>&1 | tee $@.log | ||
| bundle exec asciidoctor-pdf -a build=$(BUILD) -a imagesdir=$(IMAGES_DIR) -d book --trace -o $@ $< 2>&1 | tee $@.log |
There was a problem hiding this comment.
This was another issue with PDF generation - it could not find images in the correct directory. This fixes it.
| @@ -1,5 +1,5 @@ | |||
| include::common/attributes.adoc[] | |||
| :imagesdir: common/images | |||
| :imagesdir: images | |||
There was a problem hiding this comment.
This also consolidates where images should be find - they are always copied by make into the BUILD_DIR/images so no longer we will confuse common and non-common images. They are all copied to the same destination, of course locals overriding common.
So it turns out we have several issues.
Asciidoctor PDF now has a missing dependency "matrix". Without this gem, PDF generation simply fails, probably a bug usptream.
Second problem actually hid the first one - I added
asciidoctor ... | tee LOGFILE; grep LOGFILEto search for warnings which were never returned via exit code by asciidoctor, but I haven't realized that the pipe always returns zero exit code so even when HTML/PDF generation was broken (we had brokens links), makefile was still returning zero.After I fixed the tee problem, a third appeared - recursive make implementation did not care about return codes from the submakes at all, therefore when targets "all-html" or "all-pdf" were called, it always returned zero even if we had issues (warnings via the grep command).
Finally, I am making small improvement - for PR CI runs, let's simply build just one PDF to speed things up just to see if it actually builds. For deployments, let's build all of them, this creates a huge ZIP file and takes much longer. I think this is a good solution, previously we were building no PDFs for PR CI runs.
The root cause for PDF generation failing was because I was giving it the wrong images directory. I am going to fix all problems in separate commits. On top of that, since I am looking into this, I reimplemented the parallel make after reading GNU Makefile manual now in a proper way so it is
-jfriendly. Now we can use it on CI to even further speedups builds, for example PDF generation on my Intel NUC 8thgen:For parallelization, I had to drop the clunky images symlinking, now we use simply
cpto copy images over to the destination dir for each guide. I actually have a hard-link option to make it even faster. I also had to solve the common/images vs images/ directories problem which I run into when I was working on #977. We used to have images/ subdirectory for some guides, now we have it for all of them and images are copied from both directories into a single one.