Skip to content

main: copy schema-publish script & workflow from dev #4400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
20 changes: 12 additions & 8 deletions .github/workflows/schema-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ name: schema-publish
# issue: https://github.com/OAI/OpenAPI-Specification/issues/3715

#
# This workflow copies the 3.x schemas to the gh-pages branch
# This workflow creates a pull request for publishing schema iterations to the gh-pages branch
#

# run this on push to main
# run this on push to vX.Y-dev branches or manually
on:
push:
branches:
- main
- 'v[0-9].[0-9]-dev'
paths:
- 'src/schemas/validation/*.yaml'
- 'scripts/schema-publish.sh'
- '.github/workflows/schema-publish.yaml'
workflow_dispatch: {}

jobs:
Expand All @@ -26,7 +30,7 @@ jobs:

- uses: actions/setup-node@v4 # setup Node.js
with:
node-version: '20.x'
node-version: '22.x'

- name: Install dependencies
run: npm ci
Expand All @@ -43,15 +47,15 @@ jobs:
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: publish-schema-iteration
branch: ${{ github.ref_name }}-publish-schema-iteration
base: gh-pages
delete-branch: true
path: deploy
labels: Housekeeping,Schema
reviewers: darrelmiller,webron,earth2marsh,webron,lornajane,mikekistler,miqui,ralfhandl,handrews,karenetheridge
title: Publish OpenAPI Schema Iterations
title: '${{ github.ref_name }}: publish OpenAPI schema iterations'
commit-message: New OpenAPI schema iterations
signoff: true
body: |
This pull request is automatically triggered by GitHub action `schema-publish`.
The `schemas/**/*.yaml` files have changed and JSON files are automatically generated.
This pull request is automatically generated by GitHub action `schema-publish`.
The `src/schemas/validation/*.yaml` files have changed and JSON files are automatically generated.
106 changes: 65 additions & 41 deletions scripts/schema-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,75 @@

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

for schemaDir in schemas/v3* ; do
vVersion=$(basename "$schemaDir")
version=${vVersion:1}
echo $version

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

# find the newest commit date for each schema
maxDate=""
declare -A datesHash
for schema in "${schemas[@]}"; do
if [ -f "$schemaDir/$schema" ]; then
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")

# the newest date across a schema and all its dependencies is its date stamp
if [ "$newestCommitDate" \> "$maxDate" ]; then
maxDate=$newestCommitDate
fi
datesHash["$schema"]=$maxDate
echo $schema changed at $newestCommitDate
fi
done
schemaDir="src/schemas/validation"
branch=$(git branch --show-current)


if [ -z "$1" ]; then
if [[ $branch =~ ^v([0-9]+\.[0-9]+)-dev$ ]]; then
deploydir="./deploy/oas/${BASH_REMATCH[1]}"
else
echo "Unable to determine version from branch name; should be vX.Y-dev"
exit 1
fi
elif [ $1 = "src" ]; then
deploydir="./deploy-preview"
else
echo "Unrecognized argument"
exit 1
fi

# 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

# 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
# replace the WORK-IN-PROGRESS placeholders
sed ${sedCmd[@]} $schemaDir/$schema | npx yaml --json --indent 2 --single > $target

# create the date-stamped schemas
for schema in "${!datesHash[@]}"; do
base=$(basename "$schema" .yaml)
target=deploy/oas/$version/$base/${datesHash[$schema]}
# Find the jekyll lander markdown file for this iteration.
local jekyllLander=$(find "$deploydir/$base" -maxdepth 1 -name "*.md")

mkdir -p "deploy/oas/$version/$base"
# Move the jekyll lander markdown for this iteration to the deploy destination.
# The lander files only exist in the gh-pages branch.
if [ ! -z "$jekyllLander" ]; then
mv $jekyllLander $target.md
echo " * $newestCommitDate: $schema & jekyll lander $(basename $jekyllLander)"
else
echo " * $newestCommitDate: $schema"
fi

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

mv deploy/oas/$version/$base/*.md $target.md
done
echo === Building schemas into $deploydir

echo ""
# list of schemas to process, dependent schemas come first
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)

# publish each schema using its or any of its dependencies newest commit date.
maxDate=""
sedCmds=()
for schema in "${schemas[@]}"; do
if [ -f "$schemaDir/$schema" ]; then
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")

# the newest date across a schema and all its dependencies is its date stamp
if [ "$newestCommitDate" \> "$maxDate" ]; then
maxDate=$newestCommitDate
fi

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")

publish_schema "$schema" "$maxDate" $(printf '%s;' "${sedCmds[@]}")
fi
done

echo === Built