|
4 | 4 |
|
5 | 5 | # Run this script from the root of the repo. It is designed to be run by a GitHub workflow.
|
6 | 6 |
|
7 |
| -for schemaDir in schemas/v3* ; do |
8 |
| - vVersion=$(basename "$schemaDir") |
9 |
| - version=${vVersion:1} |
10 |
| - echo $version |
11 |
| - |
12 |
| - # list of schemas to process, dependent schemas come first |
13 |
| - schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml) |
14 |
| - |
15 |
| - # find the newest commit date for each schema |
16 |
| - maxDate="" |
17 |
| - declare -A datesHash |
18 |
| - for schema in "${schemas[@]}"; do |
19 |
| - if [ -f "$schemaDir/$schema" ]; then |
20 |
| - newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema") |
21 |
| - |
22 |
| - # the newest date across a schema and all its dependencies is its date stamp |
23 |
| - if [ "$newestCommitDate" \> "$maxDate" ]; then |
24 |
| - maxDate=$newestCommitDate |
25 |
| - fi |
26 |
| - datesHash["$schema"]=$maxDate |
27 |
| - echo $schema changed at $newestCommitDate |
28 |
| - fi |
29 |
| - done |
| 7 | +schemaDir="src/schemas/validation" |
| 8 | +branch=$(git branch --show-current) |
| 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 vX.Y-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 |
30 | 35 |
|
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 |
| 36 | + # replace the WORK-IN-PROGRESS placeholders |
| 37 | + sed ${sedCmd[@]} $schemaDir/$schema | npx yaml --json --indent 2 --single > $target |
37 | 38 |
|
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]} |
| 39 | + # Find the jekyll lander markdown file for this iteration. |
| 40 | + local jekyllLander=$(find "$deploydir/$base" -maxdepth 1 -name "*.md") |
42 | 41 |
|
43 |
| - mkdir -p "deploy/oas/$version/$base" |
| 42 | + # Move the jekyll lander markdown for this iteration to the deploy destination. |
| 43 | + # The lander files only exist in the gh-pages branch. |
| 44 | + if [ ! -z "$jekyllLander" ]; then |
| 45 | + mv $jekyllLander $target.md |
| 46 | + echo " * $newestCommitDate: $schema & jekyll lander $(basename $jekyllLander)" |
| 47 | + else |
| 48 | + echo " * $newestCommitDate: $schema" |
| 49 | + fi |
44 | 50 |
|
45 |
| - sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml |
46 |
| - node scripts/yaml2json/yaml2json.js $target.yaml |
47 |
| - rm $target.yaml |
48 |
| - mv $target.json $target |
| 51 | +} |
49 | 52 |
|
50 |
| - mv deploy/oas/$version/$base/*.md $target.md |
51 |
| - done |
| 53 | +echo === Building schemas into $deploydir |
52 | 54 |
|
53 |
| - echo "" |
| 55 | +# list of schemas to process, dependent schemas come first |
| 56 | +schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml) |
| 57 | + |
| 58 | +# publish each schema using its or any of its dependencies newest commit date. |
| 59 | +maxDate="" |
| 60 | +sedCmds=() |
| 61 | +for schema in "${schemas[@]}"; do |
| 62 | + if [ -f "$schemaDir/$schema" ]; then |
| 63 | + newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema") |
| 64 | + |
| 65 | + # the newest date across a schema and all its dependencies is its date stamp |
| 66 | + if [ "$newestCommitDate" \> "$maxDate" ]; then |
| 67 | + maxDate=$newestCommitDate |
| 68 | + fi |
| 69 | + |
| 70 | + base=$(basename $schema '.yaml') |
| 71 | + # Add the replacement for this schema's placeholder to list of sed commands. |
| 72 | + sedCmds+=("s/${base}\/WORK-IN-PROGRESS/${base}\/${maxDate}/g") |
| 73 | + |
| 74 | + publish_schema "$schema" "$maxDate" $(printf '%s;' "${sedCmds[@]}") |
| 75 | + fi |
54 | 76 | done
|
| 77 | + |
| 78 | +echo === Built |
0 commit comments