-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Expand file tree
/
Copy pathschema-publish.sh
More file actions
executable file
·93 lines (74 loc) · 2.87 KB
/
schema-publish.sh
File metadata and controls
executable file
·93 lines (74 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
# Author: @ralfhandl
# Run this script from the root of the repo. It is designed to be run by a GitHub workflow.
schemaDir="src/schemas/validation"
branch=$(git branch --show-current)
if [ -z "$1" ]; then
if [[ $branch =~ ^v([0-9]+\.[0-9]+)-dev$ ]]; then
version="${BASH_REMATCH[1]}"
deploydir="./deploy/oas/${version}"
else
echo "Unable to determine version from branch name; should be vX.Y-dev"
exit 1
fi
elif [ $1 = "src" ]; then
deploydir="./deploy-preview"
else
echo "Unrecognized argument"
exit 1
fi
# create the date-stamped schemas
publish_schema() {
local schema="$1"
local date="$2"
local sedCmd="$3"
local base=$(basename $schema '.yaml')
local target=$deploydir/$base/$date
mkdir -p $deploydir/$base
# replace the WORK-IN-PROGRESS placeholders
sed ${sedCmd[@]} $schemaDir/$schema | npx yaml --json --indent 2 --single > $target
# find the jekyll lander markdown file
local jekyllLander=$(find "$deploydir/$base" -maxdepth 1 -name "*.md")
# rename or create the jekyll lander markdown file for this iteration
if [ ! -z "$jekyllLander" ]; then
if [ "$jekyllLander" = "$target.md" ]; then
echo " * $base did not change since $date"
else
mv $jekyllLander $target.md
echo " * $base: $date added & jekyll lander moved from $(basename $jekyllLander)"
fi
else
# find the most recent preceding version
local lastdir=""; for fn in $(dirname $deploydir)/?.?; do test "$fn" "<" "$deploydir" && lastdir="$fn"; done
local lastVersion=$(basename $lastdir)
# find the jekyll lander markdown file for the preceding version
local lastLander=$(find "$lastdir/$base" -maxdepth 1 -name "*.md" 2>/dev/null)
if [ ! -z "$lastLander" ]; then
# copy and adjust the lander file from the preceding version
sed "s/$lastVersion/$version/g" $lastLander > $target.md
echo " * $base: $date added & jekyll lander copied from $(basename $lastLander) of $lastVersion"
else
echo " * $base: $date added"
fi
fi
}
echo === Building schemas into $deploydir
# list of schemas to process, dependent schemas come first
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)
# publish each schema using its or any of its dependencies newest commit date
maxDate=""
sedCmds=()
for schema in "${schemas[@]}"; do
if [ -f "$schemaDir/$schema" ]; then
newestCommitDate=$(git log -1 --format="%cd" --date=short "$schemaDir/$schema")
# the newest date across a schema and all its dependencies is its date stamp
if [ "$newestCommitDate" \> "$maxDate" ]; then
maxDate=$newestCommitDate
fi
base=$(basename $schema '.yaml')
# add the replacement for this schema's placeholder to list of sed commands
sedCmds+=("s/${base}\/WORK-IN-PROGRESS/${base}\/${maxDate}/g")
publish_schema "$schema" "$maxDate" $(printf '%s;' "${sedCmds[@]}")
fi
done
echo === Built