Skip to content

Commit eb2a0ad

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 eb2a0ad

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

scripts/schema-publish.sh

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,38 @@
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+
if [[ $branch =~ ^v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
11+
deploydir="./deploy/oas/${BASH_REMATCH[1]}"
12+
else
13+
deploydir="./deploy-preview"
14+
fi
15+
16+
# create the date-stamped schemas
17+
publish_schema() {
18+
local schema="$1"
19+
local date="$2"
20+
21+
local base=$(basename $schema '.yaml')
22+
local target=$deploydir/$base/$date
23+
24+
mkdir -p $deploydir/$base
25+
# replace the WORK-IN-PROGRESS placeholder
26+
sed -e "s/${base}\\/WORK-IN-PROGRESS/${base}\\/${date}/g" $schemaDir/$schema > $target.yaml
27+
28+
node scripts/yaml2json/yaml2json.js "$target.yaml"
29+
rm "$target.yaml"
30+
mv "$target.json" "$target"
31+
echo " * $newestCommitDate: $schema"
32+
}
33+
34+
echo === Building schemas into $deploydir
1135

1236
# list of schemas to process, dependent schemas come first
1337
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)
1438

15-
# find the newest commit date for each schema
39+
# publish each schema using its or any of its dependencies newest commit date.
1640
maxDate=""
17-
declare -A datesHash
1841
for schema in "${schemas[@]}"; do
1942
if [ -f "$schemaDir/$schema" ]; then
2043
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")
@@ -23,31 +46,9 @@ for schema in "${schemas[@]}"; do
2346
if [ "$newestCommitDate" \> "$maxDate" ]; then
2447
maxDate=$newestCommitDate
2548
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]}
42-
43-
mkdir -p "deploy/oas/$version/$base"
4449

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
50+
publish_schema "$schema" "$maxDate"
51+
fi
5152
done
5253

5354
echo === Built

0 commit comments

Comments
 (0)