From 9449ce841cbb32219bcaa68c4bde0080a1d8135e Mon Sep 17 00:00:00 2001 From: Duncan Beevers Date: Sat, 8 Feb 2025 05:04:27 -0800 Subject: [PATCH 1/3] Build single targets build.sh with no arguments builds all versions build.sh builds single version build.sh latest builds latest version build.sh src builds from src/oas.md Resolve Google Analytics snippet location relative to md2html.js Update tests to reflect inclusion of snippet Pre-requisite to https://github.com/OAI/OpenAPI-Specification/pull/4341 --- scripts/md2html/build.sh | 80 +++++++++++++++++++-------- scripts/md2html/md2html.js | 5 +- tests/md2html/fixtures/basic-new.html | 10 +++- tests/md2html/fixtures/basic-old.html | 10 +++- 4 files changed, 76 insertions(+), 29 deletions(-) diff --git a/scripts/md2html/build.sh b/scripts/md2html/build.sh index f0766d7ba8..dcfe5b1365 100755 --- a/scripts/md2html/build.sh +++ b/scripts/md2html/build.sh @@ -2,46 +2,80 @@ # Author: @MikeRalphson -# run this script from the root of the repo. It is designed to be run by a GitHub workflow. -# It contains bashisms +# run this script from the root of the repo +# It is designed to be run by a GitHub workflow -mkdir -p deploy/oas -mkdir -p deploy/js +# Usage: build.sh [version | "latest" | "src"] +# When run with no arguments, it builds artifacts for all published specification versions. +# It may also be run with a specific version argument, such as "3.1.1" or "latest" +# Finally, it may be run with "src" to build "src/oas.md" +# +# It contains bashisms -cd scripts/md2html +if [ -z "$1" ]; then + deploydir="deploy/oas" +else + deploydir="deploy-preview" +fi -cp -p ../../node_modules/respec/builds/respec-w3c.* ../../deploy/js/ +mkdir -p $deploydir/js +mkdir -p $deploydir/temp -latest=`git describe --abbrev=0 --tags` -latestCopied=none +latest=$(git describe --abbrev=0 --tags) +latestCopied="none" lastMinor="-" -for filename in $(ls -1 ../../versions/[23456789].*.md | sort -r) ; do - if [[ ${filename} == *-editors.md ]];then - continue - fi - version=$(basename "$filename" .md) +if [ -z "$1" ]; then + specifications=$(ls -1 versions/[23456789].*.md | grep -v -e "\-editors" | sort -r) +elif [ "$1" = "latest" ]; then + specifications=$(ls -1 versions/$latest.md) +elif [ "$1" = "src" ]; then + specifications="src/oas.md" +else + specifications=$(ls -1 versions/$1.md) +fi + +cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/ + +for specification in $specifications; do + version=$(basename $specification .md) minorVersion=${version:0:3} - tempfile=../../deploy/oas/v$version-tmp.html - echo -e "\n=== v$version ===" + tempfile="$deploydir/temp/$version.html" - node md2html.js --maintainers ../../versions/$version-editors.md ${filename} > $tempfile - npx respec --use-local --src $tempfile --out ../../deploy/oas/v$version.html + if [ "$1" = "src" ]; then + destination="$deploydir/$version.html" + maintainers="EDITORS.md" + else + destination="$deploydir/v$version.html" + maintainers="$(dirname $specification)/$version-editors.md" + fi + + echo === Building $version to $destination + + node scripts/md2html/md2html.js --maintainers $maintainers $specification > $tempfile + npx respec --use-local --src $tempfile --out $destination rm $tempfile + echo === Built $destination + if [ $version = $latest ]; then - if [[ ${version} != *"rc"* ]];then + if [[ ${version} != *"rc"* ]]; then # version is not a Release Candidate - ( cd ../../deploy/oas && ln -sf v$version.html latest.html ) - latestCopied=v$version + ln -sf $(basename $destination) $deploydir/latest.html + latestCopied="v$version" fi fi if [ ${minorVersion} != ${lastMinor} ] && [ ${minorVersion} != 2.0 ]; then - ( cd ../../deploy/oas && ln -sf v$version.html v$minorVersion.html ) + ln -sf $(basename $destination) $deploydir/v$minorVersion.html lastMinor=$minorVersion fi done -echo Latest tag is $latest, copied $latestCopied to latest.html -rm ../../deploy/js/respec-w3c.* +if [ "$latestCopied" != "none" ]; then + echo Latest tag is $latest, copied $latestCopied to latest.html +fi + +rm $deploydir/js/respec-w3c.* +rmdir $deploydir/js +rmdir $deploydir/temp diff --git a/scripts/md2html/md2html.js b/scripts/md2html/md2html.js index f2ae056919..29e6d93f26 100644 --- a/scripts/md2html/md2html.js +++ b/scripts/md2html/md2html.js @@ -132,10 +132,7 @@ function preface(title,options) { preface += ''; preface += ''; preface += ``; - try { - preface += fs.readFileSync('./analytics/google.html','utf8'); - } - catch (ex) {} + preface += fs.readFileSync(path.resolve(__dirname,'./analytics/google.html'),'utf8'); preface += ''; preface += '

OpenAPI Specification v30.0.1

What is the OpenAPI Specification?

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.

Status of This Document

The source-of-truth for this specification is the HTML file referenced above as This version.
+OpenAPI Specification v30.0.1 | Introduction, Definitions, & More + + +

OpenAPI Specification v30.0.1

What is the OpenAPI Specification?

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.

Status of This Document

The source-of-truth for this specification is the HTML file referenced above as This version.

Heading 1

Text for first chapter

Version 30.0.1

diff --git a/tests/md2html/fixtures/basic-old.html b/tests/md2html/fixtures/basic-old.html index e28f0ac360..0326005ec5 100644 --- a/tests/md2html/fixtures/basic-old.html +++ b/tests/md2html/fixtures/basic-old.html @@ -1,4 +1,12 @@ -OpenAPI Specification v30.0.1 | Introduction, Definitions, & More

OpenAPI Specification v30.0.1

What is the OpenAPI Specification?

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.

Status of This Document

The source-of-truth for this specification is the HTML file referenced above as This version.
+OpenAPI Specification v30.0.1 | Introduction, Definitions, & More + + +

OpenAPI Specification v30.0.1

What is the OpenAPI Specification?

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.

Status of This Document

The source-of-truth for this specification is the HTML file referenced above as This version.

Heading 1

Text for first chapter

Version 30.0.1

From 639c6cadcbaab6df23e2cdf496680458694d87ce Mon Sep 17 00:00:00 2001 From: Duncan Beevers Date: Sun, 9 Feb 2025 11:07:09 -0800 Subject: [PATCH 2/3] fixup! Build single targets build.sh with no arguments builds all versions build.sh builds single version build.sh latest builds latest version build.sh src builds from src/oas.md Resolve Google Analytics snippet location relative to md2html.js Update tests to reflect inclusion of snippet Pre-requisite to https://github.com/OAI/OpenAPI-Specification/pull/4341 --- .gitignore | 1 + scripts/md2html/build.sh | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index fadcdf5db7..f3ff4ab93f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ target atlassian-ide-plugin.xml node_modules/ deploy/ +deploy-preview/ coverage/ history Gemfile.lock diff --git a/scripts/md2html/build.sh b/scripts/md2html/build.sh index dcfe5b1365..2711cedd0a 100755 --- a/scripts/md2html/build.sh +++ b/scripts/md2html/build.sh @@ -12,18 +12,17 @@ # # It contains bashisms -if [ -z "$1" ]; then - deploydir="deploy/oas" -else +if [ "$1" = "src" ]; then deploydir="deploy-preview" +else + deploydir="deploy/oas" fi mkdir -p $deploydir/js mkdir -p $deploydir/temp +cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/ latest=$(git describe --abbrev=0 --tags) -latestCopied="none" -lastMinor="-" if [ -z "$1" ]; then specifications=$(ls -1 versions/[23456789].*.md | grep -v -e "\-editors" | sort -r) @@ -35,12 +34,11 @@ else specifications=$(ls -1 versions/$1.md) fi -cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/ +latestCopied="none" +lastMinor="-" for specification in $specifications; do version=$(basename $specification .md) - minorVersion=${version:0:3} - tempfile="$deploydir/temp/$version.html" if [ "$1" = "src" ]; then destination="$deploydir/$version.html" @@ -50,6 +48,9 @@ for specification in $specifications; do maintainers="$(dirname $specification)/$version-editors.md" fi + minorVersion=${version:0:3} + tempfile="$deploydir/temp/$version.html" + echo === Building $version to $destination node scripts/md2html/md2html.js --maintainers $maintainers $specification > $tempfile From 06a89cd8635de0dd7d0a5fefdfa821a3f8b2d668 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Mon, 10 Feb 2025 09:55:23 +0100 Subject: [PATCH 3/3] Update scripts/md2html/build.sh --- scripts/md2html/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/md2html/build.sh b/scripts/md2html/build.sh index 2711cedd0a..89ff9e3663 100755 --- a/scripts/md2html/build.sh +++ b/scripts/md2html/build.sh @@ -67,7 +67,7 @@ for specification in $specifications; do fi fi - if [ ${minorVersion} != ${lastMinor} ] && [ ${minorVersion} != 2.0 ]; then + if [ ${minorVersion} != ${lastMinor} ] && [[ ${minorVersion} =~ ^[3-9] ]]; then ln -sf $(basename $destination) $deploydir/v$minorVersion.html lastMinor=$minorVersion fi