-
-
Notifications
You must be signed in to change notification settings - Fork 44
211 lines (171 loc) · 7.82 KB
/
sync-schemastore.yml
File metadata and controls
211 lines (171 loc) · 7.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: Sync SchemaStore
on:
# Run after successful release
workflow_run:
workflows: ["Release"]
types:
- completed
# Manual trigger for testing
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run mode (compare only, no PR)'
required: false
default: false
type: boolean
permissions:
contents: read
jobs:
sync:
name: Sync schema to SchemaStore
runs-on: ubuntu-latest
# Only run if release succeeded (or manual trigger)
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout rumdl
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Fetch SchemaStore schema
id: fetch
run: |
# Fetch current SchemaStore schema
curl -s https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/rumdl.json > schemastore-current.json
# Check if fetch succeeded
if [ ! -s schemastore-current.json ]; then
echo "Failed to fetch SchemaStore schema"
exit 1
fi
echo "Fetched SchemaStore schema"
- name: Generate SchemaStore-compatible schema
run: |
# Convert local schema to SchemaStore format:
# - Use draft-07 (SchemaStore standard)
# - Use "definitions" instead of "$defs"
# - Set proper $id
jq '
# Convert $defs to definitions
if has("$defs") then
.definitions = .["$defs"] | del(.["$defs"])
else
.
end |
# Update $ref paths
walk(if type == "string" and startswith("#/$defs/") then sub("#/\\$defs/"; "#/definitions/") else . end) |
# Remove non-standard "format" fields (e.g., "uint" from schemars)
walk(if type == "object" and .format == "uint" then del(.format) else . end) |
# Set SchemaStore metadata
.["$schema"] = "http://json-schema.org/draft-07/schema#" |
.["$id"] = "https://json.schemastore.org/rumdl.json"
' rumdl.schema.json > rumdl-schemastore.json
echo "Generated SchemaStore-compatible schema"
- name: Compare schemas
id: compare
run: |
# Compare converted local schema with SchemaStore (both now in same format)
LOCAL_FLAVORS=$(jq -r '.definitions.MarkdownFlavor.enum | sort | join(",")' rumdl-schemastore.json)
REMOTE_FLAVORS=$(jq -r '.definitions.MarkdownFlavor.enum | sort | join(",")' schemastore-current.json)
echo "Local flavors: $LOCAL_FLAVORS"
echo "Remote flavors: $REMOTE_FLAVORS"
# Normalize both for comparison (sorted keys, ignore whitespace)
jq -S '.' rumdl-schemastore.json > local-normalized.json
jq -S '.' schemastore-current.json > remote-normalized.json
if diff -q local-normalized.json remote-normalized.json > /dev/null 2>&1; then
echo "schemas_match=true" >> "$GITHUB_OUTPUT"
echo "✅ Schemas are in sync"
else
echo "schemas_match=false" >> "$GITHUB_OUTPUT"
echo "❌ Schemas differ"
echo ""
echo "=== Key differences ==="
# Show flavor differences specifically
echo "Flavor differences:"
diff <(jq -r '.definitions.MarkdownFlavor.enum[]' schemastore-current.json | sort) \
<(jq -r '.definitions.MarkdownFlavor.enum[]' rumdl-schemastore.json | sort) || true
fi
- name: Create PR to SchemaStore
if: steps.compare.outputs.schemas_match == 'false' && inputs.dry_run != true
env:
GH_TOKEN: ${{ secrets.SCHEMASTORE_PAT }}
run: |
set -euo pipefail
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
BRANCH="rumdl-schema-update"
# Always sync fork with upstream for clean base
echo "Syncing fork with upstream..."
gh repo sync rvben/schemastore --source SchemaStore/schemastore --force
# Check for existing PR (to decide whether to create one later)
EXISTING_PR_NUM=$(gh pr list --repo SchemaStore/schemastore --author rvben --head "rvben:${BRANCH}" --state open --json number --jq '.[0].number // empty')
# Clone fork
git clone "https://x-access-token:${GH_TOKEN}@github.com/rvben/schemastore.git" schemastore-repo
cd schemastore-repo
# Always create/reset branch from master for clean history
git checkout -B "${BRANCH}" origin/master
# Install dependencies first (Prettier needs prettier-plugin-sort-json)
npm ci
# Copy schema
cp ../rumdl-schemastore.json src/schemas/json/rumdl.json
# Format with Prettier to match SchemaStore's pre-commit hooks
npx prettier --write src/schemas/json/rumdl.json
# Check for actual changes vs master
if git diff --quiet HEAD -- src/schemas/json/rumdl.json; then
echo "✅ Schema matches master, nothing to do"
exit 0
fi
# Validate schema
echo "Running SchemaStore validation..."
if ! node cli.js check --schema-name=rumdl.json; then
echo "❌ Schema validation failed"
exit 1
fi
echo "✅ Schema validation passed"
# Generate changelog
OLD_FLAVORS=$(jq -r '.definitions.MarkdownFlavor.enum // [] | sort | join(", ")' ../schemastore-current.json)
NEW_FLAVORS=$(jq -r '.definitions.MarkdownFlavor.enum // [] | sort | join(", ")' src/schemas/json/rumdl.json)
CHANGELOG="- Synced with upstream rumdl schema"
if [ "$OLD_FLAVORS" != "$NEW_FLAVORS" ]; then
CHANGELOG="- Updated MarkdownFlavor enum: \`${NEW_FLAVORS}\`"
fi
# Commit and push
git add src/schemas/json/rumdl.json
git commit -m "feat(rumdl): update schema to v${VERSION}"
git push origin "${BRANCH}" --force
# Create PR only if none exists
if [ -n "$EXISTING_PR_NUM" ]; then
echo "✅ Updated existing PR #${EXISTING_PR_NUM}"
exit 0
fi
PR_BODY="Updates the rumdl JSON schema to v${VERSION}.
## Changes
${CHANGELOG}
## Validation
- Schema passes \`node cli.js check --schema-name=rumdl.json\`
## Source
- Schema source: https://github.com/rvben/rumdl/blob/main/rumdl.schema.json
- Release: https://github.com/rvben/rumdl/releases/tag/v${VERSION}
---
*This PR was automatically generated by the [rumdl release workflow](https://github.com/rvben/rumdl/blob/main/.github/workflows/sync-schemastore.yml).*"
gh pr create \
--repo SchemaStore/schemastore \
--head "rvben:${BRANCH}" \
--title "feat(rumdl): update schema to v${VERSION}" \
--body "$PR_BODY"
echo "✅ Created PR to SchemaStore"
- name: Dry run summary
if: steps.compare.outputs.schemas_match == 'false' && inputs.dry_run == true
run: |
echo "## 🧪 Dry Run Summary"
echo ""
echo "Would create PR to SchemaStore with:"
echo ""
echo "### Schema changes:"
diff schemastore-current.json rumdl-schemastore.json || true
echo ""
echo "To create the PR, run this workflow without dry_run mode."
- name: Already in sync
if: steps.compare.outputs.schemas_match == 'true'
run: |
echo "✅ SchemaStore is already in sync with local schema"
echo "No action needed."