Skip to content

Commit 44a759c

Browse files
committed
Publish script
1 parent cc25d27 commit 44a759c

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed

.github/workflows/schema-publish.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: schema-publish
2+
3+
# author: @ralfhandl
4+
# issue: https://github.com/OAI/OpenAPI-Specification/issues/3715
5+
6+
#
7+
# This workflow updates the respec 'pretty' rendered versions of the spec
8+
# on the gh-pages branch when the corresponding markdown files change.
9+
#
10+
11+
# run this on push to main
12+
on:
13+
push:
14+
branches:
15+
- main
16+
- main-schema-publish # remove after testing
17+
workflow_dispatch: {}
18+
19+
jobs:
20+
publish:
21+
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v4 # checkout main branch
26+
with:
27+
fetch-depth: 0
28+
29+
- uses: actions/setup-node@v4 # setup Node.js
30+
with:
31+
node-version: '20.x'
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- uses: actions/checkout@v4 # checkout gh-pages branch
37+
with:
38+
ref: gh-pages
39+
path: deploy
40+
41+
- name: run main script
42+
run: scripts/schema-publish.sh
43+
44+
- name: Create Pull Request
45+
uses: peter-evans/create-pull-request@v6
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
branch: publish-schema-iteration
49+
base: gh-pages
50+
delete-branch: true
51+
path: deploy
52+
labels: Housekeeping,Schema
53+
team-reviewers: OAI/tsc #TODO: check if this works, or if it needs a special access token
54+
title: Publish OpenAPI Metaschema Iterations
55+
commit-message: New OpenAPI metaschema iterations
56+
signoff: true
57+
body: |
58+
This pull request is automatically triggered by GitHub action `schema-publish`.
59+
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)
13+
14+
# find the latest commit date for each schema
15+
maxDate="-"
16+
declare -A datesHash
17+
for schema in "${schemas[@]}"; do
18+
if [ -f "$schemaDir/$schema" ]; then
19+
lastCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")
20+
if [ "$lastCommitDate" \> "$maxDate" ]; then
21+
maxDate=$lastCommitDate
22+
fi
23+
datesHash["$schema"]=$maxDate
24+
echo $schema changed at $lastCommitDate
25+
else
26+
datesHash["$schema"]="-"
27+
fi
28+
done
29+
30+
# construct sed command
31+
sedCmd=()
32+
for schema in "${schemas[@]}"; do
33+
if [ -f "$schemaDir/$schema" ]; then
34+
base=$(basename "$schema" .yaml)
35+
sedCmd+=("-e s/$base\/WORK-IN-PROGRESS/$base\/${datesHash[$schema]}/g")
36+
fi
37+
done
38+
39+
# create the date-stamped schemas
40+
for schema in "${schemas[@]}"; do
41+
if [ -f "$schemaDir/$schema" ]; then
42+
base=$(basename "$schema" .yaml)
43+
target=deploy/oas/$version/$base/${datesHash[$schema]}
44+
45+
mkdir -p "deploy/oas/$version/$base"
46+
47+
sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml
48+
node scripts/yaml2json/yaml2json.js $target.yaml
49+
rm $target.yaml
50+
mv $target.json $target
51+
52+
mv deploy/oas/$version/$base/*.md $target.md
53+
fi
54+
done
55+
56+
echo ""
57+
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)