CI Integration¶
GitHub Actions¶
Using the trep Action¶
The easiest way to add trep to a GitHub Actions workflow is via the trep-dev/action:
- name: Generate test + coverage report
uses: trep-dev/action@v1
with:
tests: build/test-results.xml
cov: build/coverage.out
threshold: 80
fail-tests: true
fail-cov: true
annotate: true
See the action README for the full input reference.
Direct invocation¶
Install trep in a step, then call it directly:
- name: Install trep
run: go install github.com/trep-dev/trep/cmd/trep@latest
- name: Generate test + coverage report
run: |
trep report \
--tests build/test-results.xml \
--cov build/coverage.out \
--threshold 80 \
--fail-tests --fail-cov \
--annotate \
--output-dir dist/ \
--prefix ci \
--baseline .trep/baseline.json \
--baseline-label ${{ github.base_ref }}
- name: Upload report
uses: actions/upload-artifact@v4
with:
name: test-report
path: dist/
SARIF upload (Advanced Security)¶
- name: Generate SARIF
run: |
trep test --output-format sarif -o results.sarif test-results.xml
trep cov --output-format sarif --threshold 80 -o cov.sarif coverage.out
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
category: test-results
GitLab CI¶
test:
script:
- go test -json ./... > results.json
- go test -coverprofile=coverage.out ./...
- trep report
--tests results.json
--cov coverage.out
--threshold 80
--fail-tests --fail-cov
--annotate --annotate-platform gitlab
--output-dir public/
artifacts:
paths: [public/]
expose_as: "Test Report"
Snapshot workflow (delta badges)¶
Run on merge to main to save the baseline:
Run on PR branches to compare:
trep report --tests results.xml --cov cov.out \
--baseline .trep/baseline.json \
--baseline-label "main"
# → delta badges appear: "+2 pass / -1 fail / +3.2% cov"
GitHub Actions example (full snapshot flow):
- name: Restore baseline snapshot
uses: actions/download-artifact@v4
with:
name: trep-baseline
continue-on-error: true # first run won't have a baseline
- name: Generate report
run: |
trep report \
--tests results.xml \
--cov coverage.out \
--baseline .trep/baseline.json \
--baseline-label "main" \
--save-snapshot .trep/new-baseline.json \
--output-dir dist/
- name: Upload new baseline (on main only)
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: trep-baseline
path: .trep/new-baseline.json
Enforcing thresholds¶
| Use case | Flag(s) |
|---|---|
| Fail if any test failed | --fail (test) or --fail-tests (report) |
| Fail if line coverage below N% | --threshold N --fail (cov) or --threshold N --fail-cov (report) |
| Fail if branch coverage below N% | --threshold-branch N --fail |
| Fail if function coverage below N% | --threshold-func N --fail |
Thresholds draw a visual red marker on the coverage bar in the HTML report independent of --fail.