Skip to content

Commit 567f8a2

Browse files
authored
Merge pull request #197 from ralfhandl/main-align-schema-publish
schema-publish workflow: align with OpenAPI spec repo
2 parents ac3599c + e3e8717 commit 567f8a2

File tree

3 files changed

+70
-41
lines changed

3 files changed

+70
-41
lines changed

.github/workflows/schema-publish.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ name: schema-publish
66
# This workflow creates a pull request for publishing schema iterations to the spec.openapis.org site.
77
#
88

9-
# run this on changes to schemas to main
9+
# run this on changes to published schemas or manually
1010
on:
1111
push:
12-
paths:
13-
- "schemas/**"
1412
branches:
1513
- main
14+
paths:
15+
- "schemas/v[0-9].[0-9]/*.yaml"
1616
workflow_dispatch: {}
1717

1818
jobs:
@@ -66,4 +66,4 @@ jobs:
6666
signoff: true
6767
body: |
6868
This pull request is automatically generated by GitHub action `schema-publish` in the OAI/Overlay-Specification repo.
69-
The `schemas/**/*.yaml` files have changed and JSON files are automatically generated.
69+
The `schemas/vX.Y/*.yaml` files have changed and JSON files are automatically generated.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
],
4141
"scripts": {
4242
"build": "bash ./scripts/md2html/build.sh",
43-
"build-dev": "bash ./scripts/md2html/build.sh dev",
43+
"build-dev": "bash ./scripts/md2html/build.sh dev && bash ./scripts/schema-publish.sh dev",
4444
"format-markdown": "bash ./scripts/format-markdown.sh ./versions/*.md",
4545
"test": "c8 --100 vitest run --coverage"
4646
}

scripts/schema-publish.sh

Lines changed: 65 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,70 @@
44

55
# Run this script from the root of the repo. It is designed to be run by a GitHub workflow.
66

7-
for schemaDir in schemas/v* ; do
8-
vVersion=$(basename "$schemaDir")
7+
if [ -z "$1" ]; then
8+
schemaDirs=(schemas/v[1-9].[0-9])
9+
deployRoot="./deploy/overlay"
10+
elif [ $1 = "dev" ]; then
11+
schemaDirs=(schemas/v[1-9].[0-9]-dev)
12+
deployRoot="./deploy-preview"
13+
else
14+
echo "Unrecognized argument"
15+
exit 1
16+
fi
17+
18+
# list of schemas to process, dependent schemas come first
19+
schemas=(schema.yaml)
20+
21+
# create the date-stamped schemas
22+
publish_schema() {
23+
local schema="$1"
24+
local date="$2"
25+
local sedCmd="$3"
26+
27+
local base=$(basename $schema '.yaml')
28+
local target=$deploydir/$base/$date
29+
30+
mkdir -p $deploydir/$base
31+
32+
# replace the WORK-IN-PROGRESS placeholders
33+
sed ${sedCmd[@]} $schemaDir/$schema | npx yaml --json --indent 2 --single > $target
934

10-
if [[ "$vVersion" =~ -dev$ ]] ; then
11-
echo "Skipping dev version $vVersion"
12-
continue
35+
# find the jekyll lander markdown file
36+
local jekyllLander=$(find "$deploydir/$base" -maxdepth 1 -name "*.md")
37+
38+
# rename or create the jekyll lander markdown file for this iteration
39+
if [ ! -z "$jekyllLander" ]; then
40+
mv $jekyllLander $target.md
41+
echo " * $newestCommitDate: $schema & jekyll lander $(basename $jekyllLander)"
42+
else
43+
# find the most recent preceding version
44+
local lastdir=""; for fn in $(dirname $deploydir)/?.?; do test "$fn" "<" "$deploydir" && lastdir="$fn"; done
45+
if [ -z "$lastdir" ]; then
46+
return
47+
fi
48+
local lastVersion=$(basename $lastdir)
49+
# find the jekyll lander markdown file for the preceding version
50+
local lastLander=$(find "$lastdir/$base" -maxdepth 1 -name "*.md")
51+
52+
if [ ! -z "$lastLander" ]; then
53+
# copy and adjust the lander file from the preceding version
54+
sed "s/$lastVersion/$version/g" $lastLander > $target.md
55+
echo " * $newestCommitDate: $schema & jekyll lander $(basename $lastLander) of $lastVersion"
56+
else
57+
echo " * $newestCommitDate: $schema"
58+
fi
1359
fi
60+
}
1461

62+
for schemaDir in $schemaDirs; do
63+
vVersion=$(basename "$schemaDir")
1564
version=${vVersion:1}
16-
echo $version
65+
deploydir="$deployRoot/$version"
66+
echo === Building schemas into $deploydir
1767

18-
# list of schemas to process, dependent schemas come first
19-
schemas=(schema.yaml)
20-
21-
# find the newest commit date for each schema
68+
# publish each schema using its or any of its dependencies newest commit date
2269
maxDate=""
23-
declare -A datesHash
70+
sedCmds=()
2471
for schema in "${schemas[@]}"; do
2572
if [ -f "$schemaDir/$schema" ]; then
2673
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")
@@ -29,32 +76,14 @@ for schemaDir in schemas/v* ; do
2976
if [ "$newestCommitDate" \> "$maxDate" ]; then
3077
maxDate=$newestCommitDate
3178
fi
32-
datesHash["$schema"]=$maxDate
33-
echo $schema changed at $newestCommitDate
34-
fi
35-
done
36-
37-
# construct sed command
38-
sedCmd=()
39-
for schema in "${!datesHash[@]}"; do
40-
base=$(basename "$schema" .yaml)
41-
sedCmd+=("-e s/$base\/WORK-IN-PROGRESS/$base\/${datesHash[$schema]}/g")
42-
done
4379

44-
# create the date-stamped schemas
45-
for schema in "${!datesHash[@]}"; do
46-
base=$(basename "$schema" .yaml)
47-
target=deploy/overlay/$version/$base/${datesHash[$schema]}
80+
base=$(basename $schema '.yaml')
81+
# add the replacement for this schema's placeholder to list of sed commands
82+
sedCmds+=("s/${base}\/WORK-IN-PROGRESS/${base}\/${maxDate}/g")
4883

49-
mkdir -p "deploy/overlay/$version/$base"
50-
51-
sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml
52-
node scripts/yaml2json/yaml2json.js $target.yaml
53-
rm $target.yaml
54-
mv $target.json $target
55-
56-
mv deploy/overlay/$version/$base/*.md $target.md
84+
publish_schema "$schema" "$maxDate" $(printf '%s;' "${sedCmds[@]}")
85+
fi
5786
done
58-
59-
echo ""
6087
done
88+
89+
echo === Built

0 commit comments

Comments
 (0)