The policy engine uses a YAML configuration file to define rules. By default, the action looks for .github/policy-gate.yml.
| Key | Type | Description |
|---|---|---|
policies |
Policy[] |
List of policies to evaluate. |
Each policy defines when it applies and what it requires.
policies:
- id: string # Required. Unique identifier for the policy.
description: string # Optional. A human-readable description.
severity: error|warn # Required. 'error' fails the build; 'warn' only annotates (unless fail-on-warn is true).
when: predicate # Optional. Conditions that must be met for the policy to apply.
require: predicate # Required. The rule that must be satisfied.
message: string # Required. The message displayed when the policy is violated.Predicates are the building blocks of policies. They evaluate to true or false based on pull request and repository facts.
Checks if any of the specified file patterns (globs) have changed in the pull request.
changed:
- 'src/**/*.ts'
- 'package.json'Checks if all of the specified file patterns exist in the repository at the current PR state.
exists:
- '.github/policy-gate.yml'
- 'CODEOWNERS'Checks if the pull request body matches any of the specified regex patterns.
body:
- 'fixes #\d+'
- 'runbook'Checks if the pull request title matches any of the specified regex patterns.
title:
- '^feat:'
- '^fix:'Checks if the pull request carries any of the specified labels.
has_label:
- 'security-review'
- 'deploy-safe'Checks if the pull request has at least the specified number of approvals.
approval_count_at_least: 2Checks if specific files contain specific text patterns. This is a targeted check that only reads the requested files.
file_contains:
globs:
- 'docs/runbooks/**/*.md'
patterns:
- 'rollback'
- 'recovery'Combinators allow you to build complex logic by combining predicates.
Passes only if every child predicate passes.
require:
all:
- has_label: ['ready']
- approval_count_at_least: 1Passes if at least one child predicate passes.
require:
any:
- approval_count_at_least: 2
- has_label: ['fast-track']Inverts the result of the child predicate.
when:
not:
has_label: ['experimental']The configuration is strictly validated before execution:
- Unknown top-level or policy keys are rejected.
- Invalid severities are rejected.
- Empty IDs, messages, and arrays are rejected.
- Invalid predicate shapes are rejected.
- Negative approval thresholds are rejected.