Skip to content

Conversation

@myronmarston
Copy link
Collaborator

One of the ElasticGraph guiding principles is that all documentation should be validated, so that our CI build notifies us when it goes stale and no longer works. It's important that code snippets in READMEs remain working and accurate.

To that end, this introduces script/validate_readme_snippets. Here's how it works:

  • A new ElasticGraph project is bootstrapped into tmp/example_project_for_snippet_validation.
  • bash snippets are executed from that project directory.
  • diff snippets are applied to that project directory. Then bundle exec rake is executed to confirm the build still passes.
  • ruby snippets are dumped into a file (either at a temp path, or at the path identified in a comment) and then executed.
  • yaml snippets are parsed as YAML.
  • mermaid snippets are skipped, because they are generated (and verified) by script/update_dependency_diagrams, so we can trust they are valid.
  • text snippets (that is, snippets which don't indicate a type) are not validated. (So a simple way to get the build to pass for a failing snippet is to remove the type, so that it's just text).

We have a number of snippets that fail. This fixes the simple ones and converts the ones that can't simply be fixed to text so that they are not validated as part of the build, allowing the build to pass.

I'll be overhauling the READMEs with updated snippets in a later PR.

One of the ElasticGraph guiding principles is that all documentation
should be validated, so that our CI build notifies us when it goes
stale and no longer works. It's important that code snippets in READMEs
remain working and accurate.

To that end, this introduces `script/validate_readme_snippets`. Here's how it works:

* A new ElasticGraph project is bootstrapped into `tmp/example_project_for_snippet_validation`.
* `bash` snippets are executed from that project directory.
* `diff` snippets are applied to that project directory. Then `bundle exec rake` is executed to confirm the build still passes.
* `ruby` snippets are dumped into a file (either at a temp path, or at the path identified in a comment) and then executed.
* `yaml` snippets are parsed as YAML.
* `mermaid` snippets are skipped, because they are generated (and verified) by `script/update_dependency_diagrams`, so we can trust they are valid.
* `text` snippets (that is, snippets which don't indicate a type) are not validated. (So a simple way to get the build to pass for a failing snippet is to remove the type, so that it's just text).

We have a number of snippets that fail. This fixes the simple ones and converts
the ones that can't simply be fixed to `text` so that they are not validated
as part of the build, allowing the build to pass.

I'll be overhauling the READMEs with updated snippets in a later PR.
@CLAassistant
Copy link

CLAassistant commented Jul 18, 2025

CLA assistant check
All committers have signed the CLA.


require "yaml"

class YamlSnippetValidator < SnippetValidator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idea (non-blocking): maybe someday the actual yaml could be validated against a schema rather than just confirming it loads.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Right now, settings are validated via adhoc logic (example) and I'd like to make it so that config validation is defined using JSON schema. Then we can use that here.

@myronmarston myronmarston merged commit 31716a9 into main Jul 31, 2025
19 of 20 checks passed
@myronmarston myronmarston deleted the myron/readme-validation branch July 31, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants