Skip to content

CI integration

license-audit check is built for CI pipelines. It returns three distinct exit codes so a pipeline can tell real violations apart from packages whose license couldn't be detected.

It audits your installed environment, so install dependencies before running it. The examples below do this with uv sync --locked.

license-audit itself needn't be one of those dependencies. Like other pipeline checks, it inspects the environment from outside: the examples run it with uvx, which fetches license-audit into an environment of its own and audits the project's .venv. That keeps license-audit's own dependencies out of the audit, and works for a project that supports a Python older than license-audit needs, where adding it as a dependency fails. Without uv, pipx run license-audit check does the same; point --target at your virtualenv if it isn't the project's .venv.

An unpinned run isn't tied to a release, and a new release can change results (see versioning and stability), so pin the version where a run must be reproducible: uvx license-audit@X.Y.Z check.

Exit codes

Code Meaning
0 All dependencies pass the policy
1 Policy violation (incompatible licenses, denied licenses, or category exceeded), a required dependency missing from the environment (usually the wrong environment was audited), or the check could not run (bad arguments, no environment found, invalid config)
2 Unknown licenses detected and no other violation (when fail-on-unknown = true)

A definite violation always takes precedence: a run with both a violation and unknown licenses exits 1, so exit 2 reliably means the unknowns are the only remaining problem. Anything that stops the check from running also exits 1, never 2. All check output goes to stderr; stdout stays clean for redirection.

GitHub Actions

Minimal:

jobs:
  license-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: astral-sh/setup-uv@v7
      - run: uv sync --locked
      - run: uvx license-audit check

This audits everything uv sync installs, dev tools included. To audit only what you ship, see production dependencies only.

Show the compliance report as a PR job summary, even when check fails:

      - name: Compliance summary
        if: always()
        run: uvx license-audit report --format markdown >> $GITHUB_STEP_SUMMARY

Upload the compliance report and notices as build artifacts:

      - name: Generate reports
        if: always()
        run: |
          uvx license-audit report --output COMPLIANCE.md
          uvx license-audit report --format notices --output THIRD_PARTY_NOTICES.md
      - uses: actions/upload-artifact@v7
        if: always()
        with:
          name: license-report
          path: |
            COMPLIANCE.md
            THIRD_PARTY_NOTICES.md

GitLab CI

license-check:
  image: python:3.12
  before_script:
    - pip install uv
    - uv sync --locked
  script:
    - uvx license-audit report --format markdown --output compliance.md
    - uvx license-audit check
  artifacts:
    when: always
    paths:
      - compliance.md

The report comes first because a failing check ends the script, while report exits 0 whether or not the policy passes, so the artifact is there when you need it most.

pre-commit hook

Catch violations locally before they reach CI. Add to .pre-commit-config.yaml:

- repo: local
  hooks:
    - id: license-audit
      name: license-audit
      entry: uvx license-audit check
      language: system
      pass_filenames: false
      stages: [pre-push]

Running on the pre-push stage (instead of every commit) keeps commits fast and only runs the check once before pushing.

Branching on exit codes

Exit 2 is distinct from 1 so CI can treat undetected licenses differently from policy violations:

ec=0
uvx license-audit check || ec=$?
case $ec in
  0) ;;
  2) echo "::warning::Unknown licenses: resolve them in pyproject.toml" ;;
  *) echo "::error::License check failed (exit $ec)"; exit 1 ;;
esac

|| ec=$? keeps a failing check from ending the script before the case, since CI shells stop at the first failing command (GitHub Actions runs bash -e). The catch-all arm fails the step on any other code, such as a process killed for running out of memory, instead of letting it pass.

Different policies in separate jobs

--policy sets the level without touching pyproject.toml:

- name: Strict permissive check
  run: uvx license-audit --policy permissive check

- name: Allow weak copyleft
  run: uvx license-audit --policy weak-copyleft check

Available levels: permissive, weak-copyleft, strong-copyleft, network-copyleft.

Production dependencies only

uv sync installs the dev group by default, so the examples on this page audit your development tools too: a copyleft dev tool such as pylint (GPL-2.0-or-later) fails a permissive or weak-copyleft policy although you never ship it. To audit only your runtime dependencies, leave the dev group out when you provision:

      - run: uv sync --locked --no-dev
      - run: uvx license-audit check

Don't run license-audit through uv run here: it syncs the project first, which installs the dev group again.

Adding a new dependency

Typical flow when introducing a new package:

  1. uv add <package> (or edit pyproject.toml and uv sync).
  2. Run uvx license-audit check locally.
  3. Handle the outcome:
  4. Exit 0: commit and push.
  5. Exit 2 (unknown): the license couldn't be classified. When detection found no SPDX identifier, confirm the license and add an override; for a valid SPDX license the OSADL data doesn't cover, record your judgement instead:
    [tool.license-audit.overrides]
    new-package = "MIT"
    
    [tool.license-audit.license-classifications]
    "CC-BY-SA-4.0" = "weak-copyleft"
    
  6. Exit 1 (policy violation): swap the dependency for a differently-licensed alternative, add the license to allowed-licenses, relax policy (e.g. permissive to weak-copyleft), or, if you've reviewed the package manually and confirmed it's safe for your case, exempt it:
    [tool.license-audit.ignored-packages]
    flagged-package = "Reviewed manually; OSADL flag doesn't apply to our use case"
    

Check flags

uvx license-audit check                        # default: fail on unknowns
uvx license-audit check --no-fail-on-unknown   # tolerate unknowns (exit 0 if only unknowns; exit 1 if policy violations)
uvx license-audit check --fail-on-unknown      # explicit opt-in

The flag overrides fail-on-unknown in pyproject.toml.