Skip to content

Commit e09c356

Browse files
authored
Merge pull request #4481 from ralfhandl/main-sync-scripts-from-dev
main: port from dev
2 parents 8a3f194 + d53c93c commit e09c356

File tree

5 files changed

+83
-82
lines changed

5 files changed

+83
-82
lines changed

.github/workflows/schema-publish.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ name: schema-publish
44
# issue: https://github.com/OAI/OpenAPI-Specification/issues/3715
55

66
#
7-
# This workflow copies the 3.x schemas to the gh-pages branch
7+
# This workflow creates a pull request for publishing schema iterations to the gh-pages branch
88
#
99

10-
# run this on push to main
10+
# run this on push to vX.Y-dev branches or manually
1111
on:
1212
push:
1313
branches:
14-
- main
14+
- 'v[0-9].[0-9]-dev'
15+
paths:
16+
- 'src/schemas/validation/*.yaml'
17+
- 'scripts/schema-publish.sh'
18+
- '.github/workflows/schema-publish.yaml'
1519
workflow_dispatch: {}
1620

1721
jobs:
@@ -26,7 +30,7 @@ jobs:
2630

2731
- uses: actions/setup-node@v4 # setup Node.js
2832
with:
29-
node-version: '20.x'
33+
node-version: '22.x'
3034

3135
- name: Install dependencies
3236
run: npm ci
@@ -43,15 +47,15 @@ jobs:
4347
uses: peter-evans/create-pull-request@v6
4448
with:
4549
token: ${{ secrets.GITHUB_TOKEN }}
46-
branch: publish-schema-iteration
50+
branch: ${{ github.ref_name }}-publish-schema-iteration
4751
base: gh-pages
4852
delete-branch: true
4953
path: deploy
5054
labels: Housekeeping,Schema
5155
reviewers: darrelmiller,webron,earth2marsh,webron,lornajane,mikekistler,miqui,ralfhandl,handrews,karenetheridge
52-
title: Publish OpenAPI Schema Iterations
56+
title: '${{ github.ref_name }}: publish OpenAPI schema iterations'
5357
commit-message: New OpenAPI schema iterations
5458
signoff: true
5559
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.
60+
This pull request is automatically generated by GitHub action `schema-publish`.
61+
The `src/schemas/validation/*.yaml` files have changed and JSON files are automatically generated.

.github/workflows/validate-markdown.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
node-version: '20.x'
2929

3030
- name: Validate markdown
31-
run: npx --yes mdv versions/3.*.md
31+
run: npx --yes mdv versions/3.*.md src/oas.md
3232

3333
- name: Lint markdown 3.0.4, 3.1.1, and later
34-
run: npx --yes markdownlint-cli --config .markdownlint.yaml versions/3.0.4.md versions/3.1.[^0].md versions/3.[2-9].*.md
34+
run: npx --yes markdownlint-cli --config .markdownlint.yaml versions/3.0.4.md versions/3.1.[^0].md versions/3.[2-9].*.md src/oas.md

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"license": "Apache-2.0",
1515
"scripts": {
1616
"build": "bash ./scripts/md2html/build.sh",
17-
"test": "c8 --100 vitest --watch=false && bash scripts/schema-test-coverage.sh"
17+
"build-src": "npm run validate-markdown && bash ./scripts/md2html/build.sh src && bash ./scripts/schema-publish.sh src",
18+
"test": "c8 --100 vitest --watch=false && bash scripts/schema-test-coverage.sh",
19+
"format-markdown": "bash ./scripts/format-markdown.sh ./src/oas.md",
20+
"validate-markdown": "npx mdv src/oas.md && npx markdownlint-cli src/oas.md"
1821
},
1922
"readmeFilename": "README.md",
2023
"files": [

scripts/schema-publish.sh

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,75 @@
44

55
# Run this script from the root of the repo. It is designed to be run by a GitHub workflow.
66

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
7+
schemaDir="src/schemas/validation"
8+
branch=$(git branch --show-current)
9+
10+
11+
if [ -z "$1" ]; then
12+
if [[ $branch =~ ^v([0-9]+\.[0-9]+)-dev$ ]]; then
13+
deploydir="./deploy/oas/${BASH_REMATCH[1]}"
14+
else
15+
echo "Unable to determine version from branch name; should be vX.Y-dev"
16+
exit 1
17+
fi
18+
elif [ $1 = "src" ]; then
19+
deploydir="./deploy-preview"
20+
else
21+
echo "Unrecognized argument"
22+
exit 1
23+
fi
24+
25+
# create the date-stamped schemas
26+
publish_schema() {
27+
local schema="$1"
28+
local date="$2"
29+
local sedCmd="$3"
30+
31+
local base=$(basename $schema '.yaml')
32+
local target=$deploydir/$base/$date
33+
34+
mkdir -p $deploydir/$base
3035

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
36+
# replace the WORK-IN-PROGRESS placeholders
37+
sed ${sedCmd[@]} $schemaDir/$schema | npx yaml --json --indent 2 --single > $target
3738

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]}
39+
# Find the jekyll lander markdown file for this iteration.
40+
local jekyllLander=$(find "$deploydir/$base" -maxdepth 1 -name "*.md")
4241

43-
mkdir -p "deploy/oas/$version/$base"
42+
# Move the jekyll lander markdown for this iteration to the deploy destination.
43+
# The lander files only exist in the gh-pages branch.
44+
if [ ! -z "$jekyllLander" ]; then
45+
mv $jekyllLander $target.md
46+
echo " * $newestCommitDate: $schema & jekyll lander $(basename $jekyllLander)"
47+
else
48+
echo " * $newestCommitDate: $schema"
49+
fi
4450

45-
sed ${sedCmd[@]} $schemaDir/$schema > $target.yaml
46-
node scripts/yaml2json/yaml2json.js $target.yaml
47-
rm $target.yaml
48-
mv $target.json $target
51+
}
4952

50-
mv deploy/oas/$version/$base/*.md $target.md
51-
done
53+
echo === Building schemas into $deploydir
5254

53-
echo ""
55+
# list of schemas to process, dependent schemas come first
56+
schemas=(meta.yaml dialect.yaml schema.yaml schema-base.yaml)
57+
58+
# publish each schema using its or any of its dependencies newest commit date.
59+
maxDate=""
60+
sedCmds=()
61+
for schema in "${schemas[@]}"; do
62+
if [ -f "$schemaDir/$schema" ]; then
63+
newestCommitDate=$(git log -1 --format="%ad" --date=short "$schemaDir/$schema")
64+
65+
# the newest date across a schema and all its dependencies is its date stamp
66+
if [ "$newestCommitDate" \> "$maxDate" ]; then
67+
maxDate=$newestCommitDate
68+
fi
69+
70+
base=$(basename $schema '.yaml')
71+
# Add the replacement for this schema's placeholder to list of sed commands.
72+
sedCmds+=("s/${base}\/WORK-IN-PROGRESS/${base}\/${maxDate}/g")
73+
74+
publish_schema "$schema" "$maxDate" $(printf '%s;' "${sedCmds[@]}")
75+
fi
5476
done
77+
78+
echo === Built

scripts/yaml2json/yaml2json.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)