-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Schema Publish workflow #4162
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
Merged
Merged
Schema Publish workflow #4162
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: schema-publish | ||
|
||
# author: @ralfhandl | ||
# issue: https://github.com/OAI/OpenAPI-Specification/issues/3715 | ||
|
||
# | ||
# This workflow copies the 3.x schemas to the gh-pages branch | ||
# | ||
|
||
# run this on push to main | ||
on: | ||
push: | ||
branches: | ||
- main | ||
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. |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/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 | ||
|
||
# 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 | ||
|
||
# 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/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 | ||
done | ||
|
||
echo "" | ||
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want each
datesHash["$schema"]
to have$schema
's date, which would be$lastCommitDate
and not$maxDate
? It's not clear to me what$maxDate
is intended to do here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The schemas are visited in the order of their dependency:
meta
changes,dialect
needs to be updated. Ifdialect
itself has changed, its new date is the maximum of the two change dates.dialect
changes,schema
needs to be updated. Ifschema
itself has changed, its new date is the maximum of the two change dates.schema
changes,schema_base
needs to be updated. Ifschema_base
itself has changed, its new date is the maximum of the two change dates.This is what the loop &
$maxDate
do because we currently have a linear dependency chain. If we get more files and non-linear dependencies, this has to be revisited.