Skip to content

Parse the version from cargo pkgid with parameter expansion - #421

Merged
stepchowfun merged 1 commit into
mainfrom
unify-version-parsing
Oct 4, 2026
Merged

stepchowfun merged 1 commit into
mainfrom
unify-version-parsing

Conversation

@stepchowfun

Copy link
Copy Markdown
Owner

Unifies how the version is read from cargo pkgid on one form, parameter expansion:

PKGID="$(cargo pkgid)"
VERSION="${PKGID##*[#@:]}"

This strips everything through the last #, @, or :, leaving the version for every cargo pkgid format.

Replaced:

  • .github/workflows/ci.yml: cut -d# -f2 | cut -d: -f2. It handled Cargo's old name:version format, but with current Cargo it returns name@version whenever the checkout directory's name differs from the package name.
  • toast.yml (publish task): grep --extended-regexp --only-matching '[0-9.]+$'. It handled every format but truncated prerelease versions (1.2.3-beta.1 became .1).

Verified: with Cargo 1.99, cargo pkgid prints …/dir#1.2.3 when the directory matches the package name, …/dir#name@1.2.3 when it doesn't, and …#name@1.2.3-beta.1 for a prerelease. The expansion gave the right version in all three, while cut failed the last two and grep failed the prerelease. In this repository, I ran each changed line, extracted from the files, in Bash with set -euo pipefail (the CI step's shell, and the shell Toast tasks run in), and each produced the version cargo metadata reports. Both YAML files still parse.

This is the same change in all the Rust projects.

Status: Ready

Fixes: N/A

The version was parsed in the CI workflow and Toastfile in different ways. The CI workflow's `cut` commands expected Cargo's old `name:version` format and returned `name@version` with current Cargo when the directory name differs from the package name, and the Toastfile's `grep` truncated prerelease versions. Now each takes everything after the last `#`, `@`, or `:` in the package ID, which is the version in every format.
@stepchowfun
stepchowfun merged commit bb84b97 into main Oct 4, 2026
6 checks passed
@stepchowfun
stepchowfun deleted the unify-version-parsing branch October 4, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant