Skip to content

Commit 9bd13e9

Browse files
Add a script and action to generate ids for tests
Co-authored-by: Anirudh Jindal <jindalanirudh0@gmail.com>
1 parent e44820e commit 9bd13e9

7 files changed

Lines changed: 572 additions & 1 deletion

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Test IDs
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize]
6+
paths:
7+
- 'tests/**/*.json'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
generate:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Detect changed files
18+
uses: dorny/paths-filter@v3
19+
id: changes
20+
with:
21+
filters: |
22+
other:
23+
- '!tests/**/*.json'
24+
25+
- name: Block mixed changes
26+
if: steps.changes.outputs.other == 'true'
27+
run: |
28+
echo "Tests and other files were changed together."
29+
echo "Please submit test JSON changes separately."
30+
exit 1
31+
32+
- name: Checkout PR branch
33+
uses: actions/checkout@v4
34+
with:
35+
ref: ${{ github.event.pull_request.head.sha }}
36+
37+
- name: Setup Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: latest
41+
42+
- name: Install dependencies
43+
run: npm ci
44+
45+
- name: Generate test IDs
46+
run: |
47+
node scripts/generate-ids-for.js draft2020-12
48+
node scripts/generate-ids-for.js draft2019-09
49+
node scripts/generate-ids-for.js draft7
50+
node scripts/generate-ids-for.js draft6
51+
node scripts/generate-ids-for.js draft4
52+
node scripts/generate-ids-for.js v1
53+
54+
- name: Commit and push
55+
run: |
56+
git config user.name "test-id-bot"
57+
git config user.email "test-id-bot@users.noreply.github.com"
58+
git add tests/
59+
git diff --cached --quiet || git commit -m "chore: auto-add missing test IDs"
60+
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }}.git HEAD:refs/heads/${{ github.event.pull_request.head.ref }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,4 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
node_modules/

package-lock.json

Lines changed: 182 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
{
22
"name": "json-schema-test-suite",
33
"version": "0.1.0",
4+
"type": "module",
45
"description": "A language agnostic test suite for the JSON Schema specifications",
56
"repository": "github:json-schema-org/JSON-Schema-Test-Suite",
67
"keywords": [
78
"json-schema",
89
"tests"
910
],
1011
"author": "http://json-schema.org",
11-
"license": "MIT"
12+
"license": "MIT",
13+
"devDependencies": {
14+
"@hyperjump/browser": "^1.3.1",
15+
"@hyperjump/json-pointer": "^1.1.1",
16+
"@hyperjump/json-schema": "^1.17.4",
17+
"@hyperjump/pact": "^1.4.0",
18+
"@hyperjump/uri": "^1.3.2",
19+
"json-stringify-deterministic": "^1.0.12",
20+
"jsonc-parser": "^3.3.1"
21+
}
1222
}

scripts/generate-ids-for.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { generateIdsFor } from "./utils/test-ids.js";
2+
3+
const version = process.argv[2];
4+
if (!version) {
5+
console.error("Usage: node scripts/generate-ids-for.js <draftXXXX>");
6+
process.exit(1);
7+
}
8+
9+
await generateIdsFor(version);

0 commit comments

Comments
 (0)