Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svilgelm/opa-codecov
Merge and convert the rego coverage format to codecov json
https://github.com/svilgelm/opa-codecov
codecov open-policy-agent rego
Last synced: about 18 hours ago
JSON representation
Merge and convert the rego coverage format to codecov json
- Host: GitHub
- URL: https://github.com/svilgelm/opa-codecov
- Owner: SVilgelm
- Created: 2023-04-19T16:33:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-05T16:47:20.000Z (11 months ago)
- Last Synced: 2024-12-24T08:16:14.705Z (8 days ago)
- Topics: codecov, open-policy-agent, rego
- Language: Go
- Homepage: https://github.com/SVilgelm/SVilgelm/discussions/5
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# opa-codecov
The tool to merge and then convert the coverage file generated by `opa test --coverage ` to a simple JSON that is supported by Codecov.
- OPA format: https://www.openpolicyagent.org/docs/latest/policy-testing/#coverage
- Codecov format: https://docs.codecov.com/v4.6/docs/codecov-custom-coverage-format## Real Example
Here is the report uploaded to codecov for the `testdata/authz/authz.rego` file: https://app.codecov.io/gh/SVilgelm/opa-codecov/blob/main/testdata/authz/authz.rego
The test covers expected 50%
## Usage
### GitHub Action
```yaml
opa-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
check-latest: true
- name: Setup OPA
uses: open-policy-agent/setup-opa@v2
with:
version: latest
- name: Run OPA Tests
run: opa test tests/*.rego -v
- name: OPA Coverage
run: |
go install github.com/sv-tools/opa-codecov@main
opa test tests/*.rego -v --coverage | opa-codecov > coverage.json
- name: Publish coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.json
flags: opa
verbose: true
fail_ci_if_error: true
```### As script
```shell
go install github.com/sv-tools/opa-codecov@main
opa test tests/*.rego -v --coverage | opa-codecov > coverage.json
```### With multiple files
```shell
go install github.com/sv-tools/opa-codecov@main
for PKG in $$(find system-types -path "system-types/*/*/spec/typelib"); do \
NAME=$(echo "${PKG}"|sed "s#/#_#g"); \
opa test --coverage ${PKG} > opa-coverage-${NAME}.json; \
done
opa-codecov opa-coverage-*.json > opa-coverage.json
rm opa-coverage-*.json
```