https://github.com/dsanders11/json-schema-validate-action
GitHub Action which validates YAML/JSON files against a JSON schema
https://github.com/dsanders11/json-schema-validate-action
github-actions json-schema
Last synced: 2 months ago
JSON representation
GitHub Action which validates YAML/JSON files against a JSON schema
- Host: GitHub
- URL: https://github.com/dsanders11/json-schema-validate-action
- Owner: dsanders11
- License: mit
- Created: 2023-12-28T09:43:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-02T07:46:50.000Z (3 months ago)
- Last Synced: 2025-03-16T14:11:33.995Z (2 months ago)
- Topics: github-actions, json-schema
- Language: TypeScript
- Homepage:
- Size: 1.28 MB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Schema Validate Action
[](https://github.com/super-linter/super-linter)
[](https://github.com/dsanders11/json-schema-validate-action/actions/workflows/ci.yml)> GitHub Action which validates YAML/JSON files against a JSON schema
## Usage
### Example
```yaml
jobs:
validate-github-actions-workflows:
name: Validate GitHub Actions workflows
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Check for any changed workflows
id: check-for-changed-workflows
run: |
CHANGED_WORKFLOWS=$(gh api repos/${{ github.event.pull_request.base.repo.full_name }}/pulls/${{ github.event.pull_request.number }}/files --jq '.[] | select((.filename | match("^.github/workflows/.*.yml$")) and (.status != "removed")) | .filename')
if [[ -n "$CHANGED_WORKFLOWS" ]]; then
echo "any_changed=true" >> $GITHUB_OUTPUT
else
echo "any_changed=false" >> $GITHUB_OUTPUT
fi
- name: Validate workflows
if: steps.check-for-changed-workflows.outputs.any_changed == 'true'
uses: dsanders11/json-schema-validate-action
with:
schema: https://json.schemastore.org/github-workflow.json
files: .github/workflows/**.yml
```### Validating Schema
Schemas can be validated by setting the `schema` input to the string literal
`json-schema`.### Remote Schema Cache Busting
By default the action will cache remote schemas (this can be disabled via the
`cache-remote-schema` input). If you need to bust this cache for any reason,
simply set a URL fragment (e.g. `#bust-cache`) on the schema URL.### Inputs
- `schema` - **(required)** URL or file path to JSON schema to validate against
- `files` - **(required)** Multiline input of file paths to validate - supports
globs
- `fail-on-invalid` - Whether or not to set action failure if a file is invalid
(default: `true`)
- `cache-remote-schema` - Whether or not to cache the schema if remote (default:
`true`)### Outputs
- `valid` - `true` if all files are valid, otherwise `false`
## License
MIT