Skip to content

Commit 80a65ba

Browse files
committed
Combine build.sh and build-src.sh
build.sh with no arguments operates the same; builds all versions to /deploy build.sh with version argument builds single version to /deploy-preview build.sh with "latest" argument builds latest version to /deploy-preview build.sh with "oas" argument builds from src/oas.md to /deploy-preview
1 parent bf9155d commit 80a65ba

File tree

4 files changed

+80
-32
lines changed

4 files changed

+80
-32
lines changed

scripts/md2html/build.sh

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,38 @@
22

33
# Author: @MikeRalphson
44

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+
#
613
# It contains bashisms
714

8-
mkdir -p deploy/oas
9-
mkdir -p deploy/js
15+
if [ -z "$1" ]; then
16+
deploydir="deploy/oas"
17+
else
18+
deploydir="deploy-preview"
19+
fi
20+
21+
mkdir -p $deploydir/js
22+
mkdir -p $deploydir/temp
23+
24+
latest=$(git describe --abbrev=0 --tags)
25+
latestCopied="none"
26+
lastMinor="-"
1027

11-
cd scripts/md2html
1228
mkdir -p history
13-
cat > history/MAINTAINERS_v2.0.md <<EOF
29+
cat > history/MAINTAINERS_v2.0.md << EOF
1430
## Active
1531
* Jeremy Whitlock [@whitlockjc](https://github.com/whitlockjc)
1632
* Marsh Gardiner [@earth2marsh](https://github.com/earth2marsh)
1733
* Ron Ratovsky [@webron](https://github.com/webron)
1834
* Tony Tam [@fehguy](https://github.com/fehguy)
1935
EOF
20-
cat > history/MAINTAINERS_v3.0.0.md <<EOF
36+
cat > history/MAINTAINERS_v3.0.0.md << EOF
2137
## Active
2238
* Jeremy Whitlock [@whitlockjc](https://github.com/whitlockjc)
2339
* Marsh Gardiner [@earth2marsh](https://github.com/earth2marsh)
@@ -36,38 +52,57 @@ git show c3b88ed:EDITORS.md > history/MAINTAINERS_v3.0.4.md
3652
cp history/MAINTAINERS_v3.0.4.md history/MAINTAINERS_v3.1.1.md
3753
# add lines for 3.2.0, ...
3854

39-
cp -p ../../node_modules/respec/builds/respec-w3c.* ../../deploy/js/
55+
if [ -z "$1" ]; then
56+
specifications=$(ls -1 versions/[23456789].*.md | sort -r)
57+
elif [ "$1" = "latest" ]; then
58+
specifications=$(ls -1 versions/$latest.md)
59+
elif [ "$1" = "src" ]; then
60+
specifications="src/oas.md"
61+
else
62+
specifications=$(ls -1 versions/$1.md)
63+
fi
4064

41-
latest=`git describe --abbrev=0 --tags`
42-
latestCopied=none
43-
lastMinor="-"
44-
for filename in $(ls -1 ../../versions/[23456789].*.md | sort -r) ; do
45-
version=$(basename "$filename" .md)
65+
cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/
66+
67+
for specification in $specifications; do
68+
version=$(basename $specification .md)
4669
minorVersion=${version:0:3}
47-
tempfile=../../deploy/oas/v$version-tmp.html
48-
echo -e "\n=== v$version ==="
70+
destination="$deploydir/$version.html"
71+
tempfile="$deploydir/temp/$version.html"
4972

50-
node md2html.js --maintainers ./history/MAINTAINERS_v$version.md ${filename} > $tempfile
51-
npx respec --use-local --src $tempfile --out ../../deploy/oas/v$version.html
73+
if [ "$1" = "src" ]; then
74+
maintainers="EDITORS.md"
75+
else
76+
maintainers="history/MAINTAINERS_v$version.md"
77+
fi
78+
79+
echo === Building $version to $destination
80+
81+
node scripts/md2html/md2html.js --maintainers $maintainers $specification > $tempfile
82+
npx respec --use-local --src $tempfile --out $destination
5283
rm $tempfile
5384

85+
echo === Built $destination
86+
5487
if [ $version = $latest ]; then
55-
if [[ ${version} != *"rc"* ]];then
88+
if [[ ${version} != *"rc"* ]]; then
5689
# version is not a Release Candidate
57-
pushd ../../deploy/oas
58-
ln -sf v$version.html latest.html
59-
popd
60-
latestCopied=v$version
90+
ln -sf $(basename $destination) $deploydir/latest.html
91+
latestCopied="v$version"
6192
fi
6293
fi
6394

6495
if [ ${minorVersion} != ${lastMinor} ] && [ ${minorVersion} != 2.0 ]; then
65-
pushd ../../deploy/oas
66-
ln -sf v$version.html v$minorVersion.html
67-
popd
96+
ln -sf $(basename $destination) $deploydir/v$minorVersion.html
6897
lastMinor=$minorVersion
6998
fi
7099
done
71-
echo Latest tag is $latest, copied $latestCopied to latest.html
72100

73-
rm ../../deploy/js/respec-w3c.*
101+
if [ "$latestCopied" != "none" ]; then
102+
echo Latest tag is $latest, copied $latestCopied to latest.html
103+
fi
104+
105+
rm $deploydir/js/respec-w3c.*
106+
rmdir $deploydir/js
107+
rmdir $deploydir/temp
108+
rm -r history

scripts/md2html/md2html.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ function preface(title,options) {
131131
// ReSpec
132132
preface += '<script src="../js/respec-w3c.js" class="remove"></script>';
133133
preface += `<script class="remove">var respecConfig = ${JSON.stringify(respec)};</script>`;
134-
try {
135-
preface += fs.readFileSync('./analytics/google.html','utf8');
136-
}
137-
catch (ex) {}
134+
preface += fs.readFileSync(path.resolve(__dirname, 'analytics/google.html'),'utf8');
138135
preface += '</head><body>';
139136
preface += '<style>';
140137
preface += '#respec-ui { visibility: hidden; }';

tests/md2html/fixtures/basic-new.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>OpenAPI Specification v30.0.1 | Introduction, Definitions, &amp; More</title><meta name="description" content="The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs."><script src="../js/respec-w3c.js" class="remove"></script><script class="remove">var respecConfig = {"specStatus":"base","latestVersion":"https://spec.openapis.org/oas/latest.html","thisVersion":"https://spec.openapis.org/oas/v30.0.1.html","canonicalURI":"https://spec.openapis.org/oas/v30.0.1.html","editors":[{"name":"John Doe "},{"name":"Jane Doe "}],"formerEditors":[{"name":"Foo Bar "}],"publishDate":"3001-04-01T00:00:00.000Z","subtitle":"Version 30.0.1","edDraftURI":"https://github.com/OAI/OpenAPI-Specification/","shortName":"OAS","historyURI":null,"lint":false,"logos":[{"src":"https://raw.githubusercontent.com/OAI/OpenAPI-Style-Guide/master/graphics/bitmap/OpenAPI_Logo_Pantone.png","alt":"OpenAPI Initiative","height":48,"url":"https://openapis.org/"}],"otherLinks":[{"key":"Participate","data":[{"value":"GitHub OAI/OpenAPI-Specification","href":"https://github.com/OAI/OpenAPI-Specification/"},{"value":"File a bug","href":"https://github.com/OAI/OpenAPI-Specification/issues"},{"value":"Commit history","href":"https://github.com/OAI/OpenAPI-Specification/commits/main/versions/30.0.1.md"},{"value":"Pull requests","href":"https://github.com/OAI/OpenAPI-Specification/pulls"}]}]};</script></head><body><style>#respec-ui { visibility: hidden; }#title { color: #578000; } #subtitle { color: #578000; }.dt-published { color: #578000; } .dt-published::before { content: "Published "; }h1,h2,h3,h4,h5,h6 { color: #578000; font-weight: normal; font-style: normal; }a[href] { color: #45512c; }body:not(.toc-inline) #toc h2 { color: #45512c; }table { display: block; width: 100%; overflow: auto; }table th { font-weight: 600; }table th, table td { padding: 6px 13px; border: 1px solid #dfe2e5; }table tr { background-color: #fff; border-top: 1px solid #c6cbd1; }table tr:nth-child(2n) { background-color: #f6f8fa; }pre { background-color: #f6f8fa !important; }code { color: #c83500 } th code { color: inherit }a.bibref { text-decoration: underline;}/** * GitHub Gist Theme * Author : Louis Barranqueiro - https://github.com/LouisBarranqueiro */ .hljs { display: block; background: white; padding: 0.5em; color: #333333; overflow-x: auto; } .hljs-comment, .hljs-meta { color: #727070; } .hljs-string, .hljs-variable, .hljs-template-variable, .hljs-strong, .hljs-emphasis, .hljs-quote { color: #c74700; } .hljs-number { color: #005e5e; } .hljs-keyword, .hljs-selector-tag, .hljs-type { color: #a71d5d; } .hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-attribute { color: #007aa2; } .hljs-section, .hljs-name { color: #4b7c46; } .hljs-tag { color: #333333; } .hljs-title, .hljs-attr, .hljs-selector-id, .hljs-selector-class, .hljs-selector-attr, .hljs-selector-pseudo { color: #795da3; } .hljs-addition { color: #55a532; background-color: #eaffea; } .hljs-deletion { color: #bd2c00; background-color: #ffecec; } .hljs-link { text-decoration: underline; } </style><h1 id="title">OpenAPI Specification v30.0.1 </h1><p class="copyright">Copyright © 3001 the Linux Foundation</p><section class="notoc" id="abstract"><h2>What is the OpenAPI Specification?</h2>The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs, which allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code, additional documentation, or inspection of network traffic. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interface descriptions have done for lower-level programming, the OpenAPI Specification removes guesswork in calling a service.</section><section class="override" id="sotd" data-max-toc="0"><h2>Status of This Document</h2>The source-of-truth for this specification is the HTML file referenced above as <em>This version</em>.</section>
1+
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>OpenAPI Specification v30.0.1 | Introduction, Definitions, &amp; More</title><meta name="description" content="The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs."><script src="../js/respec-w3c.js" class="remove"></script><script class="remove">var respecConfig = {"specStatus":"base","latestVersion":"https://spec.openapis.org/oas/latest.html","thisVersion":"https://spec.openapis.org/oas/v30.0.1.html","canonicalURI":"https://spec.openapis.org/oas/v30.0.1.html","editors":[{"name":"John Doe "},{"name":"Jane Doe "}],"formerEditors":[{"name":"Foo Bar "}],"publishDate":"3001-04-01T00:00:00.000Z","subtitle":"Version 30.0.1","edDraftURI":"https://github.com/OAI/OpenAPI-Specification/","shortName":"OAS","historyURI":null,"lint":false,"logos":[{"src":"https://raw.githubusercontent.com/OAI/OpenAPI-Style-Guide/master/graphics/bitmap/OpenAPI_Logo_Pantone.png","alt":"OpenAPI Initiative","height":48,"url":"https://openapis.org/"}],"otherLinks":[{"key":"Participate","data":[{"value":"GitHub OAI/OpenAPI-Specification","href":"https://github.com/OAI/OpenAPI-Specification/"},{"value":"File a bug","href":"https://github.com/OAI/OpenAPI-Specification/issues"},{"value":"Commit history","href":"https://github.com/OAI/OpenAPI-Specification/commits/main/versions/30.0.1.md"},{"value":"Pull requests","href":"https://github.com/OAI/OpenAPI-Specification/pulls"}]}]};</script><!-- Global site tag (gtag.js) - Google Analytics -->
2+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-831873-42"></script>
3+
<script>
4+
window.dataLayer = window.dataLayer || [];
5+
function gtag(){dataLayer.push(arguments);}
6+
gtag('js', new Date());
7+
gtag('config', 'UA-831873-42');
8+
</script>
9+
</head><body><style>#respec-ui { visibility: hidden; }#title { color: #578000; } #subtitle { color: #578000; }.dt-published { color: #578000; } .dt-published::before { content: "Published "; }h1,h2,h3,h4,h5,h6 { color: #578000; font-weight: normal; font-style: normal; }a[href] { color: #45512c; }body:not(.toc-inline) #toc h2 { color: #45512c; }table { display: block; width: 100%; overflow: auto; }table th { font-weight: 600; }table th, table td { padding: 6px 13px; border: 1px solid #dfe2e5; }table tr { background-color: #fff; border-top: 1px solid #c6cbd1; }table tr:nth-child(2n) { background-color: #f6f8fa; }pre { background-color: #f6f8fa !important; }code { color: #c83500 } th code { color: inherit }a.bibref { text-decoration: underline;}/** * GitHub Gist Theme * Author : Louis Barranqueiro - https://github.com/LouisBarranqueiro */ .hljs { display: block; background: white; padding: 0.5em; color: #333333; overflow-x: auto; } .hljs-comment, .hljs-meta { color: #727070; } .hljs-string, .hljs-variable, .hljs-template-variable, .hljs-strong, .hljs-emphasis, .hljs-quote { color: #c74700; } .hljs-number { color: #005e5e; } .hljs-keyword, .hljs-selector-tag, .hljs-type { color: #a71d5d; } .hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-attribute { color: #007aa2; } .hljs-section, .hljs-name { color: #4b7c46; } .hljs-tag { color: #333333; } .hljs-title, .hljs-attr, .hljs-selector-id, .hljs-selector-class, .hljs-selector-attr, .hljs-selector-pseudo { color: #795da3; } .hljs-addition { color: #55a532; background-color: #eaffea; } .hljs-deletion { color: #bd2c00; background-color: #ffecec; } .hljs-link { text-decoration: underline; } </style><h1 id="title">OpenAPI Specification v30.0.1 </h1><p class="copyright">Copyright © 3001 the Linux Foundation</p><section class="notoc" id="abstract"><h2>What is the OpenAPI Specification?</h2>The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs, which allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code, additional documentation, or inspection of network traffic. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interface descriptions have done for lower-level programming, the OpenAPI Specification removes guesswork in calling a service.</section><section class="override" id="sotd" data-max-toc="0"><h2>Status of This Document</h2>The source-of-truth for this specification is the HTML file referenced above as <em>This version</em>.</section>
210
<section><h1>Heading 1</h1>
311
<p>Text for first chapter</p>
412
<section class="override" id="conformance"><h2>Version 30.0.1</h2>

0 commit comments

Comments
 (0)