diff --git a/.travis.yml b/.travis.yml index 623d8b984908..3ece77a236cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ version: ~> 1.0 # needed for imports - import: scala/scala-dev:travis/default.yml +dist: bionic # for generating spec PDF; see #7432 + language: scala stages: @@ -105,10 +106,19 @@ jobs: - gem install bundler - bundler --version - bundle install + # cribbed from https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/master/.travis.yml + - sudo apt-get update + - sudo apt-get install -y build-essential xorg xfonts-75dpi libpng16-16 libssl1.1 + - wget --quiet "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb" + - sudo dpkg -i "wkhtmltox_0.12.6-1.bionic_amd64.deb" + - rm "wkhtmltox_0.12.6-1.bionic_amd64.deb" script: - set -e - (cd admin && ./init.sh) - bundle exec jekyll build -s spec/ -d build/spec + - export JEKYLL_ENV=spec-pdf + - bundle exec jekyll build -s spec/ -d build/spec-pdf + - ./scripts/generate-spec-pdf.sh after_success: - ./scripts/travis-publish-spec.sh diff --git a/scripts/generate-spec-pdf.sh b/scripts/generate-spec-pdf.sh old mode 100644 new mode 100755 index 38f94ac1b24f..c49d0d39d1a6 --- a/scripts/generate-spec-pdf.sh +++ b/scripts/generate-spec-pdf.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +set -e +set -v + # NOTES: # "toc" -> treated just like another page, its location can be changed # "--window-status loaded" -> when window.status is set to "loaded", wkhtmltopdf knows js is loaded @@ -8,15 +11,29 @@ THIS_SCRIPT_DIR=$(dirname $0) ROOT_DIR=$THIS_SCRIPT_DIR/.. SPEC_SRC_DIR=$ROOT_DIR/spec SPEC_BUILD_DIR=$ROOT_DIR/build/spec +SPEC_PDF_BUILD_DIR=$ROOT_DIR/build/spec-pdf +PDF=$SPEC_BUILD_DIR/spec.pdf + +mkdir -p $SPEC_PDF_BUILD_DIR + -WKHTML_OPTS='--print-media-type --window-status loaded --footer-center [page] --javascript-delay 1000 --footer-font-name "Luxi Sans"' +WKHTML_OPTS='--print-media-type --window-status loaded --javascript-delay 1000 --load-error-handling ignore --enable-local-file-access --footer-center [page] --footer-font-name "Luxi Sans"' WKHTML_TOC="toc --xsl-style-sheet $SPEC_SRC_DIR/spec-toc.xslt" -# exclude index.html, prepend SPEC_BUILD_DIR path -HTML_FILES=$(ls $SPEC_BUILD_DIR -I 'index.html' | grep '\.html$' | while read line; do echo "$SPEC_BUILD_DIR/$line"; done) +# exclude index.html, prepend SPEC_PDF_BUILD_DIR path +HTML_FILES=$(ls $SPEC_PDF_BUILD_DIR | grep -vx 'index.html' | grep '\.html$' | while read line; do echo "$SPEC_PDF_BUILD_DIR/$line"; done) -echo "Making Spec.pdf with HTML files: " -echo $SPEC_BUILD_DIR/index.html $HTML_FILES +echo "Making spec.pdf with HTML files: " +echo $SPEC_PDF_BUILD_DIR/index.html $HTML_FILES # first goes index.html, then TOC, then rest -wkhtmltopdf $WKHTML_OPTS $SPEC_BUILD_DIR/index.html $WKHTML_TOC $HTML_FILES $SPEC_BUILD_DIR/Spec.pdf \ No newline at end of file +rm -f $PDF +wkhtmltopdf $WKHTML_OPTS $SPEC_PDF_BUILD_DIR/index.html $WKHTML_TOC $HTML_FILES $PDF || true + +# the '|| true' thing is because we get: +# Error: Failed to load http:/, with network status code 3 and http status code 0 - Host not found +# Warning: Failed loading page http: (ignored) +# as long we have `--load-error-handling ignore` we still get a PDF, but we also get a nonzero exit code + +# fail if we didn't get a PDF file out +if [ ! -f $PDF ] ; then exit 1 ; fi diff --git a/spec/_layouts/default.yml b/spec/_layouts/default.yml index 85dd08ac7e01..1de9b89d1dba 100644 --- a/spec/_layouts/default.yml +++ b/spec/_layouts/default.yml @@ -8,8 +8,7 @@ - + @@ -44,6 +43,7 @@ {{ content }} + diff --git a/spec/public/scripts/main.js b/spec/public/scripts/main.js index 51625189f4bf..9ade9c770f1e 100644 --- a/spec/public/scripts/main.js +++ b/spec/public/scripts/main.js @@ -27,16 +27,19 @@ function heading(i, heading, $heading) { } } -$('#toc').toc( - { - 'selectors': 'h1,h2,h3', - 'smoothScrolling': false, - 'chapter': currentChapter(), - 'headerLevel': 1, - 'headerCounts': [-1, currentChapter() - 1, 1, 1], - 'headerText': heading - } -); +// ignore when using wkhtmltopdf, or it won't work... +if(window.jekyllEnv !== 'spec-pdf') { + $('#toc').toc( + { + 'selectors': 'h1,h2,h3', + 'smoothScrolling': false, + 'chapter': currentChapter(), + 'headerLevel': 1, + 'headerCounts': [-1, currentChapter() - 1, 1, 1], + 'headerText': heading + } + ); +} // no language auto-detect so that EBNF isn't detected as scala hljs.configure({