Skip to content

Latest commit

 

History

History
87 lines (61 loc) · 2.16 KB

File metadata and controls

87 lines (61 loc) · 2.16 KB

Variables and References

The pattern field in rules supports three reference prefixes that resolve values dynamically at evaluation time.

var: -- Config Variables

Reference a value defined in the [vars] section of align.toml.

[vars]
node_version = ">=18"

["services/*".correct-node-version]
check = "field_contains"
expect = "package.json"
format = "json"
field = "engines.node"
pattern = "var:node_version"

The pattern resolves to ">=18" before the check runs.

If the variable is not defined, the check fails with an error message.

env: -- Environment Variables

Reference a shell environment variable directly.

["services/*".correct-node-version]
check = "field_contains"
expect = "package.json"
format = "json"
field = "engines.node"
pattern = "env:NODE_VERSION"

If the environment variable is not set, the check fails with an error message.

env: can also be used inside [vars] values, allowing indirection through config variables:

[vars]
node_version = "env:NODE_VERSION"

["services/*".correct-node-version]
check = "field_contains"
expect = "package.json"
format = "json"
field = "engines.node"
pattern = "var:node_version"

When var:node_version is resolved, it finds "env:NODE_VERSION" and automatically resolves the environment variable.

file: -- File Content Reference

Read the contents of a file (relative to the repository root) and use it as the pattern. Leading and trailing whitespace is trimmed.

["services/*".node-version-matches-file]
check = "field_contains"
expect = "package.json"
format = "json"
field = "engines.node"
pattern = "file:.node-version"

If .node-version contains 18\n, the pattern resolves to "18".

If the referenced file cannot be opened or read, the check fails with an error message.

Literal Values

Any pattern value without a recognized prefix is used as-is:

pattern = "extends"       # literal substring match
pattern = "console.log"   # literal substring match

Where References Apply

References are resolved in the pattern field of these check types:

  • file_contains / file_not_contains
  • field_contains / field_not_contains