octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).
Key features of octocov are:
- Support multiple coverage report formats.
- Support multiple code metrics.
- Support for even generating coverage report badge.
- Have a mechanism to aggregate reports from multiple repositories.
GitHub Actions for octocov is here !!
First, run test with coverage report output.
For example, in case of Go language, add -coverprofile=coverage.out option as follows
$ go test ./... -coverprofile=coverage.outAdd .octocov.yml ( or octocov.yml ) file to your repository.
# .octocov.yml
coverage:
path: coverage.out
codeToTestRatio:
code:
- '**/*.go'
- '!**/*_test.go'
test:
- '**/*_test.go'
comment:
enable: trueAnd set up a workflow file as follows and run octocov on GitHub Actions.
# .github/workflows/ci.yml
name: Test
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
-
uses: actions/setup-go@v2
with:
go-version: 1.17
-
name: Run tests with coverage report output
run: go test ./... -coverprofile=coverage.out
-
uses: k1LoW/octocov-action@v0Then, octocov comment the report of the code metrics to the pull request.
octocov acts as a code metrics viewer on the terminal.
For example, in case of Go language, add -coverprofile=coverage.out option as follows
$ go test ./... -coverprofile=coverage.outAnd run octocov ls-files , octocov view [FILE...] and octocov diff [REPORT_A] [REPORT_B]
By setting comment:, comment the reports to pull request.
# .octocov.yml
comment:
enable: true
hideFooterLink: false # hide octocov linkoctocov checks for "Code Coverage" by default. If it is running on GitHub Actions, it will also measure "Test Execution Time".
If you want to measure "Code to Test Ratio", set codeToTestRatio:.
comment:
enable: true
codeToTestRatio:
code:
- '**/*.go'
- '!**/*_test.go'
test:
- '**/*_test.go'By setting diff: ( diff.path: or diff.datastores ) additionally, it is possible to show differences from previous reports as well.
comment:
enable: true
diff:
datastores:
- s3://bucket/reportsBy setting coverage.acceptable:, the minimum acceptable coverage is specified.
If it is less than that value, the command will exit with exit status 1.
# .octocov.yml
coverage:
acceptable: 60%$ octocov
Error: code coverage is 54.9%, which is below the accepted 60.0%By setting codeToTestRatio.acceptable:, the minimum acceptable "Code to Test Ratio" is specified.
If it is less than that value, the command will exit with exit status 1.
# .octocov.yml
codeToTestRatio:
acceptable: 1:1.2
code:
- '**/*.go'
- '!**/*_test.go'
test:
- '**/*_test.go'$ octocov
Error: code to test ratio is 1:1.1, which is below the accepted 1:1.2By setting testExecutionTime.acceptable:, the maximum acceptable "Test Execution Time" is specified (on GitHub Actions only) .
If it is greater than that value, the command will exit with exit status 1.
# .octocov.yml
testExecutionTime:
acceptable: 1 min$ octocov
Error: test execution time is 1m15s, which is below the accepted 1mBy setting *.badge.path:, generate badges self.
# .octocov.yml
coverage:
badge:
path: docs/coverage.svg# .octocov.yml
codeToTestRatio:
badge:
path: docs/ratio.svg# .octocov.yml
testExecutionTime:
badge:
path: docs/time.svgYou can display the coverage badge without external communication by setting a link to this badge image in README.md, etc.
# mytool
By setting push.enable:, git push report badges self.
# .octocov.yml
coverage:
badge:
path: docs/coverage.svg
push:
enable: trueBy setting report:, store the reports to datastores and local path.
# .octocov.yml
report:
datastores:
- github://owner/coverages/reports
- s3://bucket/reports# .octocov.yml
report:
path: path/to/report.json- GitHub repository
- S3
- GCS
- BigQuery
- Local
By enabling central:, octocov acts as a central repository for collecting reports ( example ).
# .octocov.yml for central mode
central:
enable: true
root: . # root directory or index file path of collected coverage reports pages. default: .
reports:
- bq://my-project/my-dataset/reports # datastore paths (URLs) where reports are stored. default: local://reports
badges: badges # directory where badges are generated. default: badges
push:
enable: true # enable self git push- GitHub repository
- S3
- GCS
- BigQuery
- Local
octocov ls-files command can be used to list files logged in code coverage report.
octocov view (alias: octocov cat) command can be used to view the file coverage report.
Configuration for code coverage.
The path to the coverage report file.
If no path is specified, the default path for each coverage format will be scanned.
coverage:
path: tests/coverage.xmlThe minimum acceptable coverage.
coverage:
acceptable: 60%Set this if want to generate the badge self.
The path to the badge.
coverage:
badge:
path: docs/coverage.svgConfiguration for code to test ratio.
Files to count.
codeToTestRatio:
code: # files to count as "Code"
- '**/*.go'
- '!**/*_test.go'
test: # files to count as "Test"
- '**/*_test.go'The minimum acceptable ratio.
codeToTestRatio:
acceptable: 1:1.2Set this if want to generate the badge self.
The path to the badge.
codeToTestRatio:
badge:
path: docs/ratio.svgConfiguration for test execution time.
The minimum acceptable time.
testExecutionTime:
acceptable: 1minSet this if want to generate the badge self.
The path to the badge.
testExecutionTime:
badge:
path: docs/time.svgConfiguration for git push badges self.
Enable git push
push:
enable: trueSet this if want to comment report to pull request
Enable comment.
comment:
enable: trueHide footer octocov link.
comment:
hideFooterLink: trueConfiguration for comparing reports.
Path of the report to compare.
diff:
path: path/to/coverage.ymldiff:
path: .octocov/owner/repo/report.jsonDatastores where the report to be compared is stored.
diff:
datastores:
- local://.octocov # Use .octocov/owner/repo/report.json
- s3://my-bucket/reports # Use s3://my-bucket/reports/owner/repo/report.jsonConfiguration for reporting to datastores.
Path to save the report.
report:
path: path/to/report.jsonDatastores where the reports are saved.
report:
datastores:
- github://owner/coverages/reports
- s3://bucket/reportsUse github:// scheme.
github://[owner]/[repo]@[branch]/[prefix]
Required environment variables:
GITHUB_TOKENorOCTOCOV_GITHUB_TOKENGITHUB_REPOSITORYorOCTOCOV_GITHUB_REPOSITORYGITHUB_API_URLorOCTOCOV_GITHUB_API_URL(optional)
Use s3:// scheme.
s3://[bucket]/[prefix]
Required permission:
s3:PutObject
Required environment variables:
AWS_ACCESS_KEY_IDorOCTOCOV_AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYorOCTOCOV_AWS_SECRET_ACCESS_KEYAWS_SESSION_TOKENorOCTOCOV_AWS_SESSION_TOKEN(optional)
Use gs:// scheme.
gs://[bucket]/[prefix]
Required permission:
storage.objects.createstorage.objects.delete
Required environment variables:
GOOGLE_APPLICATION_CREDENTIALSorGOOGLE_APPLICATION_CREDENTIALS_JSONorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALSorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALS_JSON
Use bq:// scheme.
bq://[project ID]/[dataset ID]/[table]
Required permission:
bigquery.datasets.getbigquery.tables.getbigquery.tables.updateData
Required environment variables:
GOOGLE_APPLICATION_CREDENTIALSorGOOGLE_APPLICATION_CREDENTIALS_JSONorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALSorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALS_JSON
Datastore schema:
If you want to create a table, execute the following command ( require bigquery.datasets.create ).
$ octocov --create-bq-tableUse local:// or file:// scheme.
local://[path]
Example:
If the absolute path of .octocov.yml is /path/to/.octocov.yml
local://reports.../path/to/reportsdirectorylocal://.reports.../path/to/reportsdirectorylocal://../reports.../path/reportsdirectorylocal:///reports.../reportsdirectory.
Conditions for saving a report.
# .octocov.yml
report:
if: env.GITHUB_REF == 'refs/heads/main'
datastores:
- github://owner/coverages/reportsThe variables available in the if section are as follows
| Variable name | Type | Description |
|---|---|---|
year |
int |
Year of current time (UTC) |
month |
int |
Month of current time (UTC) |
day |
int |
Day of current time (UTC) |
hour |
int |
Hour of current time (UTC) |
weekday |
int |
Weekday of current time (UTC) (Sunday = 0, ...) |
github.event_name |
string |
Event name of GitHub Actions ( ex. issues, pull_request ) |
github.event |
object |
Detailed data for each event of GitHub Actions (ex. github.event.action, github.event.label.name ) |
env.<env_name> |
string |
The value of a specific environment variable |
Enable central mode.
central:
enable: true:NOTICE: When central mode is enabled, other functions are automatically turned off.
The root directory or index file ( index file example ) path of collected coverage reports pages. default: .
central:
root: path/toDatastore paths (URLs) where reports are stored. default: local://reports
central:
reports:
datastores:
- local://reports
- gs://my-gcs-bucket/reportsWhen using the central repository as a datastore, perform badge generation via on.push.
# .octocov.yml
report:
datastores:
- github://owner/central-repo/reports# .octocov.yml for central repo
central:
enable: true
reports:
datastores:
- local://reports
push:
enable: trueWhen using the S3 bucket as a datastore, perform badge generation via on.schedule.
# .octocov.yml
report:
datastores:
- s3://my-s3-bucket/reports# .octocov.yml for central repo
central:
enable: true
reports:
datastores:
- s3://my-s3-bucket/reports
push:
enable: trueRequired permission (Central Repo):
s3:GetObjects3:ListObject
Required environment variables (Central Repo):
AWS_ACCESS_KEY_IDorOCTOCOV_AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYorOCTOCOV_AWS_SECRET_ACCESS_KEYAWS_SESSION_TOKENorOCTOCOV_AWS_SESSION_TOKEN(optional)
When using the GCS bucket as a datastore, perform badge generation via on.schedule.
# .octocov.yml
report:
datastores:
- gs://my-gcs-bucket/reports# .octocov.yml for central repo
central:
enable: true
reports:
datastores:
- gs://my-gcs-bucket/reports
push:
enable: trueRequired permission (Central Repo):
storage.objects.getstorage.objects.liststorage.buckets.get
Required environment variables (Central Repo):
GOOGLE_APPLICATION_CREDENTIALSorGOOGLE_APPLICATION_CREDENTIALS_JSONorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALSorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALS_JSON
When using the BigQuery table as a datastore, perform badge generation via on.schedule.
# .octocov.yml
report:
datastores:
- bq://my-project/my-dataset/reports# .octocov.yml for central repo
central:
enable: true
reports:
datastores:
- bq://my-project/my-dataset/reports
push:
enable: trueRequired permission (Central Repo):
bigquery.jobs.createbigquery.tables.getData
Required environment variables (Central Repo):
GOOGLE_APPLICATION_CREDENTIALSorGOOGLE_APPLICATION_CREDENTIALS_JSONorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALSorOCTOCOV_GOOGLE_APPLICATION_CREDENTIALS_JSON
Directory where badges are generated. default: badges
central:
badges: badgesSupport local only.
Configuration for git push index file and badges self.
Enable git push
push:
enable: trueoctocov supports multiple coverage report formats.
And octocov searches for the default path for each format.
If you want to specify the path of the report file, set coverage.path
coverage:
path: /path/to/coverage.txtDefault path: coverage.out
Default path: coverage/lcov.info
Support SF DA only
Default path: coverage/.resultset.json
Default path: coverage.xml
Default path: coverage.xml
- Code Coverage
- Code to Test Ratio
- Test Execution Time (on GitHub Actions only)
deb:
Use dpkg-i-from-url
$ export OCTOCOV_VERSION=X.X.X
$ curl -L https://git.io/dpkg-i-from-url | bash -s -- https://github.com/k1LoW/octocov/releases/download/v$OCTOCOV_VERSION/octocov_$OCTOCOV_VERSION-1_amd64.debRPM:
$ export OCTOCOV_VERSION=X.X.X
$ yum install https://github.com/k1LoW/octocov/releases/download/v$OCTOCOV_VERSION/octocov_$OCTOCOV_VERSION-1_amd64.rpmapk:
Use apk-add-from-url
$ export OCTOCOV_VERSION=X.X.X
$ curl -L https://git.io/apk-add-from-url | sh -s -- https://github.com/k1LoW/octocov/releases/download/v$OCTOCOV_VERSION/octocov_$OCTOCOV_VERSION-1_amd64.apkhomebrew tap:
$ brew install k1LoW/tap/octocovmanually:
Download binary from releases page
go get:
$ go get github.com/k1LoW/octocovdocker:
$ docker pull ghcr.io/k1low/octocov:latest
