Skip to content

Packaging ignore

Keep files out of the contract you publish. Put a .pactoignore file next to pacto.yaml, write patterns the way you would in .gitignore, and pacto pack and pacto push leave the matching files out. Use it for build output, editor files and anything secret, such as the sample config you inferred a schema from.

Example .pactoignore

# Build artifacts
dist/
build/
*.log

# Editor files
.vscode/
.idea/
*.swp

# Temporary files
tmp/
*.tmp

# Large binaries not needed in the bundle
data/*.bin

# Include specific exception
!data/config.bin

The final !data/config.bin re-includes one file that an earlier pattern excluded (negation).


Syntax

.pactoignore follows the same pattern matching rules as .gitignore:

Pattern Behavior
# at start of line Comment (ignored)
Blank lines Ignored
* Match any number of characters except /
? Match a single character except /
[abc] Character class: match a, b or c
** Match zero or more directories
/ at start Anchor to the contract root
/ at end Match directories only
! at start Negate the pattern (include matching files even if earlier patterns excluded them)

The last matching pattern wins: if a file matches several, the last one decides whether it is left out or kept.


Default ignores

These patterns are always applied, even when no .pactoignore file exists:

  • .git/
  • .pactoignore
  • .DS_Store
  • pacto-plan.md, the plan pacto ci writes on GitLab CI

Note: pacto.lock is not in the default ignore list. When a lockfile is present it ships inside the bundle by default (see the lockfile). To keep it out of a pushed bundle, add an explicit pacto.lock line to .pactoignore.


Immutable files

pacto.yaml is never ignorable. Listing it in .pactoignore has no effect, because the bundle always includes the contract file.


Referenced file validation

Ignoring a file that is referenced by the contract makes pacto validate, pacto pack and pacto push fail. You cannot ship a bundle missing a file it declares.

For example, if your contract references interfaces/openapi.yaml and your .pactoignore contains:

interfaces/openapi.yaml

Then pacto pack and pacto push exit with contract validation failed with N error(s) and nothing more. Under -v both add a debug line carrying the error count, never the file name. To see the message naming the file, run pacto validate: it prints FILE_NOT_FOUND (e.g. interface spec file "interfaces/openapi.yaml" not found in bundle). Neither command reports which ignore pattern excluded it.

The same rule applies to configurations[].schema, policies[].schema and any other file path declared in pacto.yaml.


At the repository root

A .pactoignore at the repository root also hides folders from discovery. A directory pattern there, such as services/legacy/, keeps that folder out of pacto ci, pacto fleet --local and pacto dashboard --local. pacto ci names each folder it skips and the line that skipped it:

skipped: services/legacy (from .pactoignore:1)

Discovery also stops 8 levels below the root, and pacto ci and pacto migrate name each folder that limit cuts, as skipped: <folder> (from depth limit 8). Hidden folders, node_modules and vendor are skipped without a line.

Only folders are matched, so pacto.yaml is still always kept inside a bundle. When the repository root is itself a service, its bundle and discovery share this one file. A root .pactoignore that cannot be read stops these commands with an error.


Commands affected

.pactoignore is applied by:

  • pacto pack: files matching ignore patterns are excluded from the tar.gz archive
  • pacto push: files matching ignore patterns are excluded from the OCI artifact
  • pacto init: files matching ignore patterns are not read when it drafts a contract from the folder, so none of them lands in the manifests artifact's build command
  • pacto ci and pacto fleet --local: folders matching a directory pattern of the root .pactoignore are not searched for services

Every command that loads a local bundle reads through the ignore filter, so ignored files are invisible to all of them. The commands that validate the bundle (validate, pack, push) hard-fail on a missing referenced file, while graph, diff, doc and explain do not see the file and produce incomplete output. Only pacto pack and pacto push additionally package the filtered file set into the shipped artifact.


Pattern examples

  • /docs/: anchored: matches docs/ at the contract root only
  • *.log: unanchored: matches build.log and output/build.log
  • tmp/: trailing slash matches only the directory tmp/
  • !README.md after *.md: re-includes README.md; place negations after the broader exclude