https://github.com/antvirf/open-policy-agent-pr-approvals
Sample repo on how to implement automated pull request approvals using GitHub Actions, Open Policy Agent, and conftest.
https://github.com/antvirf/open-policy-agent-pr-approvals
Last synced: 3 months ago
JSON representation
Sample repo on how to implement automated pull request approvals using GitHub Actions, Open Policy Agent, and conftest.
- Host: GitHub
- URL: https://github.com/antvirf/open-policy-agent-pr-approvals
- Owner: Antvirf
- Created: 2024-08-23T05:15:36.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-09-05T04:35:53.000Z (10 months ago)
- Last Synced: 2025-01-23T13:13:40.389Z (5 months ago)
- Language: Open Policy Agent
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Open Policy Agent-based PR Approvals
- [Example PR #1: Invalid YAML](https://github.com/Antvirf/open-policy-agent-pr-approvals/pull/1)
- [Example PR #2: Valid YAML - approved](https://github.com/Antvirf/open-policy-agent-pr-approvals/pull/2)See the GitHub Actions workflow file [here](/.github/workflows/opa-pr-auto-approval.yaml). What this workflow does:
1. On PR, figure out which files were added or changed
2. Assemble the list of files, and feed them through Open Policy Agent [conftest](https://www.conftest.dev/) utility
3. Post results to the PRWhile the first and last steps are quite specific to GitHub, step #2 is orchestrated with bash scripts and is portable across environments. The only requirement is `Docker`.
## Test a file in this repo against policy
The below examples use Docker to avoid needing to install anything persistent locally:
```bash
# services
docker run --rm -v $(pwd):/project openpolicyagent/conftest test --no-fail --no-color gitops-deployments/service.yaml# deployments
docker run --rm -v $(pwd):/project openpolicyagent/conftest test --no-fail --no-color gitops-deployments/deployment.yaml# run both, the same way as the GitHub Actions script does
echo "gitops-deployments/deployment.yaml\ngitops-deployments/service.yaml" | xargs docker run --rm -v $(pwd):/project openpolicyagent/conftest test --no-fail --no-color
```