Skip to content

Commit 46f5725

Browse files
committed
accept upstream changes and simplyfying apply-test-ids.yml
2 parents ab25581 + 470010d commit 46f5725

File tree

97 files changed

+2354
-786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2354
-786
lines changed
Lines changed: 29 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: apply-test-ids
1+
name: Test IDs
22

33
on:
44
pull_request_target:
@@ -8,145 +8,63 @@ on:
88

99
permissions:
1010
contents: write
11-
pull-requests: write
1211

1312
jobs:
14-
apply:
13+
generate:
1514
runs-on: ubuntu-latest
1615

1716
steps:
18-
# 1. Detect what changed in this PR
19-
- name: Check changed paths
17+
- name: Detect changed files
2018
uses: dorny/paths-filter@v3
21-
id: filter
19+
id: changes
2220
with:
2321
filters: |
2422
tests:
2523
- 'tests/**/*.json'
26-
scripts:
27-
- 'scripts/**'
28-
- 'package.json'
29-
- 'package-lock.json'
24+
other:
25+
- '!tests/**/*.json'
3026
31-
# 2. Fail if both tests AND scripts changed together
3227
- name: Block mixed changes
33-
if: steps.filter.outputs.tests == 'true' && steps.filter.outputs.scripts == 'true'
28+
if: steps.changes.outputs.tests == 'true' && steps.changes.outputs.other == 'true'
3429
run: |
35-
echo "This PR changes both test files and scripts at the same time."
36-
echo "Please split them into separate PRs."
30+
echo "Tests and other files were changed together."
31+
echo "Please submit test JSON changes separately."
3732
exit 1
3833
39-
# 3. Checkout repo
40-
- name: Checkout
41-
if: steps.filter.outputs.tests == 'true'
34+
- name: Checkout PR branch
35+
if: steps.changes.outputs.tests == 'true'
4236
uses: actions/checkout@v4
4337
with:
4438
ref: ${{ github.event.pull_request.head.sha }}
45-
fetch-depth: 0
4639

47-
# 4. Setup Node.js
4840
- name: Setup Node.js
49-
if: steps.filter.outputs.tests == 'true'
41+
if: steps.changes.outputs.tests == 'true'
5042
uses: actions/setup-node@v4
5143
with:
52-
node-version: 18
44+
node-version: 20
5345

54-
# 5. Install dependencies
5546
- name: Install dependencies
56-
if: steps.filter.outputs.tests == 'true'
47+
if: steps.changes.outputs.tests == 'true'
5748
run: npm ci
5849

59-
# 6. Fetch list of files changed in this PR
60-
- name: Get changed test files
61-
if: steps.filter.outputs.tests == 'true'
62-
env:
63-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
- name: Generate test IDs
51+
if: steps.changes.outputs.tests == 'true'
6452
run: |
65-
curl -s \
66-
-H "Authorization: Bearer $GITHUB_TOKEN" \
67-
"${{ github.event.pull_request.url }}/files?per_page=100" \
68-
| jq -r ".[].filename" \
69-
> changed-files.txt
70-
71-
grep -E "^tests/(draft[^/]+)/.*\.json$" changed-files.txt \
72-
| sed -E "s|^tests/([^/]+)/.*|\1|" \
73-
| sort -u \
74-
> affected-drafts.txt
75-
76-
# 7. Run add-test-ids.js for each changed file
77-
- name: Apply missing test IDs
78-
if: steps.filter.outputs.tests == 'true'
79-
env:
80-
CI: "false"
53+
node scripts/generate-ids-for.js draft2020-12
54+
node scripts/generate-ids-for.js draft2019-09
55+
node scripts/generate-ids-for.js draft7
56+
node scripts/generate-ids-for.js draft6
57+
node scripts/generate-ids-for.js draft4
58+
node scripts/generate-ids-for.js v1
59+
60+
- name: Commit and push
61+
if: steps.changes.outputs.tests == 'true'
8162
run: |
82-
if [ ! -s affected-drafts.txt ]; then
83-
echo "No test JSON files changed - nothing to do."
84-
exit 0
85-
fi
86-
87-
while IFS= read -r draft; do
88-
echo "Processing dialect: $draft"
89-
grep -E "^tests/${draft}/.*\.json$" changed-files.txt | while IFS= read -r file; do
90-
if [ -f "$file" ]; then
91-
echo " -> $file"
92-
node scripts/add-test-ids.js "$draft" "$file"
93-
fi
94-
done
95-
done < affected-drafts.txt
96-
97-
# 8. Commit and push back to the PR branch
98-
- name: Commit and push changes
99-
if: steps.filter.outputs.tests == 'true'
100-
env:
101-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102-
run: |
103-
git config user.name "test-id-bot"
63+
git config user.name "test-id-bot"
10464
git config user.email "test-id-bot@users.noreply.github.com"
10565
106-
git add "tests/**/*.json"
107-
108-
if git diff --cached --quiet; then
109-
echo "No test ID changes needed - nothing to commit."
110-
echo "CHANGES_MADE=false" >> $GITHUB_ENV
111-
else
112-
SUMMARY=""
113-
TOTAL=0
114-
while IFS= read -r file; do
115-
COUNT=$(git diff --cached -- "$file" | grep "^+" | grep '"id":' | wc -l | tr -d " ")
116-
if [ "$COUNT" -gt 0 ]; then
117-
SUMMARY="${SUMMARY}\n- \`${file}\` - **${COUNT}** ID(s) added"
118-
TOTAL=$((TOTAL + COUNT))
119-
fi
120-
done < <(git diff --cached --name-only)
121-
122-
printf "%b" "$SUMMARY" > /tmp/summary.txt
123-
echo "TOTAL_IDS=${TOTAL}" >> $GITHUB_ENV
124-
125-
git commit -m "chore: auto-add missing test IDs"
126-
127-
COMMIT_SHA=$(git rev-parse HEAD)
128-
echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_ENV
129-
130-
git push \
131-
https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.event.pull_request.head.repo.full_name }}.git \
132-
HEAD:refs/heads/${{ github.event.pull_request.head.ref }}
133-
134-
echo "CHANGES_MADE=true" >> $GITHUB_ENV
135-
fi
136-
137-
# 9. Post a summary comment on the PR
138-
- name: Post PR comment
139-
if: env.CHANGES_MADE == 'true'
140-
env:
141-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142-
run: |
143-
SUMMARY=$(cat /tmp/summary.txt)
144-
COMMIT_URL="https://github.com/${{ github.event.pull_request.head.repo.full_name }}/commit/${COMMIT_SHA}"
66+
git add $(find tests -name "*.json" ! -type l)
14567
146-
BODY="### test-id-bot added ${TOTAL_IDS} missing test ID(s)\n\n${SUMMARY}\n\nView the full diff of added IDs: ${COMMIT_URL}\n\n> IDs are deterministic hashes based on the schema, test data, and expected result."
68+
git diff --cached --quiet || git commit -m "chore: auto-add missing test IDs"
14769
148-
curl -s -X POST \
149-
-H "Authorization: Bearer $GITHUB_TOKEN" \
150-
-H "Content-Type: application/json" \
151-
"${{ github.event.pull_request.comments_url }}" \
152-
--data "$(jq -n --arg body "$(printf '%b' "$BODY")" '{body: $body}')"
70+
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 }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Test IDs
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
generate:
7+
runs-on: ubuntu-latest
8+
9+
permissions:
10+
contents: write
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
repository: ${{ github.event.pull_request.head.repo.full_name }}
17+
ref: ${{ github.event.pull_request.head.ref }} # Check out the PR branch, not the merge commit
18+
fetch-depth: 0
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: latest
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
# - name: Generate test IDs for v1
29+
# run: node scripts/generate-ids-for.js v1
30+
#
31+
# - name: Generate test IDs for draft2020-12
32+
# run: node scripts/generate-ids-for.js draft2020-12
33+
#
34+
# - name: Generate test IDs for draft2019-09
35+
# run: node scripts/generate-ids-for.js draft2019-09
36+
#
37+
# - name: Generate test IDs for draft7
38+
# run: node scripts/generate-ids-for.js draft7
39+
#
40+
# - name: Generate test IDs for draft6
41+
# run: node scripts/generate-ids-for.js draft6
42+
#
43+
# - name: Generate test IDs for draft4
44+
# run: node scripts/generate-ids-for.js draft4
45+
46+
- name: Commit and push changes
47+
run: |
48+
git config user.name "test-id-action"
49+
git config user.email "test-id-action@users.noreply.github.com"
50+
git add "tests/**/*.json"
51+
git commit -m "Update test IDs based on the schema, test data, and expected result." || echo "No changes to commit"
52+
git push origin ${{ github.event.pull_request.head.ref }}

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![Build Status](https://github.com/json-schema-org/JSON-Schema-Test-Suite/workflows/Test%20Suite%20Sanity%20Checking/badge.svg)](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22)
99

1010
This repository contains a set of JSON objects that implementers of JSON Schema validation libraries can use to test their validators.
11+
The test suite repository exists to verify specified behavior defined by the JSON Schema specification and should not be confused with a style guide. It is not intended to demonstrate how schemas ought to be written. Tests may appear unusual or unintuitive, but they exist solely to exercise behavior prescribed by the specification.
1112

1213
It is meant to be language agnostic and should require only a JSON parser.
1314
The conversion of the JSON objects into tests within a specific language and test framework of choice is left to be done by the validator implementer.
@@ -79,15 +80,13 @@ Here is a single *test case*, containing one or more tests:
7980

8081
### Subdirectories Within Each Version directory
8182

82-
There is currently only one additional subdirectory that may exist within each specification version test directory.
83+
A specification version test directory may contain one or more subdirectories.
8384

84-
This is:
85+
These are:
8586

86-
1. `optional/`: Contains tests that are considered optional.
87+
1. `optional/`: Contains tests that are considered optional. Note that this subdirectory currently conflates many reasons why a test may be optional -- it may be because tests within a particular file are indeed not required by the specification but still potentially useful to an implementer, or it may be because tests within it only apply to programming languages with particular functionality (in which case they are not truly optional in such a language). In the future this directory structure will be made richer to reflect these differences more clearly.
8788

88-
Note, the `optional/` subdirectory today conflates many reasons why a test may be optional -- it may be because tests within a particular file are indeed not required by the specification but still potentially useful to an implementer, or it may be because tests within it only apply to programming languages with particular functionality (in
89-
which case they are not truly optional in such a language).
90-
In the future this directory structure will be made richer to reflect these differences more clearly.
89+
2. `proposals/`: Contains a subfolder for each active proposal to the specification. If the proposal is a keyword (generally the case), then the subfolder will bear the name of that keyword. Inside the proposal subfolder is a series of test files that would contain amendments to the required test suite should the proposal be incorporated into the specification. These test should be considered volitile while the proposal is in development, however implementations claiming to support the proposal are expected to pass its tests.
9190

9291
## Using the Suite to Test a Validator Implementation
9392

@@ -215,6 +214,7 @@ This suite is being used by:
215214

216215
* [jinx](https://github.com/juxt/jinx)
217216
* [json-schema](https://github.com/tatut/json-schema)
217+
* [M3](https://github.com/JulesGosnell/m3) (all drafts, pure Clojure — also usable from Java, Kotlin, Scala, and JavaScript)
218218

219219
### Coffeescript
220220

@@ -262,6 +262,7 @@ This suite is being used by:
262262
* [Snow](https://github.com/ssilverman/snowy-json)
263263
* [jsonschemafriend](https://github.com/jimblackler/jsonschemafriend)
264264
* [OpenAPI JSON Schema Generator](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator)
265+
* [M3](https://github.com/JulesGosnell/m3) (all drafts, pure Clojure — also usable from Kotlin, Scala, and JavaScript)
265266

266267
### JavaScript
267268

@@ -280,10 +281,17 @@ This suite is being used by:
280281
* [jsen](https://github.com/bugventure/jsen)
281282
* [ajv](https://github.com/epoberezkin/ajv)
282283
* [djv](https://github.com/korzio/djv)
284+
* [M3](https://github.com/JulesGosnell/m3) (all drafts, pure Clojure — also usable from Java, Kotlin, and Scala)
283285

284286
### Kotlin
285287

286288
* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations)
289+
* [kotlinx-schema](https://github.com/Kotlin/kotlinx-schema)
290+
* [M3](https://github.com/JulesGosnell/m3) (all drafts, pure Clojure — also usable from Java, Scala, and JavaScript)
291+
292+
### Lua
293+
294+
* [lua-schema](https://framagit.org/fperrad/lua-schema)
287295

288296
### Node.js
289297

@@ -334,13 +342,17 @@ Node-specific support is maintained in a [separate repository](https://github.co
334342
### Scala
335343

336344
* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations)
337-
* [typed-json](https://github.com/frawa/typed-json)
345+
* [M3](https://github.com/JulesGosnell/m3) (all drafts, pure Clojure — also usable from Java, Kotlin, and JavaScript)
338346

339347
### Swift
340348

341349
* [JSONSchema](https://github.com/kylef/JSONSchema.swift)
342350
* [swift-json-schema](https://github.com/ajevans99/swift-json-schema)
343351

352+
### Unison
353+
354+
* [typed-json](https://share.unison-lang.org/@frawa/typed-json)
355+
344356
If you use it as well, please fork and send a pull request adding yourself to
345357
the list :).
346358

0 commit comments

Comments
 (0)