Skip to content

Commit 2f31da5

Browse files
committed
Add --single-page option to only build the single page version
Part of #232. This also fixes an issue where the Docker build would always used the cached Docker container for Wattsi, so updating $WATTSI_LATEST would cause any further Docker builds to warn that Wattsi was out of date. Now it uses the one based on the $WATTSI_LATEST variable.
1 parent 18bdae0 commit 2f31da5

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
ARG WATTSI_VERSION
2+
FROM whatwg/wattsi:${WATTSI_VERSION} as wattsi-stage
3+
14
FROM debian:stable-slim
25
RUN apt-get update && \
36
apt-get install -y ca-certificates curl git unzip python3 python3-pip && \
47
rm -rf /var/lib/apt/lists/*
58

6-
COPY --from=whatwg/wattsi:latest /whatwg/wattsi/bin/wattsi /bin/wattsi
9+
COPY --from=wattsi-stage /whatwg/wattsi/bin/wattsi /bin/wattsi
710

811
RUN pip3 install bs-highlighter
912

build.sh

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ DIR=$(pwd)
1010
# The latest required version of Wattsi. Update this and the fallback in
1111
# https://github.com/whatwg/wattsi/blob/master/src/build.sh if you change how ./build.sh invokes
1212
# Wattsi.
13-
WATTSI_LATEST=90
13+
WATTSI_LATEST=107
1414

1515
# Shared state variables throughout this script
1616
LOCAL_WATTSI=true
1717
DO_UPDATE=true
1818
DO_LINT=true
1919
DO_HIGHLIGHT=true
20+
SINGLE_PAGE_ONLY=false
2021
USE_DOCKER=false
2122
VERBOSE=false
2223
QUIET=false
@@ -134,6 +135,7 @@ function processCommandLineArgs {
134135
echo " -n|--no-update Don't update before building; just build."
135136
echo " -l|--no-lint Don't lint before building; just build."
136137
echo " -h|--no-highlight Don't syntax-highlight the output."
138+
echo " -p|--single-page Only build the single-page variant of the spec."
137139
echo " -q|--quiet Don't emit any messages except errors/warnings."
138140
echo " -v|--verbose Show verbose output from every build step."
139141
exit 0
@@ -147,6 +149,9 @@ function processCommandLineArgs {
147149
-h|--no-highlight)
148150
DO_HIGHLIGHT=false
149151
;;
152+
-p|--single-page)
153+
SINGLE_PAGE_ONLY=true
154+
;;
150155
-d|--docker)
151156
USE_DOCKER=true
152157
;;
@@ -427,7 +432,7 @@ function relativePath {
427432
# Arguments: none
428433
# Output: A web server with the build output will be running inside the Docker container
429434
function doDockerBuild {
430-
DOCKER_BUILD_ARGS=( --tag whatwg-html )
435+
DOCKER_BUILD_ARGS=( --tag whatwg-html --build-arg "WATTSI_VERSION=$WATTSI_LATEST" )
431436
$QUIET && DOCKER_BUILD_ARGS+=( --quiet )
432437

433438
docker build "${DOCKER_BUILD_ARGS[@]}" .
@@ -440,6 +445,7 @@ function doDockerBuild {
440445
$DO_UPDATE || DOCKER_RUN_ARGS+=( --no-update )
441446
$DO_LINT || DOCKER_RUN_ARGS+=( --no-lint )
442447
$DO_HIGHLIGHT || DOCKER_RUN_ARGS+=( --no-highlight )
448+
$SINGLE_PAGE_ONLY && DOCKER_RUN_ARGS+=( --single-page )
443449
$SERVE && DOCKER_RUN_ARGS+=( --serve )
444450

445451
# Pass in the html-build SHA (since there's no .git directory inside the container)
@@ -555,17 +561,22 @@ function processSource {
555561
# Singlepage HTML
556562
mv "$HTML_TEMP/wattsi-output/index-html" "$HTML_OUTPUT/index.html"
557563

558-
# Singlepage Commit Snapshot
559-
COMMIT_DIR="$HTML_OUTPUT/commit-snapshots/$HTML_SHA"
560-
mkdir -p "$COMMIT_DIR"
561-
mv "$HTML_TEMP/wattsi-output/index-snap" "$COMMIT_DIR/index.html"
564+
if [[ $SINGLE_PAGE_ONLY == "false" ]]; then
565+
# Singlepage Commit Snapshot
566+
COMMIT_DIR="$HTML_OUTPUT/commit-snapshots/$HTML_SHA"
567+
mkdir -p "$COMMIT_DIR"
568+
mv "$HTML_TEMP/wattsi-output/index-snap" "$COMMIT_DIR/index.html"
569+
570+
# Multipage HTML and Dev Edition
571+
mv "$HTML_TEMP/wattsi-output/multipage-html" "$HTML_OUTPUT/multipage"
572+
mv "$HTML_TEMP/wattsi-output/multipage-dev" "$HTML_OUTPUT/dev"
573+
574+
cp -pR "$HTML_SOURCE/dev" "$HTML_OUTPUT"
575+
fi
562576

563577
cp -p entities/out/entities.json "$HTML_OUTPUT"
564578
cp -p "$HTML_TEMP/wattsi-output/xrefs.json" "$HTML_OUTPUT"
565579

566-
# Multipage HTML and Dev Edition
567-
mv "$HTML_TEMP/wattsi-output/multipage-html" "$HTML_OUTPUT/multipage"
568-
mv "$HTML_TEMP/wattsi-output/multipage-dev" "$HTML_OUTPUT/dev"
569580
clearDir "$HTML_TEMP"
570581

571582
echo "User-agent: *
@@ -578,7 +589,6 @@ Disallow: /review-drafts/" > "$HTML_OUTPUT/robots.txt"
578589
cp -pR "$HTML_SOURCE/fonts" "$HTML_OUTPUT"
579590
cp -pR "$HTML_SOURCE/images" "$HTML_OUTPUT"
580591
cp -pR "$HTML_SOURCE/demos" "$HTML_OUTPUT"
581-
cp -pR "$HTML_SOURCE/dev" "$HTML_OUTPUT"
582592
else
583593
# Singlepage Review Draft
584594
YEARMONTH=$(basename "$SOURCE_LOCATION" .wattsi)
@@ -621,9 +631,12 @@ function runWattsi {
621631

622632
if [[ "$LOCAL_WATTSI" == "true" ]]; then
623633
WATTSI_ARGS=()
624-
if $QUIET; then
634+
if [[ "$QUIET" == "true" ]]; then
625635
WATTSI_ARGS+=( --quiet )
626636
fi
637+
if [[ "$SINGLE_PAGE_ONLY" == "true" ]]; then
638+
WATTSI_ARGS+=( --single-page-only )
639+
fi
627640
WATTSI_ARGS+=( "$1" "$HTML_SHA" "$2" "$BUILD_TYPE" \
628641
"$HTML_CACHE/caniuse.json" \
629642
"$HTML_CACHE/mdn-spec-links-html.json" )
@@ -637,17 +650,26 @@ function runWattsi {
637650
$QUIET || echo
638651
$QUIET || echo "Local wattsi or pip3 are not present; trying the build server..."
639652

640-
CURL_ARGS=( https://build.whatwg.org/wattsi \
653+
CURL_URL="https://build.whatwg.org/wattsi"
654+
if [[ "$QUIET" == "true" && "$SINGLE_PAGE_ONLY" == "true" ]]; then
655+
CURL_URL="$CURL_URL?quiet&single-page-only"
656+
elif [[ "$QUIET" == "true" ]]; then
657+
CURL_URL="$CURL_URL?quiet"
658+
elif [[ "$SINGLE_PAGE_ONLY" == "true" ]]; then
659+
CURL_URL="$CURL_URL?single-page-only"
660+
fi
661+
662+
CURL_ARGS=( "$CURL_URL" \
641663
--form "source=@$1" \
642664
--form "sha=$HTML_SHA" \
643665
--form "build=$BUILD_TYPE" \
644666
--form "caniuse=@$HTML_CACHE/caniuse.json" \
645667
--form "mdn=@$HTML_CACHE/mdn-spec-links-html.json" \
646668
--dump-header "$HTML_TEMP/wattsi-headers.txt" \
647669
--output "$HTML_TEMP/wattsi-output.zip" )
648-
if $VERBOSE; then
670+
if [[ "$VERBOSE" == "true" ]]; then
649671
CURL_ARGS+=( --verbose )
650-
elif $QUIET; then
672+
elif [[ "$QUIET" == "true" ]]; then
651673
CURL_ARGS+=( --silent )
652674
fi
653675
curl "${CURL_ARGS[@]}"

0 commit comments

Comments
 (0)