Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/schema-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ name: schema-publish
# This workflow creates a pull request for publishing schema iterations to the spec.openapis.org site.
#

# run this on changes to schemas to main
# run this on changes to published schemas or manually
on:
push:
paths:
- "schemas/**"
branches:
- main
paths:
- "schemas/v[0-9].[0-9]/*.yaml"
workflow_dispatch: {}

jobs:
Expand Down Expand Up @@ -66,4 +66,4 @@ jobs:
signoff: true
body: |
This pull request is automatically generated by GitHub action `schema-publish` in the OAI/Overlay-Specification repo.
The `schemas/**/*.yaml` files have changed and JSON files are automatically generated.
The `schemas/vX.Y/*.yaml` files have changed and JSON files are automatically generated.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
],
"scripts": {
"build": "bash ./scripts/md2html/build.sh",
"build-dev": "bash ./scripts/md2html/build.sh dev",
"build-dev": "bash ./scripts/md2html/build.sh dev && bash ./scripts/schema-publish.sh dev",
"format-markdown": "bash ./scripts/format-markdown.sh ./versions/*.md",
"test": "c8 --100 vitest run --coverage"
}
Expand Down
101 changes: 65 additions & 36 deletions scripts/schema-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,70 @@

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

for schemaDir in schemas/v* ; do
vVersion=$(basename "$schemaDir")
if [ -z "$1" ]; then
schemaDirs=(schemas/v[1-9].[0-9])
deployRoot="./deploy/overlay"
elif [ $1 = "dev" ]; then
schemaDirs=(schemas/v[1-9].[0-9]-dev)
deployRoot="./deploy-preview"
else
echo "Unrecognized argument"
exit 1
fi

# list of schemas to process, dependent schemas come first
schemas=(schema.yaml)

# 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

if [[ "$vVersion" =~ -dev$ ]] ; then
echo "Skipping dev version $vVersion"
continue
# 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
mv $jekyllLander $target.md
echo " * $newestCommitDate: $schema & jekyll lander $(basename $jekyllLander)"
else
# find the most recent preceding version
local lastdir=""; for fn in $(dirname $deploydir)/?.?; do test "$fn" "<" "$deploydir" && lastdir="$fn"; done
if [ -z "$lastdir" ]; then
return
fi
local lastVersion=$(basename $lastdir)
# find the jekyll lander markdown file for the preceding version
local lastLander=$(find "$lastdir/$base" -maxdepth 1 -name "*.md")

if [ ! -z "$lastLander" ]; then
# copy and adjust the lander file from the preceding version
sed "s/$lastVersion/$version/g" $lastLander > $target.md
echo " * $newestCommitDate: $schema & jekyll lander $(basename $lastLander) of $lastVersion"
else
echo " * $newestCommitDate: $schema"
fi
fi
}

for schemaDir in $schemaDirs; do
vVersion=$(basename "$schemaDir")
version=${vVersion:1}
echo $version
deploydir="$deployRoot/$version"
echo === Building schemas into $deploydir

# list of schemas to process, dependent schemas come first
schemas=(schema.yaml)

# find the newest commit date for each schema
# publish each schema using its or any of its dependencies newest commit date
maxDate=""
declare -A datesHash
sedCmds=()
for schema in "${schemas[@]}"; do
if [ -f "$schemaDir/$schema" ]; then
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")
Expand All @@ -29,32 +76,14 @@ for schemaDir in schemas/v* ; do
if [ "$newestCommitDate" \> "$maxDate" ]; then
maxDate=$newestCommitDate
fi
datesHash["$schema"]=$maxDate
echo $schema changed at $newestCommitDate
fi
done

# construct sed command
sedCmd=()
for schema in "${!datesHash[@]}"; do
base=$(basename "$schema" .yaml)
sedCmd+=("-e s/$base\/WORK-IN-PROGRESS/$base\/${datesHash[$schema]}/g")
done

# create the date-stamped schemas
for schema in "${!datesHash[@]}"; do
base=$(basename "$schema" .yaml)
target=deploy/overlay/$version/$base/${datesHash[$schema]}
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")

mkdir -p "deploy/overlay/$version/$base"

sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml
node scripts/yaml2json/yaml2json.js $target.yaml
rm $target.yaml
mv $target.json $target

mv deploy/overlay/$version/$base/*.md $target.md
publish_schema "$schema" "$maxDate" $(printf '%s;' "${sedCmds[@]}")
fi
done

echo ""
done

echo === Built