diff --git a/.github/workflows/schema-publish.yaml b/.github/workflows/schema-publish.yaml index 0206ef56fa..568990ea6e 100644 --- a/.github/workflows/schema-publish.yaml +++ b/.github/workflows/schema-publish.yaml @@ -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: @@ -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 @@ -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. diff --git a/scripts/schema-publish.sh b/scripts/schema-publish.sh index d1a7f822bd..54d55fc80f 100755 --- a/scripts/schema-publish.sh +++ b/scripts/schema-publish.sh @@ -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