You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
This PR adds a Rego v1 compatibility check to the action, ensuring
policy files conform to OPA v1 / Rego v1 syntax before tests are run.
### What changed
- **New input `v1_compatible_check`** (default: `true`) — when enabled,
runs `opa check --v1-compatible` against all Rego files in `path` before
executing tests. If any files use v0-only syntax (missing `if`,
`contains`, or `import rego.v1`), the action fails immediately with
OPA's error output identifying the offending files and line numbers.
- **Test runner flag is now driven by the same input** — when
`v1_compatible_check: true`, `opa test` also runs with `--v1-compatible`
so the syntax validation and test execution are consistent. When
`false`, both revert to `--v0-compatible`.
- **All `examples/` updated to Rego v1 syntax** — replaced `import
future.keywords.*` with `import rego.v1`, added `if` to rule bodies, and
added `contains` to partial set rules across all 8 policies and 7 test
files. All 46 tests still pass.
- **README updated** — new input documented in the inputs table and How
It Works section.
If the new V1 check fails, the report output will display as:
<img width="570" height="856" alt="Screenshot 2026-04-20 at 11 25 28 AM"
src="https://github.com/user-attachments/assets/ff67ab67-b827-4490-9843-9005e8976dc9"
/>
### ⚠️ Breaking change
This will be a **major version bump**. The `v1_compatible_check` input
defaults to `true`, which means existing users with v0 syntax policies
will see their workflows fail. To preserve previous behavior, set:
```yaml
- uses: masterpointio/github-action-opa-rego-test@main
with:
path: ./policies
v1_compatible_check: false
` ``
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
* **New Features**
* Added optional Rego v1 compatibility check to the action (enabled by default). When enabled the action validates all policy files and fails early on v0-only syntax.
* Action now surfaces a dedicated v1-compatibility failure section in its output.
* **Documentation**
* README updated with a new `v1_compatible_check` input to control this behavior and adjusted workflow step ordering.
* **Examples**
* Updated example policies and tests to Rego v1 syntax.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Copy file name to clipboardExpand all lines: README.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,7 @@ In the example below, all `_test.rego` files' location are valid and will be exe
91
91
| `report_untested_files` | Check & report Rego files without corresponding test files | No | `false` |
92
92
| `opa_version` | Version of the OPA CLI to use. | No | `1.4.2` |
93
93
| `opa_static` | Whether to use the static binary for OPA installation. use. | No | `false` |
94
+
| `v1_compatible_check` | Flag to run `opa check --v1-compatible` against all Rego files in `path`. Fails the action with a clear error if any files use Rego v0-only syntax. Set to `false` to disable. | No | `true` |
94
95
| `indicate_source_message` | Flag to comment the origins watermark (this repository) of the GitHub Action in the PR comment. | No | `true` |
95
96
96
97
### Outputs
@@ -105,12 +106,13 @@ In the example below, all `_test.rego` files' location are valid and will be exe
105
106
This GitHub Action automates the process of testing OPA (Open Policy Agent) Rego policies and generating coverage reports. Here's a breakdown of its operation:
106
107
107
108
1. Setup: The action begins by setting up OPA using the open-policy-agent/setup-opa@v2 action, ensuring the necessary tools are available.
108
-
2. Run OPA Tests: It executes `opa test` on all .rego files in the specified directory (default is the root directory). The test results are captured and stored as an output.
109
-
3. Run OPA Coverage Tests: Enabled by default but optional, the action performs coverage tests on each .rego file that has a corresponding \_test.rego file. This step identifies which parts of your policies are covered by tests.
110
-
4. Find Untested Files: Optionally if enabled, it can identify Rego files that don't have corresponding test files, helping you maintain comprehensive test coverage.
111
-
5. Parse and Format Results: A custom TypeScript script (index.ts) processes the raw test and coverage outputs. It parses the results into a structured format and generates a user-friendly summary.
112
-
6. Generate PR Comment: The formatted results are used to create or update a comment on the pull request.
113
-
7. Fail the Action if Tests Fail: If any tests fail, the action is marked as failed, which can be used to block PR merges or trigger other workflows.
109
+
2. Find Untested Files: Optionally if enabled, it can identify Rego files that don't have corresponding test files, helping you maintain comprehensive test coverage.
110
+
3. Rego v1 Compatibility Check (optional, default enabled): Runs `opa check --v1-compatible` against all Rego files in the path. If any files use Rego v0-only syntax, the action fails immediately with OPA's error output identifying the offending files. This check can be disabled by setting `v1_compatible_check: false`.
111
+
4. Run OPA Tests: It executes `opa test` on all .rego files in the specified directory (default is the root directory). The test results are captured and stored as an output.
112
+
5. Run OPA Coverage Tests: Enabled by default but optional, the action performs coverage tests on each .rego file that has a corresponding \_test.rego file. This step identifies which parts of your policies are covered by tests.
113
+
6. Parse and Format Results: A custom TypeScript script (index.ts) processes the raw test and coverage outputs. It parses the results into a structured format and generates a user-friendly summary.
114
+
7. Generate PR Comment: The formatted results are used to create or update a comment on the pull request.
115
+
8. Fail the Action if Tests Fail: If any tests fail, the action is marked as failed, which can be used to block PR merges or trigger other workflows.
114
116
115
117

Copy file name to clipboardExpand all lines: action.yml
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,10 @@ inputs:
45
45
description: "Whether to use the static binary. Default is false."
46
46
required: false
47
47
default: "false"
48
+
v1_compatible_check:
49
+
description: Flag to run OPA v1 compatibility check (`opa check --v1-compatible`) on all Rego files in the path. Fails the action if any files are not Rego v1 compatible. Default of true.
50
+
required: false
51
+
default: "true"
48
52
indicate_source_message:
49
53
description: Flag to comment the origins (this repository) of the GitHub Action in the PR comment. Default of true.
0 commit comments