📄 Writing YAML with Validation
When working with YAML files, validating them is like a superpower that saves you a lot of time and effort.
Each of the actions and workflows in AutoPR clearly define their inputs and outputs. By enabling validation, you inform your editor of these definitions, so it can help you avoid writing invalid YAML.
There are three schemas available for validation:
trigger_schema.json
- validates trigger filesworkflow_schema.json
- validates workflows filesstrict_workflow_schema.json
- validates workflows files, with strong typing for workflows
Writing with strict typing
Compared to workflow_schema
, strict_workflow_schema
is also aware of workflow definitions (and their inputs/outputs).
If you're using it to write workflows that reference themselves, you will need to regenerate it after definining
the new workflows' names, inputs and outputs.
Regenerate by running python -m autopr.models.config.entrypoints
(or make schema
if you're in the root of the AutoPR repository).
Make sure to select the new schema file you generated if you were previously working off a remote URL.
Editor config
AutoPR workflows and triggers are strictly typed, and the YAML files that define them are validated against a JSON schema. Configuring these in your editor can help you avoid errors and typos, and can help you discover new features.
VS Code
AutoPR includes a .vscode
folder,
which already contains settings for schema validation. Additionally, make sure you have extension YAML by Red Hat
installed.
If you want to set schema validation for an external repository, simply copy
the .vscode
folder
into the root of your workspace.
Alternatively, include one of the following comments to the top of your yaml file:
- for triggers:
# yaml-language-server: $schema=https://raw.githubusercontent.com/irgolic/AutoPR/triggers.schema.json
- for workflows:
# yaml-language-server: $schema=https://raw.githubusercontent.com/irgolic/AutoPR/workflows.schema.json
- for strict workflows:
# yaml-language-server: $schema=https://raw.githubusercontent.com/irgolic/AutoPR/workflows-strict.schema.json
PyCharm
Head to Preferences > Languages & Frameworks > Schemas and DTDs > JSON Schema Mappings
and add the following mappings:
- AutoPR Triggers:
https://raw.githubusercontent.com/irgolic/AutoPR/triggers.schema.json
- AutoPR Workflows:
https://raw.githubusercontent.com/irgolic/AutoPR/workflows.schema.json
- AutoPR Strict Workflows:
https://raw.githubusercontent.com/irgolic/AutoPR/workflows-strict.schema.json
Afterwards, while editing a YAML file, select the corresponding schema in the bottom right corner of the editor.