Skip to content

Commit

Permalink
Merge pull request #14 from GrantBirki/yaml-as-json-docs
Browse files Browse the repository at this point in the history
Yaml as json docs
  • Loading branch information
GrantBirki authored Jun 25, 2023
2 parents 071cb0a + 37818ea commit 4164ed6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ Here is a quick example of how to install this action in any workflow:
| `yaml_extension` | `false` | `".yaml"` | The file extension for YAML files (e.g. .yaml) |
| `yaml_extension_short` | `false` | `".yml"` | The "short" file extension for YAML files (e.g. .yml) |
| `yaml_exclude_regex` | `false` | `""` | A regex to exclude files from validation (e.g. `".*\.schema\.yaml$"` to exclude all files ending with `.schema.yaml`) - Default is `""` which doesn't exclude any files |
| `yaml_as_json` | `false` | `"false"` | Whether or not to treat and validate YAML files as JSON files - `"true"` or `"false"` - Default is `"false"`. If this is true, the JSON schema will be used to validate YAML files. Any YAML schemas will be ignored. For this context, a YAML file is any file which matches the yaml_extension or yaml_extension_short inputs. See the [docs](docs/yaml_as_json.md) for more details |
| `exclude_file` | `false` | `""` | The full path to a file in the repository where this Action is running that contains a list of '.gitignore'-style patterns to exclude files from validation (e.g. ./exclude.txt) |
| `use_gitignore` | `true` | `true` | Whetheror not to use the .gitignore file in the root of the repository to exclude files from validation - `"true"` or `"false"` - Default is `"true"` |
| `use_gitignore` | `true` | `"true"` | Whetheror not to use the .gitignore file in the root of the repository to exclude files from validation - `"true"` or `"false"` - Default is `"true"` |
| `git_ignore_path` | `false` | `".gitignore"` | The full path to the .gitignore file to use if use_gitignore is set to "true" (e.g. ./src/.gitignore) - Default is ".gitignore" which uses the .gitignore file in the root of the repository |
| `github_token` | `false` | `${{ github.token }}` | The GitHub token used to create an authenticated client - Provided for you by default! |

Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/yaml_as_json/invalid/yaml1.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bad data: oh no
bad data: oh no
2 changes: 1 addition & 1 deletion __tests__/fixtures/yaml_as_json/valid/yaml1.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
foo: 1
bar: abc
bar: abc
12 changes: 4 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ inputs:
description: A regex to exclude JSON files from validation (e.g. .*\.schema\.json$) - Default is "" which doesn't exclude any files
required: false
default: ""
yaml_as_json:
description: |
Whether or not to treat YAML files as JSON files - "true" or "false" - Default is "false".
If this is true, the JSON schema will be used to validate YAML files. Any YAML schemas will be ignored.
For this context, a YAML file is any file which matches the yaml_extension or yaml_extension_short inputs.
required: false
default: "false"
yaml_schema:
description: The full path to the YAML schema file (e.g. ./schemas/schema.yml) - Default is "" which doesn't enforce a strict schema
required: false
Expand All @@ -57,6 +49,10 @@ inputs:
description: A regex to exclude YAML files from validation (e.g. .*\.schema\.yaml$) - Default is "" which doesn't exclude any files
required: false
default: ""
yaml_as_json:
description: Whether or not to treat and validate YAML files as JSON files - "true" or "false" - Default is "false". If this is true, the JSON schema will be used to validate YAML files. Any YAML schemas will be ignored. For this context, a YAML file is any file which matches the yaml_extension or yaml_extension_short inputs.
required: false
default: "false"
exclude_file:
description: The full path to a file in the repository where this Action is running that contains a list of '.gitignore'-style patterns to exclude files from validation (e.g. ./exclude.txt)
required: false
Expand Down
13 changes: 13 additions & 0 deletions docs/yaml_as_json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# YAML as JSON

By setting the the `yaml_as_json` input option to `"true"`, you can treat YAML files as JSON so that they can be validated with the same schema as JSON files. This is useful as the [yaml validator](https://github.com/ketanSaxena/schema-validator) is rather limited in its capabilities. This means any matching YAML files will be validated with the configured `json_schema` rather than the `yaml_schema`.

Here is an example of how to use this feature:

```yaml
- name: json-yaml-validate
id: json-yaml-validate
uses: GrantBirki/[email protected] # replace with the latest version
with:
yaml_as_json: "true" # enable yaml as json mode
```

0 comments on commit 4164ed6

Please sign in to comment.