Skip to content

YAML Schema Validation

Actions
Validates YAML files against specified schemas using the yaml-language-server
v2.0.2
Latest
Star (1)

yaml-ls-check CI npm version

Provides an easy way to validate YAML files against given schemas utilizing the yaml-language-server project.

This package contains a CLI, a GitHub action, and the library itself.

CLI

Install the CLI via npm:

npm install --global yaml-ls-check

The CLI should now be accessible as yaml-ls-check or the short-hand ylsc, and can be used to validate YAML files:

# Validate all YAML files in the given directory, using the .vscode/settings.json file in it, if present.
ylsc <directory>
ylsc dir <directory>

# Optionally, you can provide a list of files to exclude from validation. File paths can be given as glob patterns.
ylsc <directory> --exclude <files...>

# Validate given YAML files against the given schema.
# Schema can either be a local or remote one. File paths can be given as glob patterns.
ylsc schema <schema> <files...>

GitHub Action

If you have a .vscode/settings.json in the root of your repository directory, you can just use the action directly:

steps:
- uses: actions/checkout@v2
- uses: ds-ukassel/yaml-ls-check@v2.0.2

Additional settings for it are:

  • root: If the repository root should not act as root for the validation.
  • schemaMapping: Specify mapping of schema to file patterns that should match the schema. This overwrites the mapping found in any potential .vscode/settings.json file.
  • excludedFiles: A list of file paths or glob patterns to exclude from validation relative to the root.
steps:
- uses: actions/checkout@v2
- uses: ds-ukassel/yaml-ls-check@v2.0.2
  with:
    root: data
    schemaMapping: |
      {
        "schemas/my-schema.json": [ "files/*.yml" ]
      }
    excludedFiles: |
      "helm/**/*.yaml"

Library

npm install yaml-ls-check
import { validateDirectory } from 'yaml-ls-check';

async function someFunction() {
    const invalidFiles = await validateDirectory('path/to/a/folder');
    // invalidFiles is now an array containing paths to files that failed validation
    // and the found errors in the form: { filePath: string, errors: Diagnostics[] }
}

YAML Schema Validation is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Validates YAML files against specified schemas using the yaml-language-server
v2.0.2
Latest

YAML Schema Validation is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.