|
2 | 2 |
|
3 | 3 | # Author: @MikeRalphson
|
4 | 4 |
|
5 |
| -# run this script from the root of the repo. It is designed to be run by a GitHub workflow. |
| 5 | +# run this script from the root of the repo |
| 6 | +# It is designed to be run by a GitHub workflow |
| 7 | + |
| 8 | +# Usage: build.sh [version | "latest" | "src"] |
| 9 | +# When run with no arguments, it builds artifacts for all published specification versions. |
| 10 | +# It may also be run with a specific version argument, such as "3.1.1" or "latest" |
| 11 | +# Finally, it may be run with "src" to build "src/oas.md" |
| 12 | +# |
6 | 13 | # It contains bashisms
|
7 | 14 |
|
8 |
| -mkdir -p deploy/oas |
9 |
| -mkdir -p deploy/js |
| 15 | +if [ "$1" = "src" ]; then |
| 16 | + deploydir="deploy-preview" |
| 17 | +else |
| 18 | + deploydir="deploy/oas" |
| 19 | +fi |
| 20 | + |
| 21 | +mkdir -p $deploydir/js |
| 22 | +mkdir -p $deploydir/temp |
| 23 | +cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/ |
10 | 24 |
|
11 |
| -cd scripts/md2html |
| 25 | +latest=$(git describe --abbrev=0 --tags) |
12 | 26 |
|
13 |
| -cp -p ../../node_modules/respec/builds/respec-w3c.* ../../deploy/js/ |
| 27 | +if [ -z "$1" ]; then |
| 28 | + specifications=$(ls -1 versions/[23456789].*.md | grep -v -e "\-editors" | sort -r) |
| 29 | +elif [ "$1" = "latest" ]; then |
| 30 | + specifications=$(ls -1 versions/$latest.md) |
| 31 | +elif [ "$1" = "src" ]; then |
| 32 | + specifications="src/oas.md" |
| 33 | +else |
| 34 | + specifications=$(ls -1 versions/$1.md) |
| 35 | +fi |
14 | 36 |
|
15 |
| -latest=`git describe --abbrev=0 --tags` |
16 |
| -latestCopied=none |
| 37 | +latestCopied="none" |
17 | 38 | lastMinor="-"
|
18 |
| -for filename in $(ls -1 ../../versions/[23456789].*.md | sort -r) ; do |
19 |
| - if [[ ${filename} == *-editors.md ]];then |
20 |
| - continue |
| 39 | + |
| 40 | +for specification in $specifications; do |
| 41 | + version=$(basename $specification .md) |
| 42 | + |
| 43 | + if [ "$1" = "src" ]; then |
| 44 | + destination="$deploydir/$version.html" |
| 45 | + maintainers="EDITORS.md" |
| 46 | + else |
| 47 | + destination="$deploydir/v$version.html" |
| 48 | + maintainers="$(dirname $specification)/$version-editors.md" |
21 | 49 | fi
|
22 | 50 |
|
23 |
| - version=$(basename "$filename" .md) |
24 | 51 | minorVersion=${version:0:3}
|
25 |
| - tempfile=../../deploy/oas/v$version-tmp.html |
26 |
| - echo -e "\n=== v$version ===" |
| 52 | + tempfile="$deploydir/temp/$version.html" |
27 | 53 |
|
28 |
| - node md2html.js --maintainers ../../versions/$version-editors.md ${filename} > $tempfile |
29 |
| - npx respec --use-local --src $tempfile --out ../../deploy/oas/v$version.html |
| 54 | + echo === Building $version to $destination |
| 55 | + |
| 56 | + node scripts/md2html/md2html.js --maintainers $maintainers $specification > $tempfile |
| 57 | + npx respec --use-local --src $tempfile --out $destination |
30 | 58 | rm $tempfile
|
31 | 59 |
|
| 60 | + echo === Built $destination |
| 61 | + |
32 | 62 | if [ $version = $latest ]; then
|
33 |
| - if [[ ${version} != *"rc"* ]];then |
| 63 | + if [[ ${version} != *"rc"* ]]; then |
34 | 64 | # version is not a Release Candidate
|
35 |
| - ( cd ../../deploy/oas && ln -sf v$version.html latest.html ) |
36 |
| - latestCopied=v$version |
| 65 | + ln -sf $(basename $destination) $deploydir/latest.html |
| 66 | + latestCopied="v$version" |
37 | 67 | fi
|
38 | 68 | fi
|
39 | 69 |
|
40 |
| - if [ ${minorVersion} != ${lastMinor} ] && [ ${minorVersion} != 2.0 ]; then |
41 |
| - ( cd ../../deploy/oas && ln -sf v$version.html v$minorVersion.html ) |
| 70 | + if [ ${minorVersion} != ${lastMinor} ] && [[ ${minorVersion} =~ ^[3-9] ]]; then |
| 71 | + ln -sf $(basename $destination) $deploydir/v$minorVersion.html |
42 | 72 | lastMinor=$minorVersion
|
43 | 73 | fi
|
44 | 74 | done
|
45 |
| -echo Latest tag is $latest, copied $latestCopied to latest.html |
46 | 75 |
|
47 |
| -rm ../../deploy/js/respec-w3c.* |
| 76 | +if [ "$latestCopied" != "none" ]; then |
| 77 | + echo Latest tag is $latest, copied $latestCopied to latest.html |
| 78 | +fi |
| 79 | + |
| 80 | +rm $deploydir/js/respec-w3c.* |
| 81 | +rmdir $deploydir/js |
| 82 | +rmdir $deploydir/temp |
0 commit comments