#cargo #publish #workspace #all

bin+lib cargo-publish-all

Tool to publish all packages

9 releases (4 breaking)

0.5.3 Jun 16, 2019
0.5.2 Jun 16, 2019
0.5.1 Dec 30, 2018
0.4.1 Dec 26, 2018
0.1.0 Dec 23, 2018

#167 in Cargo plugins

Download history 6/week @ 2020-12-24 8/week @ 2020-12-31 6/week @ 2021-01-07 8/week @ 2021-01-14 7/week @ 2021-01-21 5/week @ 2021-01-28 6/week @ 2021-02-04 23/week @ 2021-02-11 33/week @ 2021-02-18 10/week @ 2021-02-25 7/week @ 2021-03-04 6/week @ 2021-03-11 8/week @ 2021-03-18 42/week @ 2021-03-25 7/week @ 2021-04-01 16/week @ 2021-04-08

51 downloads per month

MIT/Apache

25KB
539 lines

cargo-publish-all

coverage license crate

Use at your own risk.

This tool scans the current workspace, builds every package as if it was published and publishes the ones that do not exist yet on crates.io. If at any point the validation fails it will stop.

Validation consists of two phases:

  1. Package & normalize all packages; replace version dependencies for crates that will be published with paths and try building every package.
  2. If the first pass succeeds, publish all packages in the correct order. This will verify a second time, and should ideally never fail. However, it's better to be safe.

If an error is only detected in phase 2 (which should not happen), half of the workspace will be published (and build successfully), the other half won't be on crates.io. This is definitely better than having broken packages on crates.io.

Usage

cargo install cargo-publish-all
cargo-publish-all

Note that you need to confirm the "publishing plan" by entering "y". If you don't want this, specify --yes:

cargo-publish-all --yes

Since this tool is still in its early phase, it may not always work as expected. Thus, you can use --dry-run to make sure it behaves as expected, without pushing to crates.io:

cargo-publish-all --dry-run

Note: This will always fail for the second crate, which is a known issue. You can still see what it would do, though. This should be improved in the future.

Showing more output

By default, cargo-publish-all will hide all output except errors and high-level status messages since the output will become quite big. You can change that using the --verbose flag.

Docker

There is a docker image for using cargo-publish-all. It can be accessed using

registry.gitlab.com/torkleyy/cargo-publish-all

GitLab CI

Note that you should have an environment variable CRATES_IO_TOKEN defined (and protected!).

crates.io:
  image: registry.gitlab.com/torkleyy/cargo-publish-all:latest
  stage: deploy
  script:
  - cargo-publish-all --token $CRATES_IO_TOKEN --yes
  only: 
    refs:
    - master

This will allow everybody with write access to trigger a push to crates.io. Also note that secret varibles are not masked and can be revealed by merging a changed script.

Help

cargo-publish-all --help
cargo-publish-all 0.2
Thomas Schaller <torkleyy@gmail.com>
Upload workspace packages to crates.io

USAGE:
    cargo-publish-all [FLAGS] [OPTIONS]

FLAGS:
        --allow-dirty      Allow dirty working directories to be packaged
        --dry-run          Perform all checks without uploading
    -h, --help             Prints help information
        --manifest-path    Path to Cargo.toml
    -V, --version          Prints version information
        --verbose          Show more output
        --yes              Confirm publishing without interaction

OPTIONS:
        --token <TOKEN>    Token to use when uploading

Example output

$ cargo-publish-all     
   Resolving workspace
    Fetching crates.io versions
Skipping crate `nitric-lock-internals`, version already published
Skipping crate `nitric`, version already published
   Verifying workspace
   Verifying nitric-lock-internals
   Verifying nitric-lock
   Verifying nitric
Summary:
nitric-lock-internals: 0.0.1 (skipped)
nitric-lock: 0.0.1
nitric: 0.0.1 (skipped)
Continue? [y/N] y
  Publishing workspace
    Skipping nitric-lock-internals
  Publishing nitric-lock
    Skipping nitric

Behavior

The high-level behavior can be described as follows:

Publishes every unpublished crate of the current workspace, provided all members of the workspace will build when pulled from crates.io.

This means you can simply run this on CI and it will publish crates as soon as the version number is bumped.

Example cases

Note: the following properties should be tested in the future

  • Executing cargo-publish-all a second time should have no effect
  • cargo-publish-all for a single-crate workspace is equivalent to cargo publish

TODO:

  • Proper logging, no use of println!
  • show how versions are bumped (0.1.2 -> 0.1.3)
    • bumping older versions (how to display this?)
  • try merging this into Cargo
    • maybe too opinionated?
    • cargo-publish-all is idompotent, cargo publish not

Dependencies

~49MB
~1M SLoC