Skip to content

Commit

Permalink
Add new worklow: validate automation schema
Browse files Browse the repository at this point in the history
Using yamale, we're now ensuring the automation file schema is correct:
- check for required data
- check for data type
- check overall structure of the file
  • Loading branch information
cjeanner committed Apr 4, 2024
1 parent fa47a11 commit 1b54e4e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .ci/automation-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This schema is used to validate the automation files.
# Be sure to update this file if ou add new parameters,
# or change names or types in the existing files!
# We are using yamale to validate files
# https://github.com/23andMe/Yamale
---
vas: map(include('_architecture'), key=str())

---
# Define various nested types
_values:
name: str()
src_file: str()
---
_hook:
name: str()
type: str()
source: str()
inventory: str(required=False)
---
_stage:
path: str()
wait_conditions: list(min=1)
values: list(include('_values'), min=1)
build_output: str()
pre_stage_run: list(include('_hook'), required=False)
post_stage_run: list(include('_hook'), required=False)
---
_architecture:
stages: list(include('_stage'), min=1)
29 changes: 29 additions & 0 deletions .github/workflows/automation-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Validate automation schema
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
- stable
paths:
- ".ci/automation-schema.yaml"
- "automation/vars/*.yaml"
- "automation/vars/*.yml"

jobs:
yamale:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install yaml-lint
run: pip install yamale

- name: Run yamale
run: yamale -s .ci/automation-schema.yaml automation/vars/
14 changes: 14 additions & 0 deletions automation/vars/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Automation files

## Schema validation
The files are tested using `yamale`. Be sure to update
the `.ci/automation-schema.yaml` file at the root of this
project if you add a new key, or modify a type!

More information about [yamale](https://github.com/23andMe/Yamale).

## Manually check schema
```Bash
$ pip install yamale
$ yamale -s .ci/automation-schema.yaml automation/vars
```

0 comments on commit 1b54e4e

Please sign in to comment.