-
Notifications
You must be signed in to change notification settings - Fork 111
Add versioned schemas and PR validation for index.json files #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jormundur00
wants to merge
9
commits into
master
Choose a base branch
from
jormundur00/gh-813
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c6f75d4
Add initial schemas
jormundur00 ed195f7
Add initial test index schemas, and move and add version to library-a…
jormundur00 ca796fe
Improve examples
jormundur00 8c81587
Move schemas directory to the project root
jormundur00 c2877e0
Package schemas with GraalVM Reachability Metadata releases
jormundur00 a7805bd
Remove unused schema and fix action.yml typo
jormundur00 fb13318
Add schema validation workflow and update detect-file-changes github …
jormundur00 89f8e23
Use gradle task when collecting changed file list
jormundur00 edf77b7
Code cleanup
jormundur00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| name: "Validate index.json files" | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| validate-json: | ||
| name: "📋 Validate changed JSON files" | ||
| runs-on: ubuntu-22.04 | ||
| timeout-minutes: 10 | ||
|
|
||
| steps: | ||
| - name: "☁️ Checkout repository" | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: "🔎 Detect relevant file changes" | ||
| id: filter | ||
| uses: ./.github/actions/detect-file-changes | ||
| with: | ||
| file-patterns: | | ||
| - 'metadata/index.json' | ||
| - 'metadata/*/*/index.json' | ||
| - 'tests/src/index.json' | ||
| - 'tests/src/*/*/*/index.json' | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: "Setup Python" | ||
| if: steps.filter.outputs.changed == 'true' | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: "Install validation tools" | ||
| if: steps.filter.outputs.changed == 'true' | ||
| run: | | ||
| pip install jq check-jsonschema | ||
|
|
||
| - name: "Check that the changed index.json files conform to their schemas" | ||
| if: steps.filter.outputs.changed == 'true' | ||
| run: | | ||
| set -e | ||
|
|
||
| # Treat changed_files as a proper array | ||
| FILES=(${{ steps.filter.outputs.changed_files }}) | ||
|
|
||
| # Track failures | ||
| FAILURES=() | ||
|
|
||
| for FILE in "${FILES[@]}"; do | ||
|
|
||
| # Determine schema for each file | ||
| if [[ "$FILE" == "metadata/index.json" ]]; then | ||
| SCHEMA="schemas/metadata-root-index-schema-v1.0.0.json" | ||
| elif [[ "$FILE" == metadata/*/*/index.json ]]; then | ||
| SCHEMA="schemas/metadata-library-index-schema-v1.0.0.json" | ||
| elif [[ "$FILE" == "tests/src/index.json" ]]; then | ||
| SCHEMA="schemas/tests-root-index-schema-v1.0.0.json" | ||
| elif [[ "$FILE" == tests/src/*/*/*/index.json ]]; then | ||
| SCHEMA="schemas/tests-project-index-schema-v1.0.0.json" | ||
| else | ||
| echo "ℹ️ Skipping: $FILE (no schema mapping)" | ||
| continue | ||
| fi | ||
|
|
||
| echo "🔍 Validating $FILE using $SCHEMA" | ||
|
|
||
| # Step 1: Check JSON well-formedness | ||
| if ! jq -e . "$FILE" >/dev/null; then | ||
| echo "❌ $FILE is not valid JSON" | ||
| FAILURES+=("$FILE (invalid JSON)") | ||
| continue | ||
| fi | ||
|
|
||
| # Step 2: Validate against schema | ||
| if ! check-jsonschema --schemafile "$SCHEMA" "$FILE"; then | ||
| FAILURES+=("$FILE (schema validation failed)") | ||
| continue | ||
| fi | ||
|
|
||
| echo "✅ $FILE validated successfully" | ||
| done | ||
|
|
||
| # Fail at the end if any errors occurred | ||
| if [ ${#FAILURES[@]} -ne 0 ]; then | ||
| echo "::error ::Some files failed validation:" | ||
| for f in "${FAILURES[@]}"; do | ||
| echo "::error :: $f" | ||
| done | ||
| exit 1 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| { | ||
| "$id": "https://github.com/oracle/graalvm-reachability-metadata/schemas/metadata-library-index.schema.json", | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "description": "Schema for metadata/<groupId>/<artifactId>/index.json. Each entry describes a metadata bundle for a range of library versions.", | ||
| "type": "array", | ||
| "minItems": 1, | ||
| "items": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": [ | ||
| "module", | ||
| "metadata-version", | ||
| "tested-versions" | ||
| ], | ||
| "properties": { | ||
| "module": { | ||
| "$ref": "#/$defs/moduleCoordinate", | ||
| "description": "Maven coordinates in the form '<groupId>:<artifactId>'." | ||
| }, | ||
| "metadata-version": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "Subdirectory name where the metadata files for this entry reside, e.g. '7.1.0.Final'." | ||
| }, | ||
| "tested-versions": { | ||
| "type": "array", | ||
| "description": "Explicitly tested upstream library versions that this metadata is known to support.", | ||
| "minItems": 1, | ||
| "uniqueItems": true, | ||
| "items": { | ||
| "type": "string", | ||
| "minLength": 1 | ||
| } | ||
| }, | ||
| "latest": { | ||
| "type": "boolean", | ||
| "description": "Marks this entry as the latest/default metadata for currently supported versions." | ||
| }, | ||
| "default-for": { | ||
| "type": "string", | ||
| "description": "Java regular expression describing the version range for which this entry should be used by default (e.g. '7\\\\.1\\\\..*')." | ||
| }, | ||
| "override": { | ||
| "type": "boolean", | ||
| "description": "When true, expresses the intent to exclude outdated built-in metadata shipped with Native Image for the matched versions." | ||
| }, | ||
| "skipped-versions": { | ||
| "type": "array", | ||
| "description": "Versions explicitly excluded from support, each with a reason.", | ||
| "minItems": 1, | ||
| "items": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": [ "version", "reason" ], | ||
| "properties": { | ||
| "version": { | ||
| "type": "string", | ||
| "minLength": 1 | ||
| }, | ||
| "reason": { | ||
| "type": "string", | ||
| "minLength": 1 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "$defs": { | ||
| "moduleCoordinate": { | ||
| "type": "string", | ||
| "pattern": "^[^:]+:[^:]+$" | ||
| } | ||
| }, | ||
| "examples": [ | ||
| [ | ||
| { | ||
| "metadata-version": "0.0.1", | ||
| "module": "org.example:library", | ||
| "tested-versions": [ "0.0.1", "0.0.2" ], | ||
| "default-for": "0\\.0\\..*" | ||
| }, | ||
| { | ||
| "latest": true, | ||
| "metadata-version": "1.0.0", | ||
| "module": "org.example:library", | ||
| "tested-versions": [ "1.0.0", "1.1.0-M1", "1.1.0" ] | ||
| }, | ||
| { | ||
| "metadata-version": "1.19.0", | ||
| "module": "io.opentelemetry:opentelemetry-exporter-logging", | ||
| "tested-versions": [ "1.19.0" ], | ||
| "override": true, | ||
| "skipped-versions": [ | ||
| { "version": "1.0.5", "reason": "Known incompatible API change." } | ||
| ] | ||
| } | ||
| ] | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| { | ||
| "$id": "https://github.com/oracle/graalvm-reachability-metadata/schemas/metadata-root-index.schema.json", | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "description": "Schema for metadata/index.json. This file lists modules known to the repository and optionally the directory where their metadata is stored, the allowed package prefixes for metadata, and inter-module requirements. See docs/CONTRIBUTING.md (Metadata structure).", | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["module"], | ||
| "properties": { | ||
| "module": { | ||
| "$ref": "#/$defs/moduleCoordinate", | ||
| "description": "Maven coordinates for the module in the form '<groupId>:<artifactId>'." | ||
| }, | ||
| "directory": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "pattern": "^[^\\s].*$", | ||
| "description": "Repository-relative path under 'metadata/' containing this module's metadata (e.g. 'org.example/library'). If omitted, the entry may reference requirements only." | ||
| }, | ||
| "allowed-packages": { | ||
| "type": "array", | ||
| "description": "List of package (or fully-qualified name) prefixes considered valid sources of metadata entries for this module. Used to filter-in relevant JSON entries.", | ||
| "minItems": 1, | ||
| "uniqueItems": true, | ||
| "items": { | ||
| "type": "string", | ||
| "minLength": 1 | ||
| } | ||
| }, | ||
| "requires": { | ||
| "type": "array", | ||
| "description": "Optional list of module coordinates this module depends on. Each item is '<groupId>:<artifactId>'.", | ||
| "minItems": 1, | ||
| "uniqueItems": true, | ||
| "items": { | ||
| "$ref": "#/$defs/moduleCoordinate" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "$defs": { | ||
| "moduleCoordinate": { | ||
| "type": "string", | ||
| "pattern": "^[^:]+:[^:]+$" | ||
| } | ||
| }, | ||
| "examples": [ | ||
| [ | ||
| { | ||
| "directory": "org.example/library", | ||
| "module": "org.example:library" | ||
| }, | ||
| { | ||
| "allowed-packages": ["org.package.name"], | ||
| "module": "org.example:dependant-library", | ||
| "requires": ["org.example:library"] | ||
| }, | ||
| { | ||
| "allowed-packages" : [ "org.hibernate", "jakarta" ], | ||
| "directory" : "org.hibernate.orm/hibernate-envers", | ||
| "module" : "org.hibernate.orm:hibernate-envers", | ||
| "requires" : [ "org.hibernate.orm:hibernate-core" ] | ||
| } | ||
| ] | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "$id": "https://github.com/oracle/graalvm-reachability-metadata/docs/schemas/tests-project-index-schema-v1.0.0.json", | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "title": "Test Project Index", | ||
| "description": "Schema for tests/src/<groupId>/<artifactId>/<version>/index.json. This file optionally customizes the test invocation via 'test-command'. If omitted or if the property is not present, a default command will be used (gradlew nativeTest with environment overrides) per TestInvocationTask.", | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "properties": { | ||
| "test-command": { | ||
| "type": "array", | ||
| "description": "Command line to run for this test project. Supports template parameters: <metadata_dir>, <group_id>, <artifact_id>, <version>.", | ||
| "minItems": 1, | ||
| "items": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "Part of the command line. May include template parameters like <metadata_dir>, <group_id>, <artifact_id>, <version>." | ||
| } | ||
| } | ||
| }, | ||
| "examples": [ | ||
| { | ||
| "test-command": [ | ||
| "gradle", | ||
| "nativeTest", | ||
| "-Pmetadata.dir=<metadata_dir>", | ||
| "-Plibrary.version=<version>" | ||
| ] | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always strive to do this in gradle. That way I can also do it locally to verify everything is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I've removed this file-producing part of the GitHub action and created a
generateChangedIndexFileMatrixgradle task that will do this in gradle (and is locally test-able). As these tasks require aci.jsonentry, I've added it as only tested onjava: latest-eaandos: ubuntu-latestas not to produce multiple jobs (because there shouldn't be any change with different jdks for this functionality as we don't run native-image).