Description

The cargo crawler looks recursively for all cargo crates from a specific root directory. Then for each of them, it tries to update dependencies specified in Cargo.toml.

Dependencies are read from:

  • [dependencies]

  • [dev-dependencies]

  • [build-dependencies]

  • the [workspace.dependencies] equivalents

This crawler can be enabled either automatically with default behavior by running updatecli diff from a directory containing the files to update. Or by providing a manifest. The automatic discovery behavior can be tuned by providing a YAML manifest with a cargo crawler in top-level directive autodiscovery as explained in the "Autodiscovery" page.

Requirements

Updates are applied by running cargo, so the toolchain has to be reachable from the environment running Updatecli.

Important
If a Cargo.lock sits next to Cargo.toml and neither the cargo command nor cargo upgrade can be found, the whole crate is skipped with a warning. Updatecli will not bump a dependency it cannot re-lock.

cargo upgrade comes from cargo-edit. When it is available, both Cargo.toml and Cargo.lock are updated. When only plain cargo is available, a reduced command is generated that refreshes the lock file alone.

Generated manifests

Each dependency produces:

  • a cargopackage source resolving the latest crate version,

  • a shell condition that stops the pipeline when the discovered version already matches what is declared,

  • a shell target invoking cargo upgrade and cargo update, guarded by a file/checksum over Cargo.toml and Cargo.lock.

The generated command honours Updatecli’s dry-run mode by passing --dry-run to cargo when $DRY_RUN is set, so updatecli diff does not modify the crate.

Private registries

Use registries to describe a non-default crate registry, so generated sources resolve versions against it rather than crates.io.

Manifests

Parameters

The crawler cargo supports the following parameters:

NameTypeDescriptionRequired
ignorearray

“ignore” defines rules to exclude matching crates from the autodiscovery.

remark:

  • a crate is ignored when it matches at least one rule.
    cratesobject

“crates” defines the crates to match, keyed by crate name.

remark:

  • an empty value matches any version.
  • otherwise the value is a semantic version constraint, such as “>=1.0.0”.
  • when the version or the constraint cannot be parsed, the value must equal the version.
    pathstring

“path” defines a “Cargo.toml” path pattern.

remark:

  • the pattern must match the whole path, not just a substring.
  • the pattern follows the Go filepath.Match syntax, such as “*” or “?”.
    registriesarray

“registries” defines the Cargo registry names to match.

remark:

  • the registry name is the “registry” key of a dependency in “Cargo.toml”.
  • a registry name must be identical to one of the entries.
onlyarray

“only” defines rules to restrict the autodiscovery to matching crates.

remark:

  • a crate is kept only when it matches at least one rule.
    cratesobject

“crates” defines the crates to match, keyed by crate name.

remark:

  • an empty value matches any version.
  • otherwise the value is a semantic version constraint, such as “>=1.0.0”.
  • when the version or the constraint cannot be parsed, the value must equal the version.
    pathstring

“path” defines a “Cargo.toml” path pattern.

remark:

  • the pattern must match the whole path, not just a substring.
  • the pattern follows the Go filepath.Match syntax, such as “*” or “?”.
    registriesarray

“registries” defines the Cargo registry names to match.

remark:

  • the registry name is the “registry” key of a dependency in “Cargo.toml”.
  • a registry name must be identical to one of the entries.
registriesobject

“registries” defines the Cargo registries used by the generated manifests, keyed by registry name.

remark:

  • the key is the name set in the “registry” key of a dependency in “Cargo.toml”.
    authobject“auth” defines the credentials used to authenticate with the cargo registry.
        headerformatstring

“headerformat” defines the format of the Authorization header sent with “token”.

default: Bearer %s

remark:

  • “%s” is replaced by the token.

example:

  • headerformat: “Token %s”
        tokenstring“token” defines the cargo registry token used for authentication.
    rootdirstring

“rootdir” defines the local directory of a cargo registry index, used instead of the registry API.

remark:

  • “url”, “rootdir” and “scmid” are mutually exclusive.
    scmidstring

“scmid” defines the scm holding the cargo registry index, used instead of the registry API.

remark:

  • only used by the cargo autodiscovery.
  • “url”, “rootdir” and “scmid” are mutually exclusive.
    urlstring

“url” defines the URL of the cargo registry API.

default: https://crates.io/api/v1/crates, when neither “rootdir” nor a scm is set.

remark:

  • “url”, “rootdir” and “scmid” are mutually exclusive.
rootdirstring

“rootdir” defines the directory where the crawler starts searching for “Cargo.toml” files.

default: the scm directory when “scmid” is set, otherwise the directory relative paths resolve from, by default the working directory.

remark:

  • a relative path is resolved from the default directory.
  • an absolute path is used as is, instead of the scm directory.
versionfilterobject

“versionfilter” defines the version filter used by the generated manifests.

default: kind “semver” with pattern “*”, the latest version.

remark:

  • with kind “semver”, “pattern” accepts:
    • “prerelease”: the latest prerelease of the current version.
    • “patch”: patch updates only.
    • “minor”: patch and minor updates.
    • “minoronly”: minor updates only.
    • “major”: patch, minor and major updates.
    • “majoronly”: major updates only.
    • a version constraint, such as “>= 1.0.0”.
  • with kind “regex”, “pattern” accepts a regular expression.
  • with kind “semver” and a pattern other than “*”, a dependency whose version is not a strict semantic version uses its declared version as the pattern.
  • more examples at https://www.updatecli.io/docs/core/versionfilter/

example:

versionfilter:
  kind: semver
  pattern: minor
    kindstring

“kind” defines the versioning scheme used to select a version.

default: latest

remark:

  • accepted values are “latest”, “semver”, “regex”, “regex/semver”, “time”, “regex/time”, “lex” and “pep440”.
  • “latest” returns the last version of the list.
  • “lex” sorts the versions lexicographically and returns the last one.
  • “pep440” follows https://peps.python.org/pep-0440/

example:

  • kind: semver
    patternstring

“pattern” defines the version pattern, according to “kind”.

default:

  • latest: “latest”
  • semver and pep440: “*”
  • regex: “.*”
  • time and regex/time: “2006-01-02”

remark:

  • for “latest”, “latest” returns the last version, any other value must match a version exactly.
  • for “semver” and “regex/semver”, it is a semantic versioning constraint.
  • for “pep440”, it is a pep440 version specifier.
  • for “regex”, it is a regular expression.
  • for “time” and “regex/time”, it is a Go date layout.
  • ignored by “lex”.

example:

  • pattern: ~1.2
  • pattern: “>=1.0.0 <2.0.0”
  • pattern: ^v\d+.\d+.\d+$
    regexstring

“regex” defines the regular expression extracting the version from each entry.

remark:

  • only used by the kinds “regex/semver” and “regex/time”.
  • the value of the first capture group is used as the version.

example:

  • regex: ^v(\d+.\d+.\d+)$
    replaceallobject

“replaceall” applies a regular expression replacement to each version before filtering.

remark:

  • only used by the kinds “regex”, “regex/semver” and “regex/time”.
  • the replacement runs before “pattern” or “regex” is evaluated.

example:

replaceall:
  pattern: "_"
  replacement: "."

turns “curl-8_15_0” into “curl-8.15.0”.

        patternstring

“pattern” defines the regular expression matching the text to replace.

example:

  • pattern: “_”
        replacementstring

“replacement” defines the text replacing each match of “pattern”.

remark:

  • capture groups can be referenced with $1, $2, and so on.

example:

  • replacement: “.”
    strictboolean

“strict” enforces strict semantic versioning rules when parsing versions.

default: false

remark:

  • only used by the kinds “semver” and “regex/semver”.
⚠ This table is generated from the Updatecli codebase and may contain inaccurate data. Feel free to report them on github.com/updatecli/updatecli

Example

# updatecli.d/default.yaml
name: "Cargo compose autodiscovery using git scm"
scms:
  default:
    kind: git
    spec:
      url: https://github.com/updatecli-test/cargo-lab.git
      branch: "main"
  private-registry:
    kind: git
    spec:
      url: "https://github.com/updatecli-test/fake-cargo-registry.git"
      branch: "main"

autodiscovery:
  scmid: default
  crawlers:
    cargo:
      registries:
        fake-private-git:
          scmid: private-registry
        fake-private-http:
          url: "https://updatecli-test.github.io/fake-cargo-registry/api/v1/crates"