Skip to content

Commit 20117c7

Browse files
committed
Update schema-publish.sh
Configure deploydir based on branch name Check branch name for conformance to vX.Y.Z structure * deploy to /deploy/oas/$version if branch name is conformant * deploy to /deploy-preview if branch name is non-conformant Perform only one traversal of schemas structure Remove intermediate data structures (datesHash, sedCmd)
1 parent 92e5fc9 commit 20117c7

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"license": "Apache-2.0",
1515
"scripts": {
1616
"build": "bash ./scripts/md2html/build.sh",
17-
"build-src": "npm run validate-markdown && bash ./scripts/md2html/build.sh src",
17+
"build-src": "npm run validate-markdown && bash ./scripts/md2html/build.sh src && bash ./scripts/schema-publish.sh src",
1818
"test": "c8 --100 vitest --watch=false && bash scripts/schema-test-coverage.sh",
1919
"format-markdown": "bash ./scripts/format-markdown.sh ./src/oas.md",
2020
"validate-markdown": "npx mdv src/oas.md && npx markdownlint-cli src/oas.md"

scripts/schema-publish.sh

+55-27
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,61 @@
66

77
schemaDir="src/schemas/validation"
88
branch=$(git branch --show-current)
9-
version=${branch:1:3}
10-
echo === Building schemas into ./deploy/oas/$version
9+
10+
11+
if [ -z "$1" ]; then
12+
if [[ $branch =~ ^v([0-9]+\.[0-9]+)-dev$ ]]; then
13+
deploydir="./deploy/oas/${BASH_REMATCH[1]}"
14+
else
15+
echo "Unable to determine version from branch name; should be vMAJOR.MINOR.PATCH-dev"
16+
exit 1
17+
fi
18+
elif [ $1 = "src" ]; then
19+
deploydir="./deploy-preview"
20+
else
21+
echo "Unrecognized argument"
22+
exit 1
23+
fi
24+
25+
# create the date-stamped schemas
26+
publish_schema() {
27+
local schema="$1"
28+
local date="$2"
29+
local sedCmd="$3"
30+
31+
local base=$(basename $schema '.yaml')
32+
local target=$deploydir/$base/$date
33+
34+
mkdir -p $deploydir/$base
35+
# replace the WORK-IN-PROGRESS placeholders
36+
sed -e $sedCmd $schemaDir/$schema > $target.yaml
37+
38+
node scripts/yaml2json/yaml2json.js "$target.yaml"
39+
rm "$target.yaml"
40+
mv "$target.json" "$target"
41+
42+
# Find the jekyll lander markdown file for this iteration.
43+
local jekyllLander=$(find "$deploydir/$base" -maxdepth 1 -name "*.md")
44+
45+
# Move the jekyll lander markdown for this iteration to the deploy destination.
46+
# The lander files only exist in the gh-pages branch.
47+
if [ ! -z "$jekyllLander" ]; then
48+
mv $jekyllLander $target.md
49+
echo " * $newestCommitDate: $schema & jekyll lander $(basename $jekyllLander)"
50+
else
51+
echo " * $newestCommitDate: $schema"
52+
fi
53+
54+
}
55+
56+
echo === Building schemas into $deploydir
1157

1258
# list of schemas to process, dependent schemas come first
1359
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)
1460

15-
# find the newest commit date for each schema
61+
# publish each schema using its or any of its dependencies newest commit date.
1662
maxDate=""
17-
declare -A datesHash
63+
sedCmds=()
1864
for schema in "${schemas[@]}"; do
1965
if [ -f "$schemaDir/$schema" ]; then
2066
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")
@@ -23,31 +69,13 @@ for schema in "${schemas[@]}"; do
2369
if [ "$newestCommitDate" \> "$maxDate" ]; then
2470
maxDate=$newestCommitDate
2571
fi
26-
datesHash["$schema"]=$maxDate
27-
echo $schema changed at $newestCommitDate
28-
fi
29-
done
30-
31-
# construct sed command
32-
sedCmd=()
33-
for schema in "${!datesHash[@]}"; do
34-
base=$(basename "$schema" .yaml)
35-
sedCmd+=("-e s/$base\/WORK-IN-PROGRESS/$base\/${datesHash[$schema]}/g")
36-
done
37-
38-
# create the date-stamped schemas
39-
for schema in "${!datesHash[@]}"; do
40-
base=$(basename "$schema" .yaml)
41-
target=deploy/oas/$version/$base/${datesHash[$schema]}
4272

43-
mkdir -p "deploy/oas/$version/$base"
73+
base=$(basename $schema '.yaml')
74+
# Add the replacement for this schema's placeholder to list of sed commands.
75+
sedCmds+=("s/${base}\/WORK-IN-PROGRESS/${base}\/${maxDate}/g")
4476

45-
sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml
46-
node scripts/yaml2json/yaml2json.js $target.yaml
47-
rm $target.yaml
48-
mv $target.json $target
49-
50-
mv deploy/oas/$version/$base/*.md $target.md
77+
publish_schema "$schema" "$maxDate" $(printf '%s;' "${sedCmds[@]}")
78+
fi
5179
done
5280

5381
echo === Built

0 commit comments

Comments
 (0)