Bumping manifests a=b2g-bump
[gecko.git] / js / src / doc / publish.sh
blobfad0b27d94d534254fd85fabd3dd74fba01c3de5
1 #!/usr/bin/env bash
3 # Format js/src/doc documentation in SOURCEDIR, place formatted files in OUTPUTDIR,
4 # and post all changed pages to MDN using KEYID and SECRET to identify the poster.
5 # See js/src/doc/README.md for general usage information.
7 # Usage:
9 # ./publish.sh SOURCEDIR OUTPUTDIR KEYID SECRET
11 # Pages are tagged with the current Mercurial parent changeset ID.
13 set -eu
15 progname=$(basename $0)
16 doc=$(cd $(dirname $0); pwd)
17 lib=$doc/lib
19 sourcedir=$1
20 outputdir=$2
21 keyid=$3
22 secret=$4
24 $doc/format.sh --mdn "$sourcedir" "$outputdir"
26 config=$sourcedir/config.sh
28 watermark=$lib/extract-watermark.sh
30 # Fetch a URL, with caching disabled.
31 fetch() {
32 curl --silent -XGET "$1" \
33 -H"Cache-Control: no-cache, no-store, must-revalidate" \
34 -H"Pragma: no-cache" \
35 -H"Expires: 0"
38 source $lib/dummy-config.sh
40 markdown() {
41 INPUT_FILE=$1
42 URL=$BASE_URL$2
44 local formatted_file=$outputdir/${INPUT_FILE/md/html}
46 # Extract the watermark from the formatted file.
47 local local_watermark=$("$watermark" < "$formatted_file")
49 # Get the existing page, and extract its watermark, if any.
50 local public_watermark=$(fetch "$URL?raw" | "$watermark")
52 if [ "$local_watermark" != "$public_watermark" ]; then
53 echo "$progname: Updating: $URL" >&2
54 local status
55 status=$(curl --silent -X PUT -H"Content-Type: text/html" --upload-file "$formatted_file" -u "$keyid:$secret" "$URL")
56 case "$status" in
57 CREATED | RESET)
60 echo "$progname: Error posting $URL, from $config: $status" >&2
61 exit 1
63 esac
64 else
65 echo "$progname: Unchanged: $URL" >&2
69 # MDN can't currently update attached resources. But we can verify that the current
70 # published versions match what we have.
71 resource() {
72 local label=$1
73 local file=$sourcedir/$2
74 local url=$3
76 if cmp "$file" <(fetch "$url") > /dev/null; then
77 echo "$progname: Unchanged: $url" >&2
78 else
79 echo "$progname: Warning: resource out of date: $url" >&2
83 source $config