From 44a759c6d1ef83fe83d1a623869c69a5fcd7c80f Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Fri, 25 Oct 2024 15:48:53 +0200 Subject: [PATCH 1/5] Publish script --- .github/workflows/schema-publish.yaml | 59 +++++++++++++++++++ .../base.schema.yaml => dialect.yaml} | 0 .../v3.1/{meta/base.schema.yaml => meta.yaml} | 0 scripts/schema-publish.sh | 57 ++++++++++++++++++ scripts/yaml2json/yaml2json.js | 2 +- 5 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/schema-publish.yaml rename schemas/v3.1/{dialect/base.schema.yaml => dialect.yaml} (100%) rename schemas/v3.1/{meta/base.schema.yaml => meta.yaml} (100%) create mode 100755 scripts/schema-publish.sh diff --git a/.github/workflows/schema-publish.yaml b/.github/workflows/schema-publish.yaml new file mode 100644 index 0000000000..e22a910f40 --- /dev/null +++ b/.github/workflows/schema-publish.yaml @@ -0,0 +1,59 @@ +name: schema-publish + +# author: @ralfhandl +# issue: https://github.com/OAI/OpenAPI-Specification/issues/3715 + +# +# This workflow updates the respec 'pretty' rendered versions of the spec +# on the gh-pages branch when the corresponding markdown files change. +# + +# run this on push to main +on: + push: + branches: + - main + - main-schema-publish # remove after testing + workflow_dispatch: {} + +jobs: + publish: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 # checkout main branch + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 # setup Node.js + with: + node-version: '20.x' + + - name: Install dependencies + run: npm ci + + - uses: actions/checkout@v4 # checkout gh-pages branch + with: + ref: gh-pages + path: deploy + + - name: run main script + run: scripts/schema-publish.sh + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: publish-schema-iteration + base: gh-pages + delete-branch: true + path: deploy + labels: Housekeeping,Schema + team-reviewers: OAI/tsc #TODO: check if this works, or if it needs a special access token + title: Publish OpenAPI Metaschema Iterations + commit-message: New OpenAPI metaschema 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. diff --git a/schemas/v3.1/dialect/base.schema.yaml b/schemas/v3.1/dialect.yaml similarity index 100% rename from schemas/v3.1/dialect/base.schema.yaml rename to schemas/v3.1/dialect.yaml diff --git a/schemas/v3.1/meta/base.schema.yaml b/schemas/v3.1/meta.yaml similarity index 100% rename from schemas/v3.1/meta/base.schema.yaml rename to schemas/v3.1/meta.yaml diff --git a/scripts/schema-publish.sh b/scripts/schema-publish.sh new file mode 100755 index 0000000000..67757c7aeb --- /dev/null +++ b/scripts/schema-publish.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# Author: @ralfhandl + +# 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 + + schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml) + + # find the latest commit date for each schema + maxDate="-" + declare -A datesHash + for schema in "${schemas[@]}"; do + if [ -f "$schemaDir/$schema" ]; then + lastCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema") + if [ "$lastCommitDate" \> "$maxDate" ]; then + maxDate=$lastCommitDate + fi + datesHash["$schema"]=$maxDate + echo $schema changed at $lastCommitDate + else + datesHash["$schema"]="-" + fi + done + + # construct sed command + sedCmd=() + for schema in "${schemas[@]}"; do + if [ -f "$schemaDir/$schema" ]; then + base=$(basename "$schema" .yaml) + sedCmd+=("-e s/$base\/WORK-IN-PROGRESS/$base\/${datesHash[$schema]}/g") + fi + done + + # create the date-stamped schemas + for schema in "${schemas[@]}"; do + if [ -f "$schemaDir/$schema" ]; then + base=$(basename "$schema" .yaml) + target=deploy/oas/$version/$base/${datesHash[$schema]} + + mkdir -p "deploy/oas/$version/$base" + + 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 + fi + done + + echo "" +done diff --git a/scripts/yaml2json/yaml2json.js b/scripts/yaml2json/yaml2json.js index f69145ad36..decb075cc7 100755 --- a/scripts/yaml2json/yaml2json.js +++ b/scripts/yaml2json/yaml2json.js @@ -6,7 +6,7 @@ const fs = require('fs'); const yaml = require('yaml'); function convert(filename) { - console.log(filename); + // console.log(filename); const s = fs.readFileSync(filename,'utf8'); let obj; try { From 6a4b0f4417da8011d568784f59713ef44423f753 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Fri, 25 Oct 2024 15:56:44 +0200 Subject: [PATCH 2/5] Update schema-publish.yaml --- .github/workflows/schema-publish.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/schema-publish.yaml b/.github/workflows/schema-publish.yaml index e22a910f40..17b0814bea 100644 --- a/.github/workflows/schema-publish.yaml +++ b/.github/workflows/schema-publish.yaml @@ -13,7 +13,6 @@ on: push: branches: - main - - main-schema-publish # remove after testing workflow_dispatch: {} jobs: From fd5cdc2a92c6370d67e9f43fdc8613d3b46eef78 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Fri, 25 Oct 2024 16:00:49 +0200 Subject: [PATCH 3/5] Update schema-publish.yaml --- .github/workflows/schema-publish.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/schema-publish.yaml b/.github/workflows/schema-publish.yaml index 17b0814bea..4ac83ae88b 100644 --- a/.github/workflows/schema-publish.yaml +++ b/.github/workflows/schema-publish.yaml @@ -4,8 +4,7 @@ name: schema-publish # issue: https://github.com/OAI/OpenAPI-Specification/issues/3715 # -# This workflow updates the respec 'pretty' rendered versions of the spec -# on the gh-pages branch when the corresponding markdown files change. +# This workflow copies the 3.x schemas to the gh-pages branch # # run this on push to main From d687024ce1c048d850e4bc90fff95f0fd924e1b8 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Sat, 26 Oct 2024 12:05:24 +0200 Subject: [PATCH 4/5] Loop over hash keys --- scripts/schema-publish.sh | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/scripts/schema-publish.sh b/scripts/schema-publish.sh index 67757c7aeb..d4ddbfd82f 100755 --- a/scripts/schema-publish.sh +++ b/scripts/schema-publish.sh @@ -12,7 +12,7 @@ for schemaDir in schemas/v3* ; do schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml) # find the latest commit date for each schema - maxDate="-" + maxDate="" declare -A datesHash for schema in "${schemas[@]}"; do if [ -f "$schemaDir/$schema" ]; then @@ -22,35 +22,29 @@ for schemaDir in schemas/v3* ; do fi datesHash["$schema"]=$maxDate echo $schema changed at $lastCommitDate - else - datesHash["$schema"]="-" fi done # construct sed command sedCmd=() - for schema in "${schemas[@]}"; do - if [ -f "$schemaDir/$schema" ]; then - base=$(basename "$schema" .yaml) - sedCmd+=("-e s/$base\/WORK-IN-PROGRESS/$base\/${datesHash[$schema]}/g") - fi + 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 "${schemas[@]}"; do - if [ -f "$schemaDir/$schema" ]; then - base=$(basename "$schema" .yaml) - target=deploy/oas/$version/$base/${datesHash[$schema]} + for schema in "${!datesHash[@]}"; do + base=$(basename "$schema" .yaml) + target=deploy/oas/$version/$base/${datesHash[$schema]} - mkdir -p "deploy/oas/$version/$base" + mkdir -p "deploy/oas/$version/$base" - sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml - node scripts/yaml2json/yaml2json.js $target.yaml - rm $target.yaml - mv $target.json $target + 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 - fi + mv deploy/oas/$version/$base/*.md $target.md done echo "" From 6d04eeb177fbb72c92b167e77812b4ab948c5703 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Tue, 29 Oct 2024 17:27:00 +0100 Subject: [PATCH 5/5] More intuitive variable name, more comments --- scripts/schema-publish.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/schema-publish.sh b/scripts/schema-publish.sh index d4ddbfd82f..d1a7f822bd 100755 --- a/scripts/schema-publish.sh +++ b/scripts/schema-publish.sh @@ -9,19 +9,22 @@ for schemaDir in schemas/v3* ; do 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 latest commit date for each schema + # find the newest commit date for each schema maxDate="" declare -A datesHash for schema in "${schemas[@]}"; do if [ -f "$schemaDir/$schema" ]; then - lastCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema") - if [ "$lastCommitDate" \> "$maxDate" ]; then - maxDate=$lastCommitDate + 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 $lastCommitDate + echo $schema changed at $newestCommitDate fi done