6
6
7
7
schemaDir=" src/schemas/validation"
8
8
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
11
57
12
58
# list of schemas to process, dependent schemas come first
13
59
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)
14
60
15
- # find the newest commit date for each schema
61
+ # publish each schema using its or any of its dependencies newest commit date.
16
62
maxDate=" "
17
- declare -A datesHash
63
+ sedCmds=()
18
64
for schema in " ${schemas[@]} " ; do
19
65
if [ -f " $schemaDir /$schema " ]; then
20
66
newestCommitDate=$( git log -1 --format=" %ad" --date=short " $schemaDir /$schema " )
@@ -23,31 +69,13 @@ for schema in "${schemas[@]}"; do
23
69
if [ " $newestCommitDate " \> " $maxDate " ]; then
24
70
maxDate=$newestCommitDate
25
71
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
72
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" )
44
76
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
51
79
done
52
80
53
81
echo === Built
0 commit comments