Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git tags when packaging #841

Open
steveklabnik opened this issue Nov 11, 2014 · 7 comments
Open

Git tags when packaging #841

steveklabnik opened this issue Nov 11, 2014 · 7 comments

Comments

@steveklabnik
Copy link
Member

Bundler does some cool git stuff when publishing a package[1]. Conceptually, with cargo commands instead, and with error handling and rollback elided, it does this:

$ cargo build
$ git diff --exit-code == 0
$ git diff-index --quiet --cached HEAD == 0
$ git tag -a -m \"Version #{version}\" #{version_tag} 
$ git push
$ git push --tags
$ cargo publish

(version is like 1.2.3 and version_tag is like v1.2.3)

Having the tags automatically created at the same commit as was released, plus ensuring that what's on github/whatever is the same as what's on crates.io would be pretty great.

1: https://github.com/bundler/bundler/blob/master/lib/bundler/gem_helper.rb#L47-L50

@shadowmint
Copy link

I don't have much to add to this except 1) yes please, and 2) version_tag should not be prefixed with v; this is a left over from pre-2.0 of semver and no longer part of the spec.

@bluss
Copy link
Member

bluss commented Jan 17, 2016

packagename-VERSION may be a good tag name pattern. It works for those that have many cargo packages per repository (which is quite common: regex, quickcheck, rand, etc, many do).

I don't think cargo should push.

@sbeckeriv
Copy link
Contributor

@steveklabnik how important is the push tag step? @bluss doesnt think it should push.

I have auto tagging configurable via cargo config. Its not clear to me yet on how to push tags via libgit2-rs. Also should the config live in the cargo toml so its project wide? I thought Cargo.toml was loaded in the config object but my test say otherwise.

https://github.com/rust-lang/cargo/compare/master...sbeckeriv:git-auto-tag-841?expand=1

let me know your thoughts/concerns/comments.
thanks
Becker

@Nemo157
Copy link
Member

Nemo157 commented May 4, 2016

Just thought I'd mention that I use an inverse workflow, I tag (with PGP signature) and use that as a trigger that the CI service should publish that commit to crates.io. I feel it comes closer to ensuring reproducible builds, the exact build steps taken (modulo the setup of the CI container) are specified in the .travis.yml/.gitlab-ci.yml/... file with the code. Not sure how common this might be compared to publishing from your local dev machine though.

If this auto-tagging is configurable that would ensure this workflow still works, I'm not sure if there's any other way that this could interact better/worse with it.

sbeckeriv added a commit to sbeckeriv/cargo that referenced this issue May 20, 2016
Dearest reviewer,

This is part of rust-lang#841 which is about the publishing and tagging flow.
This pull request just prevents publishing with uncommitted or untracked
files. I have included a flag for turning this off. There are two new
test.

More details about the full flow at
rust-lang#2443 . I plan on doing more
work on the flow, however, I felt this was useful enough to do stand
alone. When I tried the flow before I was doing to much at once.

Thanks!
Becker

[Updated]
Moved from config to flag
Using open_ext to sub crates
Include the file names in error message
include flag in error
Move to discover off of open_ext
formatting
sbeckeriv added a commit to sbeckeriv/cargo that referenced this issue May 20, 2016
Dearest reviewer,

This is part of rust-lang#841 which is about the publishing and tagging flow.
This pull request just prevents publishing with uncommitted or untracked
files. I have included a flag for turning this off. There are two new
test.

More details about the full flow at
rust-lang#2443 . I plan on doing more
work on the flow, however, I felt this was useful enough to do stand
alone. When I tried the flow before I was doing to much at once.

Thanks!
Becker

[Updated]
Moved from config to flag
Using open_ext to sub crates
Include the file names in error message
include flag in error
Move to discover off of open_ext
formatting
cut back on unwraps
rework file check logic with a bail
bors added a commit that referenced this issue Jun 11, 2016
Prevent packaging a crate if any files are dirty

This commit alters Cargo's behavior to prevent publishing a crate by default if
any files in that crate are determined to be dirty, that is either modified or
not part of the working tree.

This can prevent common mistakes like many listed in #2063 and enables features like #841.

Closes #1597
Closes #2063
@matklad
Copy link
Member

matklad commented Nov 13, 2018

Automatic tagging and pushing to the repo do raise some design questions.

A possibly simpler solution is to check that a tag exists before publishing. This should be done over here:

fn check_repo_state(

That can be extended later with an opt-in ‘—tag’ flag later, and could probably be made a default after edition switch? Code for that should probably go either in that cargo_package.rs file, or here:

pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> {

I don’t feel like adding taggging by default would work without opt-in at this moment, due to backwards compatibility requirements.

@dwijnand
Copy link
Member

This is available through https://github.com/sunng87/cargo-release.

Are we still interested in this being in cargo proper?

@steveklabnik
Copy link
Member Author

I very much am! I think being "standard" here is very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants