Skip to content

Commit 7e96988

Browse files
authored
Merge pull request #4162 from ralfhandl/main-schema-publish
Schema Publish workflow
2 parents b980078 + 6d04eeb commit 7e96988

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

.github/workflows/schema-publish.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: schema-publish
2+
3+
# author: @ralfhandl
4+
# issue: https://github.com/OAI/OpenAPI-Specification/issues/3715
5+
6+
#
7+
# This workflow copies the 3.x schemas to the gh-pages branch
8+
#
9+
10+
# run this on push to main
11+
on:
12+
push:
13+
branches:
14+
- main
15+
workflow_dispatch: {}
16+
17+
jobs:
18+
publish:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4 # checkout main branch
24+
with:
25+
fetch-depth: 0
26+
27+
- uses: actions/setup-node@v4 # setup Node.js
28+
with:
29+
node-version: '20.x'
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- uses: actions/checkout@v4 # checkout gh-pages branch
35+
with:
36+
ref: gh-pages
37+
path: deploy
38+
39+
- name: run main script
40+
run: scripts/schema-publish.sh
41+
42+
- name: Create Pull Request
43+
uses: peter-evans/create-pull-request@v6
44+
with:
45+
token: ${{ secrets.GITHUB_TOKEN }}
46+
branch: publish-schema-iteration
47+
base: gh-pages
48+
delete-branch: true
49+
path: deploy
50+
labels: Housekeeping,Schema
51+
team-reviewers: OAI/tsc #TODO: check if this works, or if it needs a special access token
52+
title: Publish OpenAPI Metaschema Iterations
53+
commit-message: New OpenAPI metaschema iterations
54+
signoff: true
55+
body: |
56+
This pull request is automatically triggered by GitHub action `schema-publish`.
57+
The `schemas/**/*.yaml` files have changed and JSON files are automatically generated.
File renamed without changes.
File renamed without changes.

scripts/schema-publish.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
# Author: @ralfhandl
4+
5+
# Run this script from the root of the repo. It is designed to be run by a GitHub workflow.
6+
7+
for schemaDir in schemas/v3* ; do
8+
vVersion=$(basename "$schemaDir")
9+
version=${vVersion:1}
10+
echo $version
11+
12+
# list of schemas to process, dependent schemas come first
13+
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)
14+
15+
# find the newest commit date for each schema
16+
maxDate=""
17+
declare -A datesHash
18+
for schema in "${schemas[@]}"; do
19+
if [ -f "$schemaDir/$schema" ]; then
20+
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")
21+
22+
# the newest date across a schema and all its dependencies is its date stamp
23+
if [ "$newestCommitDate" \> "$maxDate" ]; then
24+
maxDate=$newestCommitDate
25+
fi
26+
datesHash["$schema"]=$maxDate
27+
echo $schema changed at $newestCommitDate
28+
fi
29+
done
30+
31+
# construct sed command
32+
sedCmd=()
33+
for schema in "${!datesHash[@]}"; do
34+
base=$(basename "$schema" .yaml)
35+
sedCmd+=("-e s/$base\/WORK-IN-PROGRESS/$base\/${datesHash[$schema]}/g")
36+
done
37+
38+
# create the date-stamped schemas
39+
for schema in "${!datesHash[@]}"; do
40+
base=$(basename "$schema" .yaml)
41+
target=deploy/oas/$version/$base/${datesHash[$schema]}
42+
43+
mkdir -p "deploy/oas/$version/$base"
44+
45+
sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml
46+
node scripts/yaml2json/yaml2json.js $target.yaml
47+
rm $target.yaml
48+
mv $target.json $target
49+
50+
mv deploy/oas/$version/$base/*.md $target.md
51+
done
52+
53+
echo ""
54+
done

scripts/yaml2json/yaml2json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const fs = require('fs');
66
const yaml = require('yaml');
77

88
function convert(filename) {
9-
console.log(filename);
9+
// console.log(filename);
1010
const s = fs.readFileSync(filename,'utf8');
1111
let obj;
1212
try {

0 commit comments

Comments
 (0)