From 24f4e54f51d5bdce749d80bd2b10778df3f47e03 Mon Sep 17 00:00:00 2001 From: Stephen Demjanenko Date: Fri, 23 Jun 2023 10:16:42 -0700 Subject: [PATCH] Add Github workflow to validate YAML schema This will allow us to ensure the YAML is well formatted in PRs. Note, we would like to make `source` a required field, but the YAML file currently fails this requirement. NOTE: The github workflow currently warns about `Unexpected input(s) 'yaml-file-dir'. This is happening because of a bug that doesn't affect the output. See: https://github.com/lyubick/action-YAML-schema-validator/pull/8 --- .github/workflows/validate-yaml-schema.yml | 22 +++++++++++++++ schema.json | 32 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/validate-yaml-schema.yml create mode 100644 schema.json diff --git a/.github/workflows/validate-yaml-schema.yml b/.github/workflows/validate-yaml-schema.yml new file mode 100644 index 0000000..7bde9cb --- /dev/null +++ b/.github/workflows/validate-yaml-schema.yml @@ -0,0 +1,22 @@ +on: + push: + branches: + - main + + pull_request: + branches: + - main + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Check schema + uses: lyubick/action-YAML-schema-validator@v2 + with: + json-schema-file: schema.json + yaml-file-dir: accounts.yaml + recursive: false \ No newline at end of file diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..852e909 --- /dev/null +++ b/schema.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "source": { + "anyOf": [ + { "type": "string" }, + { + "type": "array", + "items": { "type": "string" }, + "uniqueItems": true + } + ] + }, + "accounts": { + "type": "array", + "items": { "type": "string", "minLength": 12, "maxLength": 12 }, + "uniqueItems": true + }, + "type": { + "enum": ["aws"] + } + }, + "required": ["name", "accounts"], + "additionalProperties": false + } +}