CI checks and inventory
Three commands connect your CI to Pratique. One fails a build when a lockfile goes around Pratique, one reports what each project uses, and one records what each build made and used.
The pratique command that runs the server also has client commands for CI. Each one is a
single static binary call with no other dependencies.
| Command | What it does | Needs a token |
|---|---|---|
pratique lockcheck | Fails when a lockfile would fetch from anywhere but Pratique. | No. It only reads local files. |
pratique inventory | Reports the packages a project's lockfiles list, for the Projects page. | Yes |
pratique build record | Records what a CI run made and what went into it, for the Builds page. | Yes |
For inventory and build record, set PRATIQUE_TOKEN to an access token, or
pass --token. Use a bot token: an admin creates one under Access tokens by choosing
A bot or CI system, so the records name the system and not a person. See tokens.
All three commands take --registry, the address of your Pratique server. If you leave it out, they use
PRATIQUE_PUBLIC_URL from the environment.
Check lockfiles
A lockfile records where each package comes from. If one points at the public registry, a Git repository or a
direct URL, the next install goes around Pratique and none of its checks apply. pratique lockcheck finds
those entries and fails the build.
pratique lockcheck --registry https://pratique.example.com
It reads these files: package-lock.json, npm-shrinkwrap.json, yarn.lock,
pnpm-lock.yaml, uv.lock, poetry.lock, composer.lock, and any
.txt file whose name contains requirements. It searches the paths you give it, or the current
directory if you give none, and skips node_modules, .git, .venv,
venv, vendor, __pycache__, .tox, dist and
build.
- Each finding is printed as file, line and source. The command then fails, and tells you to regenerate those lockfiles with Pratique as the registry.
- No lockfiles fails too. If it finds nothing to check, it fails with "no lockfiles found, so nothing was checked". A wrong path can't pass quietly.
- Credentials are redacted. If a source URL contains a user name or password, the output shows
REDACTEDin its place, so CI logs don't capture it.
The Connect page shows this command with your server's address filled in. Run it on every pipeline, because it is fast and needs no token. See enforce it for why this matters.
Report what each project uses
When a package is reported as malware, you need to know who has it. Download records only cover what passed through
Pratique. A project's lockfiles also cover what was installed before Pratique existed. pratique inventory
sends those lockfiles' package names and versions to Pratique.
export PRATIQUE_TOKEN="$PRATIQUE_CI_TOKEN"
pratique inventory --registry https://pratique.example.com --project acme/api .
It reads the same lockfiles as lockcheck, and also go.sum. It sends names and versions,
never your code.
- Each report replaces the last one for that project, so a package the project dropped stops counting against it. Report from your default branch, so a feature branch doesn't replace what is in production.
- It fails on known malware. If the project uses a version that is already reported as malware, the command prints each one and fails, so the build stops.
- It fails if it finds no lockfile, with "no lockfile found, so nothing was reported".
The Projects page lists every project, its status, how many packages it lists, when its lockfile was reported and by whom. Who uses this package? searches across all projects at any time. When a package is reported as malware, the hourly recheck opens an incident that names every project that lists that version.
A project that doesn't report isn't covered. A project that hasn't reported for 30 days shows as Out of date.
To try it without CI, use Or upload a lockfile to try it at the bottom of the Projects page. Enter a Project name, choose a Lockfile of up to 32 MB with its usual file name, and choose Add project.
Record builds
A build record links a CI run to what it made and what went into it. In an incident it answers two questions: this package is bad, so which builds used it? And this artifact is in production, so which commit made it? Add the command to the end of a CI job:
pratique build record --registry https://pratique.example.com \
--produces npm:acme-api@1.2.3=dist/acme-api-1.2.3.tgz .
On GitHub Actions and GitLab CI, it reads the build's name, number, commit, branch, repository and link from the CI environment. Elsewhere, pass them yourself.
| Flag | Meaning |
|---|---|
--name, --number | The build's name, such as acme/api, and this run's number. Required outside GitHub Actions and GitLab CI. |
--commit, --repo, --branch, --url | The commit built, the repository's address, the branch, and a link to the run. Optional. |
--status | success, failure or cancelled. Optional, and never detected from CI. |
--produces | An artifact the build made, as npm:name@1.2.3. Add =path to record the file's SHA-256 hash. Repeat the flag for each artifact. |
| Paths at the end | Where to look for lockfiles, the same files pratique inventory reads. Without a path, no lockfiles are read, so give . for the current directory. |
Put the flags before the paths. Reporting the same name and number again replaces that record.
What it checks
- Known malware. The command fails if the build used a version already reported as malware.
- The stored artifact. If you gave
=path, it compares the file's hash with the file Pratique stores under that name and version. If they differ, the command fails and an incident opens. That is what a stolen publish token looks like: someone else's file under your version.
Because it compares with what is stored, record the build after you publish, not before.
Later, the hourly recheck looks at what builds from the last 90 days used. When a package is reported as malware, the incident and the package's page name those builds.
Find a build
Use Find a build on the Builds page. You can search by a build's name, a commit, a
file's hash, or a package such as lodash@4.17.20.
CI reports these records, so they are only as true as CI. To prove where a release was built, use signed provenance.
Who can report under a name
Project and build records decide who gets a malware alert and what storage cleanup keeps. So each name has one owner, and a token can't rewrite what another team reported. Projects and builds share one set of names, because they usually name the same repository.
- The first report claims the name. It goes to the token's team. If the token has no team, it goes to the person or bot.
- After that, only the owner or an admin can report under it. Any other token gets a 403 that names the owner, and the attempt shows as Report refused under Activity. An admin's report doesn't take the name over.
- Moving a token into a team moves the names it owns to that team on its next report.
- To reassign a name, an admin opens the project or build and uses Owner. Choose a team under New owner, or Whoever reports next to free the name, then choose Change owner.
A name nobody owns can be claimed by anyone with a token. To stop someone with no team from claiming a new name, set
access.claim_needs_team: true or PRATIQUE_CLAIM_NEEDS_TEAM=true. Either way, report your
important projects early. See teams.
If a new bot token with a different name takes over reporting, reassign the names first, or its reports are refused.
Use the same token for inventory and build record in one repository, because they share the
name.
Example CI jobs
The Docker image contains the pratique binary at /pratique. It is a static binary, so you can
copy it out of the image and run it on the CI machine. Running it on the CI machine, and not inside a container, lets
build record read the CI environment.
GitHub Actions
Store the bot token as a repository or organization secret named PRATIQUE_TOKEN.
name: pratique
on: [push]
jobs:
check:
runs-on: ubuntu-latest
env:
PRATIQUE_PUBLIC_URL: https://pratique.example.com
PRATIQUE_TOKEN: ${{ secrets.PRATIQUE_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Get the pratique command
run: |
docker create --name pratique-cli ghcr.io/justpolidor/pratique:latest
docker cp pratique-cli:/pratique "$RUNNER_TEMP/pratique"
docker rm pratique-cli
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Check lockfiles
run: pratique lockcheck
- name: Report what this project uses
if: github.ref_name == github.event.repository.default_branch
run: pratique inventory --project "$GITHUB_REPOSITORY" .
In a release job, after the publish step, add the build record:
- name: Record the build
run: |
pratique build record \
--produces "npm:acme-api@${VERSION}=dist/acme-api-${VERSION}.tgz" .
GitLab CI
The image has no shell, so it can't be a job's image. Copy the binary out with Docker-in-Docker, which
needs a runner that allows it. Store the bot token as a masked CI/CD variable named PRATIQUE_TOKEN.
.pratique:
image: docker:27
services: [docker:27-dind]
variables:
PRATIQUE_PUBLIC_URL: https://pratique.example.com
before_script:
- docker create --name pratique-cli ghcr.io/justpolidor/pratique:latest
- docker cp pratique-cli:/pratique /usr/local/bin/pratique
- docker rm pratique-cli
pratique-lockcheck:
extends: .pratique
script:
- pratique lockcheck
pratique-inventory:
extends: .pratique
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- pratique inventory --project "$CI_PROJECT_PATH" .
In a release job that extends .pratique, run pratique build record after the publish step,
in the same way as on GitHub Actions.
If your runners can't run Docker, build the binary from source instead. See install.