diff --git a/.github/workflows/schema-publish.yaml b/.github/workflows/schema-publish.yaml index 6abd54b..9dbc717 100644 --- a/.github/workflows/schema-publish.yaml +++ b/.github/workflows/schema-publish.yaml @@ -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: @@ -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. diff --git a/package.json b/package.json index ceafab5..e7fe3ab 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/scripts/schema-publish.sh b/scripts/schema-publish.sh index 9f96a19..7bf098c 100755 --- a/scripts/schema-publish.sh +++ b/scripts/schema-publish.sh @@ -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") @@ -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