tx0 in CI
In a pull request, tx0 reports only the findings the change introduced and writes SARIF for a code scanning service. The exit code fails the job when the findings exceed the gate.
Check what a pull request introduced
tx0 check --since REV reports the findings that are new since the git revision REV. Findings are compared by rule and identity, not by line, so moved or reformatted code does not show up as new.
Use the merge base of the pull request as REV, so findings fixed on the main branch since the branch started are not counted. On the sample, after an edit to jobs/retry.py, only the finding in that file is reported:
$ tx0 check --since HEAD
warning[tx0/python:duplicate-condition]: `status == 429` is tested earlier in this chain, so this branch never runs
--> jobs/retry.py:6:10 74RVF0NHX
|
6 | elif status == 429:
| ^^^^^^^^^^^^^
2 | if status == 429:
| ^^^^^^^^^^^^^ first tested here
1 findings in 1 files; 1 files checked, 1 from the cache, 0 findings suppressed GitHub Actions
This workflow installs tx0 from PyPI, checks the pull request against its merge base and uploads the findings to code scanning, which shows them on the pull request.
fetch-depth: 0fetches the history, so the merge base can be found.if: always()uploads the report even when the gate fails the step.- The PyPI package runs on Linux x86_64, which
ubuntu-latestis.
The tx0 GitHub Action does the same in one step and keeps the cache between runs.
name: tx0
on: pull_request
permissions:
contents: read
security-events: write
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: pip install tx0
- run: tx0 check --since "$(git merge-base origin/$BASE HEAD)" --format sarif > tx0.sarif
env:
BASE: ${{ github.base_ref }}
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: tx0.sarifOther CI systems
Any CI that runs a command works the same way: install tx0 with the shell script, pip or npm, find the merge base and run the check. --format json writes one finding per line for other tools.
$ curl -LsSf https://tx0.io/install.sh | sh
$ tx0 check --since "$(git merge-base origin/main HEAD)" --format sarif > tx0.sarif The gate and existing findings
[gate] in tx0.toml sets how many reported findings of each level are allowed; without it, any finding fails. The exit code is 0 when the gate passes, 1 when the findings fail it, 2 for a usage or configuration error and 3 when tx0 could not run.
For a branch or a nightly job without a base to compare with, tx0 baseline records today's findings and tx0 check --new reports only the ones that are not in it. Start on existing code has the details.