Cargo Releases
This page documents deployments using dpl v1 which is currently the legacy version. The dpl v2 is released, and we recommend useig it. Please see our blog post for details. dpl v2 documentation can be found here.
Travis CI can automatically release your Rust crate to crates.io after a successful build. (Alternative registries may be supported in the future).
A minimal .travis.yml
configuration for publishing to crates.io looks as follows:
language: rust
deploy:
provider: cargo
token: "YOUR_API_TOKEN"
Obtain a crates.io API token #
An API token can be obtained by logging in to your crates.io account, and generating a new token at https://crates.io/me.
Always encrypt your API token. Assuming you have the Travis CI command line client installed, you can do it like this:
$ travis encrypt YOUR_API_TOKEN --add deploy.token
What to release #
Most likely, you would only want to deploy to crates.io when a new version of your package is cut. To do this, you can tell Travis CI to only deploy on tagged commits, like so:
deploy:
...
on:
tags: true
If you tag a commit locally, remember to run git push --tags
to ensure that
your tags are uploaded to GitHub.
You can explicitly specify the branch to release from with the on option:
deploy:
...
on:
branch: production
Alternatively, you can also configure Travis CI to release from all branches:
deploy:
...
on:
all_branches: true
Builds triggered from Pull Requests will never trigger a release.
Release build artifacts #
After your tests run and before the release, Travis CI will clean up any additional files and changes you made.
This is necessary because Cargo will refuse to publish crates from a dirty working directory (an option to allow this may be added to this provider in the future).
Run Commands Before or After Deploy #
Sometimes, you want to run commands before or after deploying. You can use the
before_deploy
and after_deploy
stages for this. These will only be triggered
if Travis CI is actually deploying.
before_deploy: "echo 'ready?'"
deploy:
..
after_deploy:
- ./after_deploy_1.sh
- ./after_deploy_2.sh