Skip to content

Commit 6aecea1

Browse files
authored
Merge pull request #63 from GrantBirki/docs-updates
add `Custom Regex Formats` section to the documentation
2 parents 33e30cf + 7a5a721 commit 6aecea1

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Here is a quick example of how to install this action in any workflow:
5454
| `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 |
5555
| `allow_multiple_documents` | `false` | `"false"` | Whether or not to allow multiple documents in a single YAML file - `"true"` or `"false"` - Default is `"false"`. Useful for k8s documents. |
5656
| `ajv_strict_mode` | `false` | `"true"` | Whether or not to use strict mode for AJV - "true" or "false" - Default is "true" |
57-
| `ajv_custom_regexp_formats` | `false` | `""` | List of key value pairs of format_name=regexp. Each pair must be on a newline. (e.g. lowercase_chars=^[a-z]*$ ) |
57+
| `ajv_custom_regexp_formats` | `false` | `""` | List of key value pairs of `format_name=regexp`. Each pair must be on a newline. (e.g. `lowercase_chars=^[a-z]*$` - See below for more details) |
5858
| `github_token` | `false` | `${{ github.token }}` | The GitHub token used to create an authenticated client - Provided for you by default! |
5959

6060
## Outputs 📤
@@ -207,6 +207,68 @@ Details on the fields seen in the schema above:
207207
- `required` - an array of strings, each of which is a property name that is required
208208
- `additionalProperties` - a boolean value that determines if additional properties are allowed in the object
209209

210+
### JSON Schema with Custom Regex Formats
211+
212+
You can also use custom regex formats in your JSON schema. This is useful for validating specific formats of strings. This section describes how you can use custom regex formats with this Action.
213+
214+
#### JSON Schema Example with Custom Regex Formats
215+
216+
Here is an example JSON schema that uses custom regex formats:
217+
218+
> For this example, assume that the JSON schema's file path is `./schemas/custom_with_regex.json` from the root of the repository
219+
220+
```json
221+
{
222+
"type": "object",
223+
"properties": {
224+
"lowercase_char_property": {
225+
"type": "string",
226+
"format": "lowercase_char"
227+
},
228+
"lowercase_alphanumeric_property": {
229+
"type": "string",
230+
"format": "lowercase_alphanumeric"
231+
}
232+
},
233+
"required": ["lowercase_char_property", "lowercase_alphanumeric_property"],
234+
"additionalProperties": false
235+
}
236+
```
237+
238+
#### JSON Input Example with Custom Regex Formats
239+
240+
Here is an example file that we are going to validate against the schema above:
241+
242+
> For this example, assume that the JSON file's file path is `config/valid.json` from the root of the repository
243+
244+
```json
245+
{
246+
"lowercase_char_property": "valid",
247+
"lowercase_alphanumeric_property": "valid1"
248+
}
249+
```
250+
251+
#### Custom Regex Formats - Action Input
252+
253+
Now that we have a JSON schema that uses custom regex formats and a JSON file that we want to validate against the schema, we need to provide the custom regex formats to the Action. The example workflow step below shows how to do this:
254+
255+
```yaml
256+
- name: json-yaml-validate
257+
uses: GrantBirki/[email protected] # replace with the latest version
258+
id: json-yaml-validate
259+
with:
260+
json_schema: ./schemas/custom_with_regex.json # <--- the schema file that uses custom regex formats
261+
ajv_custom_regexp_formats: |
262+
lowercase_char=^[a-z]*$
263+
lowercase_alphanumeric=^[a-z0-9]*$
264+
# ^ these are the custom regex formats used in the schema that we inject into the Action so they can be used
265+
files: |
266+
config/valid.json
267+
# ^ uses the example file as seen in the section above
268+
```
269+
270+
The `ajv_custom_regexp_formats` input is a multi-line string that contains the custom regex formats used in the JSON schema. Each line in the string should be in the format `format_name=regex_pattern`. The `format_name` is the name of the custom regex format used in the schema, and `regex_pattern` is the regex pattern that the value in the JSON file must match.
271+
210272
### YAML Schema Docs
211273

212274
For validating a `.yaml` file with a `.yaml` schema

0 commit comments

Comments
 (0)