Publish to crates.io when the version changes - #13
Merged
Conversation
Releases were manual: bump, merge, then remember to run cargo publish from a clean checkout. The remembering is the part that fails. Merging a Cargo.toml version bump to master now publishes that version and tags the commit. Built around the fact that a publish cannot be undone and a version number can never be reused: - The registry, not a diff, decides whether work is needed. A rerun, a revert or a manual publish all leave a diff misleading and the registry correct, so an accidental rerun is a no-op rather than a failure. - Only Cargo.toml triggers it, since only Cargo.toml carries the version, so an ordinary merge publishes nothing. - A concurrency group serializes it, so two merges in quick succession cannot race each other into the registry. - The full check suite runs inside the publish job rather than trusting the CI workflow to have finished. Both fire on the same push and nothing orders them. - The tag is pushed after a successful publish, so it never points at a version that failed to go out. - A missing token fails with its name and where to add it, rather than as an authentication error from cargo part way through a release. The token is read through the environment rather than interpolated into a command, so it cannot reach a shell trace. Both branches of the version check were run locally against the real registry before this was committed: 0.2.1 correctly reads as needing publication and 0.2.0 as already done.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Answers "did you wire up auto push to crates on version change?" — no, and now yes.
Merging a
Cargo.tomlversion bump tomasterpublishes that version and tags the commit.Designed around publishing being irreversible
A published version can never be unpublished or reused, so every choice here favours doing nothing over doing something twice:
Cargo.tomltriggers it, since onlyCargo.tomlcarries the version. An ordinary merge publishes nothing.The token is read through the environment rather than interpolated into a command, so it cannot reach a shell trace.
Verified before pushing
Both branches of the version check were run locally against the real registry:
One thing you have to do
The repository has no secrets configured. I checked, and I am deliberately not handling the token value.
Create one at https://crates.io/settings/tokens with
publish-updatescope, then add it asCARGO_REGISTRY_TOKENunder Settings → Secrets and variables → Actions.Until then the job fails loudly with that instruction rather than silently skipping.
What happens when this merges
Master is already at 0.2.1, which is not published. So merging this PR touches
Cargo.toml... actually it does not — this PR only adds a workflow file. The trigger ispaths: ["Cargo.toml"], so merging it publishes nothing.To release 0.2.1 once the secret exists, run the workflow manually (
workflow_dispatchis enabled for exactly this), or let the next version bump carry it. I would suggest the manual run, so the first execution is watched rather than incidental.