GitHub Action

The action installs tx0, fails the job on findings a pull request introduced, keeps the cache of tx0 between runs, and uploads the findings to GitHub code scanning.

All docs pages

The action is read from the tx0 repository, which is not public yet. Until it is, the workflow on CI runs the same check with tx0 installed from PyPI.

The workflow

.github/workflows/tx0.yml
name: tx0
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
  security-events: write
jobs:
  tx0:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: tx0io/tx0@main

On a pull request, only findings that are new since the base count for the gate. On a push to main, the whole tree is checked. To pin the version and pass more arguments to tx0 check:

.github/workflows/tx0.yml
      - uses: tx0io/tx0@main
        with:
          version: 0.1.0-alpha.3
          args: --tier recommended

What it does

  1. Picks the build for the runner: Linux, macOS or Windows, x86_64 or arm64. With version: latest it asks GitHub for the newest release.
  2. Restores the binary and the result store of tx0 from the Actions cache. Results are keyed by content, so an older entry is always safe to reuse.
  3. On a pull request, finds the base from the merge commit GitHub prepared and fetches it if the checkout does not have it. The default shallow checkout is enough.
  4. Writes SARIF for the whole tree, then runs tx0 check --since BASE, so the exit code counts only what the pull request introduced. Code scanning compares whole result sets, which is why the upload gets every finding.
  5. Saves the cache and uploads the SARIF file. Pull requests from forks get a read-only token and skip the upload.

The gate is the [gate] table of tx0.toml; without it, any new finding fails the job.

Inputs

version
the tx0 version to install, such as 0.1.0; default latest
working-directory
where to run tx0, relative to the workspace; default .
args
more arguments for tx0 check, such as --tier recommended or paths; default empty
base
the revision whose findings count as known; on pull requests, the base the pull request is merged into; on other events the whole tree is reported; default empty
cache
keep the binary and the cache of tx0 between runs with the Actions cache; default true
upload-sarif
upload the findings of the whole tree to code scanning; needs security-events: write; default true
sarif-file
where to write the SARIF file; default tx0.sarif
token
the token for the GitHub API, used to find the newest release when only pre-releases exist; default github.token

Outputs

version
the installed tx0 version
exit-code
the exit code of the check: 0 passed, 1 the gate failed, 2 or 3 tx0 could not run

For other CI systems, CI has the commands to run.