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
refactor(ts)!: use @actions/exec instead of bash script for OPA commands, allow testing entire directory vs file by file (#27)
## Describe your changes
* Input var of `test_mode` to indicate whether to test the Rego by an
entire directory - `directory` - (including entire package, e.g. `opa
test ./`) or by individual file by file basis - `file` - (e.g. `opa test
a_test.rego a.rego`). Default will test by entire directory package.
* Previously, it was testing OPA policies on a file by file basis
(testing a.rego against a_test.rego). If this is the desired behavior,
use `test_mode = file`.
* Default OPA version is now the latest at the time of writing at
[1.4.2](https://github.com/open-policy-agent/opa/releases). Previously,
it was 0.67.1, latest at Summer of 2024.
* Executions are ran with the `--v0-compatible` flag, see official OPA
documentation on this:
https://www.openpolicyagent.org/docs/latest/v0-compatibility/
* The action will now use [@actions/exec
](https://github.com/actions/toolkit/tree/main/packages/exec) to run the
OPA test commands instead of a bash script. The output is consumed and
processed as JSON.
## Reminder:
- When the PR is ready, be sure to run `npm run build` to compile into
the distribution `/dist` folder, which is the source code that the
Action uses.
Copy file name to clipboardExpand all lines: .github/workflows/test.yml
+13-3Lines changed: 13 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -33,10 +33,20 @@ jobs:
33
33
id: checkout
34
34
uses: actions/checkout@v4
35
35
36
-
- name: Test Local Action
37
-
id: test-action
36
+
- name: Test Local Action (Individual File Mode)
37
+
id: test-action-opa-files
38
38
uses: ./
39
39
with:
40
40
path: ./examples
41
+
test_mode: file
41
42
report_untested_files: true
42
-
pr_comment_title: Below is the Action testing on itself with this PR's source code against the `/examples` directory. Confirm it is as expected.
43
+
pr_comment_title: Below is the Action testing on itself with this PR's source code against policies in `/examples` file by file. Confirm it is as expected.
44
+
45
+
- name: Test Local Action (Directory Package Mode)
46
+
id: test-action-opa-package
47
+
uses: ./
48
+
with:
49
+
path: ./examples
50
+
test_mode: directory
51
+
report_untested_files: true
52
+
pr_comment_title: Below is the Action testing on itself with this PR's source code against `/examples` entire package directory. Confirm it is as expected.
path: "./config/spacelift-policies"# Path of the directory where the OPA Rego policies are stored. Optional, defaults to `.` which is the root directory.
65
+
path: "./config/spacelift-policies"# Path of the directory where the OPA Rego policies are stored.
65
66
report_untested_files: true # Flag to check & report Rego files without corresponding test files. Optional, defaults to false.
66
67
```
67
68
@@ -77,17 +78,19 @@ In the example below, all `_test.rego` files' location are valid and will be exe
| `path` | Path to the directory containing OPA Rego files to test | Yes | REQUIRED |
84
+
| `test_mode` | Whether to test the Rego by an entire directory (including entire package, e.g. `opa test ./`) or by individual files (e.g. `opa test a_test.rego a.rego`). Options of `directory` or `file`. Default is `directory`. | No | `test` |
85
+
| `test_file_postfix` | Postfix of the test files to run (e.g. notification.rego <> notification_test.rego) | No | `_test` |
86
+
| `write_pr_comment` | Flag to write a user-friendly PR comment with test results | No | `true` |
87
+
| `pr_comment_title` | Title of the PR comment for test results | No | `🧪 OPA Rego Policy Test Results` |
88
+
| `pr_comment_mode` | Mode that will be used to update comment. Options of upsert (update in place) or recreate. | No | `upsert` |
89
+
| `run_coverage_report` | Flag to run OPA coverage tests and include in PR comment | No | `true` |
90
+
| `report_untested_files` | Check & report Rego files without corresponding test files | No | `false` |
91
+
| `opa_version` | Version of the OPA CLI to use. | No | `1.4.2` |
92
+
| `opa_static` | Whether to use the static binary for OPA installation. use. | No | `false` |
93
+
| `indicate_source_message` | Flag to comment the origins watermark (this repository) of the GitHub Action in the PR comment. | No | `true` |
91
94
92
95
### Outputs
93
96
@@ -121,11 +124,14 @@ On each pull request, there is a GitHub Actions workflow that runs the tests aut
121
124
122
125
## 🏗️ Setup & Run Locally
123
126
124
-
You can use [nektos/act](https://github.com/nektos/act) to simulate and run a GitHub Actions workflow locally. To directly test the custom TypeScript action locally, you can:
127
+
You can use [nektos/act](https://github.com/nektos/act) to simulate and run a GitHub Actions workflow locally.
128
+
129
+
To directly test the custom TypeScript action locally, you can:
125
130
126
131
1. `npm run install`
127
132
2. `node ./dist/index.js`
128
133
This is assuming you have `npm` and `node` installed already. Note: You will have to manually provide the required inputs since this is directly executing the TypeScript code.
134
+
Additionally, if you are using VS Code, you can use the `.vscode/launch.json` (which executes `npx ts-node ./src/index.ts`) to run and attach the debugger.
0 commit comments