{"id":17678066,"url":"https://github.com/babarot/action-opa","last_synced_at":"2025-05-12T22:25:11.196Z","repository":{"id":40315627,"uuid":"237394102","full_name":"babarot/action-opa","owner":"babarot","description":"Run opa test command with GitHub Actions","archived":false,"fork":false,"pushed_at":"2023-02-24T15:32:35.000Z","size":505,"stargazers_count":9,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T09:38:09.129Z","etag":null,"topics":["conftest","github-actions","opa","openpolicyagent","rego"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/babarot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-01-31T09:02:12.000Z","updated_at":"2025-02-23T16:54:00.000Z","dependencies_parsed_at":"2023-09-09T05:49:39.761Z","dependency_job_id":null,"html_url":"https://github.com/babarot/action-opa","commit_stats":{"total_commits":25,"total_committers":6,"mean_commits":4.166666666666667,"dds":0.28,"last_synced_commit":"8e5a6653fd55d993f2e0232b1fb439709eada100"},"previous_names":["babarot/action-opa","b4b4r07/action-opa"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarot%2Faction-opa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarot%2Faction-opa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarot%2Faction-opa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarot%2Faction-opa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babarot","download_url":"https://codeload.github.com/babarot/action-opa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253832051,"owners_count":21971201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conftest","github-actions","opa","openpolicyagent","rego"],"created_at":"2024-10-24T08:03:33.582Z","updated_at":"2025-05-12T22:25:11.174Z","avatar_url":"https://github.com/babarot.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"action-opa\n==========\n\n[![](https://github.com/b4b4r07/action-opa/workflows/release/badge.svg)](https://github.com/b4b4r07/action-opa/releases)\n\n![](docs/demo.png)\n\nRun [opa test](https://www.openpolicyagent.org/docs/latest/policy-testing/) command with GitHub Actions\n\nYou can use the fixed version from: [Releases](https://github.com/b4b4r07/action-opa/releases/latest)\n\n## Usage\n\nA whole example is here:\n\n```yaml\nname: opa\n\non:\n  pull_request:\n    paths:\n      - '.github/workflows/opa.yml' ## self-trigger\n      - '.policy/**'\n\njobs:\n  opa:\n    name: opa test\n    runs-on: ubuntu-latest\n    steps:\n    - name: Checkout\n      uses: actions/checkout@v1\n    - name: Get changed objects\n      uses: b4b4r07/action-changed-objects@master\n      with:\n        added: 'true'\n        deleted: 'false'\n        modified: 'true'\n      id: objects\n    - name: Run opa test against changed files\n      uses: b4b4r07/action-opa@master\n      if: steps.objects.outputs.changed\n      with:\n        coverage: 90%\n        files: ${{ steps.objects.outputs.changed }}\n      id: opa\n    - name: Post opa command result to GitHub comment\n      uses: b4b4r07/action-github-comment@master\n      if: steps.opa.outputs.result\n      with:\n        body: |\n          ## opa test result\n          ```\n          ${{ steps.opa.outputs.result }}\n          ```\n      env:\n        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n        LOG: trace\n```\n\nIf you want to test [opa](https://github.com/open-policy-agent/opa)/[conftest](https://github.com/instrumenta/conftest) policies against only changed files, you need to use [b4b4r07/action-changed-objects](https://github.com/b4b4r07/action-changed-objects) to get the changed files in Git commit. It defaults to compare with checkout-ed branch and origin/master branch.\n\nBesides, if you want to post the `opa test` command result on your pull requests, you need to set the step `Post opa command result to GitHub comment`. The contents of `body` is the message itself. You can configure it as Markdown. For more details, please see also [b4b4r07/action-github-comment](https://github.com/b4b4r07/action-github-comment).\n\n\u003cimg src=\"docs/comment.png\" width=\"600\"\u003e\n\nBTW, you want the example rego files:\n\n\u003cdetails\u003e\u003csummary\u003e\u003ccode\u003eexample.rego\u003c/code\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\n```rego\npackage authz\n\nallow {\n    input.path == [\"users\"]\n    input.method == \"POST\"\n}\n\nallow {\n    some profile_id\n    input.path = [\"users\", profile_id]\n    input.method == \"GET\"\n    profile_id == input.user_id\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003ccode\u003eexample_test.rego\u003c/code\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\n```rego\npackage authz\n\ntest_post_allowed {\n    allow with input as {\"path\": [\"users\"], \"method\": \"POST\"}\n}\n\ntest_get_anonymous_denied {\n    not allow with input as {\"path\": [\"users\"], \"method\": \"GET\"}\n}\n\ntest_get_user_allowed {\n    allow with input as {\"path\": [\"users\", \"bob\"], \"method\": \"GET\", \"user_id\": \"bob\"}\n}\n\ntest_get_another_user_denied {\n    not allow with input as {\"path\": [\"users\", \"bob\"], \"method\": \"GET\", \"user_id\": \"alice\"}\n}\n```\n\n\u003c/details\u003e\n\n```console\n$ docker run -v $(pwd):/tests openpolicyagent/opa test -v /tests/example.rego /tests/example_test.rego\ndata.authz.test_post_allowed: PASS (2.3088ms)\ndata.authz.test_get_anonymous_denied: PASS (765.8µs)\ndata.authz.test_get_user_allowed: PASS (880.2µs)\ndata.authz.test_get_another_user_denied: PASS (1.1077ms)\n--------------------------------------------------------------------------------\nPASS: 4/4\n```\n\n## Customizing\n\n### inputs\n\nThe following are optional as `step.with` keys\n\n| Name       | Type   | Description                                                       | Default |\n| ---------- | ------ | ----------------------------------------------------------------- | ------- |\n| `path`     | String | Path to directory where rego files are located                    | `.`     |\n| `coverage` | String | Percentage of test coverage to require                            | `80%`   |\n| `files`    | String | Files subject to OPA testing. List should be separated by a space |         |\n\nWhen providing a `path` and `files` at the same time, `files` will be attempted first, then falling back on `path` if the files can not be got from.\n\n### outputs\n\nThe following outputs can be accessed via `${{ steps.\u003cstep-id\u003e.outputs }}` from this action\n\n| Name     | Type   | Description              |\n| -------- | ------ | ------------------------ |\n| `result` | String | Outputs of `opa` command |\n\n### environment variables\n\nThe following are as `step.env` keys\n\n| Name | Description |\n| ---- | ----------- |\n| n/a  | n/a         |\n\n## License\n\n[MIT](https://b4b4r07.mit-license.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabarot%2Faction-opa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabarot%2Faction-opa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabarot%2Faction-opa/lists"}