https://github.com/bitwizeshift/actions-jsonschema
JSON Schema Validation provided through a GitHub Action
https://github.com/bitwizeshift/actions-jsonschema
Last synced: about 2 months ago
JSON representation
JSON Schema Validation provided through a GitHub Action
- Host: GitHub
- URL: https://github.com/bitwizeshift/actions-jsonschema
- Owner: bitwizeshift
- License: mit
- Created: 2024-03-09T15:27:19.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-18T10:42:37.000Z (about 1 year ago)
- Last Synced: 2024-12-28T17:14:03.748Z (about 1 year ago)
- Language: TypeScript
- Size: 4.65 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# JSON Schema Validation Action
[](https://github.com/super-linter/super-linter)

[](https://github.com/bitwizeshift/actions-jsonschema/actions/workflows/check-dist.yaml)
[](https://github.com/bitwizeshift/actions-jsonschema/actions/workflows/codeql-analysis.yaml)
A GitHub action for validating [JSON], [TOML], and [YAML] formatted
configuration files against a [JSON Schema] definition.
[JSON]: https://www.json.org/json-en.html
[YAML]: https://yaml.org/
[TOML]: https://toml.io/en/
[JSON Schema]: https://json-schema.org/
> Convenience [composite actions] are available in addition to the primary
> `jsonschema` action, such as:
>
> - `github-workflow`: which leverages [schemastore]'s [`github-workflow.json`]
> - `github-action`: which leverages [schemastore]'s [`github-action.json`]
> - `cargo`: which leverages [schemastore]'s [`cargo.json`]
[`github-workflow.json`]: https://json.schemastore.org/github-workflow.json
[`github-action.json`]: https://json.schemastore.org/github-action.json
[`cargo.json`]: https://json.schemastore.org/cargo.json
[composite actions]:
https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
## Features
- [x] Supports [JSON], [YAML], and [TOML] resource validation.
- [x] Validates schemas from both remote or local definitions.
- [x] Support for [caching] downloaded schemas to reduce network traffic.
- [x] Convenience actions which leverage [schemastore] schems.
[schemastore]: https://www.schemastore.org/json/
## Documentation
## Usage
### Pre-requisites
Create a workflow `.yaml` file in your repository's `.github/workflows`
directory. Some [example workflow](#example-workflows) are available below. For
more information, see the GitHub Help Documentation for [Creating a workflow
file].
[Creating a workflow file]:
https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file
### Inputs
- `paths` - a set of path globs to run this validation against.
- `schema` - either a path to a local file, or to a URL of a [JSON Schema].
- `cache-key` - (optional) key to use for caching downloaded schemas. Only
relevant when `schema` refers to a URL.
- `github-token` - (optional) the GitHub API token to use for internal API
calls. Default: `${{ github.token }}`.
- `scope` - (optional) whether to validate `'all'` globbed files, or only ones
that have been modified in the `'diff'`. Default: `'all'`.
### Outputs
- `status` - whether validation succeeded. Will be one of `'success'` or
`'failure'`.
## Example Workflows
### Validating by local schema
```yaml
name: Validate against Schema
on: push
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate local custom schema
uses: bitwizeshift/actions-jsonschema@v1
with:
schema: ./some-schema.json
paths: |
testdata/**/*.json
resources/**/*.json
```
### Validating GitHub workflows on change (with caching)
```yaml
name: Validate GitHub Workflow Schema
on:
push:
paths:
- '.github/workflows/*.yaml'
pull_request:
paths:
- '.github/workflows/*.yaml'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate Workflow Schema
uses: bitwizeshift/actions-jsonschema/github-workflow@v1
with:
paths: ./.github/workflows/*.yaml
cache-key: github-workflow
scope: diff # Using 'diff' only evaluates files that change
```