Skip to content

Prep for semver bump and document current blocker #3338

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ parking_lot = "0.11"
rand = "0.7"
reqwest = { version = "0.11", features = ["blocking", "gzip", "json"] }
scheduled-thread-pool = "0.2.0"
semver = { version = "0.10", features = ["diesel", "serde"] }
semver = { version = "0.10", features = ["diesel", "serde"] } # TODO: Bump to 0.11 after steveklabnik/semver#217 is resolved
semver_next = { version = "0.11", package = "semver" }
sentry = "0.22"
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0.0"
Expand Down
1 change: 1 addition & 0 deletions src/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod dialoguer;
pub mod on_call;
pub mod populate;
pub mod render_readmes;
pub mod test_new_semver_release;
pub mod test_pagerduty;
pub mod transfer_crates;
pub mod verify_token;
71 changes: 71 additions & 0 deletions src/admin/test_new_semver_release.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use crate::{
db,
schema::{dependencies, versions},
};

use clap::Clap;
use diesel::prelude::*;

#[derive(Clap, Copy, Clone, Debug)]
#[clap(
name = "test-new-semver-release",
about = "Scan the database for all versions and version requirements to \
ensure they can be parsed by the latest `semver` crate."
)]
pub struct Opts {}

pub fn run(_opts: Opts) {
use self::dependencies::dsl::*;
use self::versions::dsl::*;

let url = db::connection_url(&dotenv::var("READ_ONLY_REPLICA_URL").unwrap());
let conn = PgConnection::establish(&url).unwrap();
conn.transaction::<_, diesel::result::Error, _>(|| {
let vers = versions.select(num).load(&conn)?;
test_versions(&vers);

let deps = dependencies.select(req).load(&conn)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure about loading all dependencies in a single query, but this is against the replica database and I expect memory usage to be somewhere around 100 MB so I think this is okay for our current scale.

test_dependency_predicates(&deps);

Ok(())
})
.unwrap();

println!("Test finished.");
}

fn test_versions(versions: &[String]) {
for version in versions {
if let Err(e) = semver::Version::parse(version) {
println!("Could not parse `{}` as a semver::Version: {}", version, e);
}
}

Comment on lines +38 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for version in versions {
if let Err(e) = semver::Version::parse(version) {
println!("Could not parse `{}` as a semver::Version: {}", version, e);
}
}

this looks like a duplicate to me, no?

for version in versions {
if let Err(e) = semver::Version::parse(version) {
println!("Could not parse `{}` as a semver::Version: {}", version, e);
}

if let Err(e) = semver_next::Version::parse(version) {
println!(
"Could not parse `{}` as a semver_next::Version: {}",
version, e
);
}
}
}

fn test_dependency_predicates(versions: &[String]) {
for version in versions {
if let Err(e) = semver::VersionReq::parse(version) {
println!("Could not parse `{}` as a semver::Version: {}", version, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!("Could not parse `{}` as a semver::Version: {}", version, e);
println!("Could not parse `{}` as a semver::VersionReq: {}", version, e);

}

if let Err(e) = semver_next::VersionReq::parse(version) {
println!(
"Could not parse `{}` as a semver_next::Version: {}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Could not parse `{}` as a semver_next::Version: {}",
"Could not parse `{}` as a semver_next::VersionReq: {}",

version, e
);
}
}
}
6 changes: 4 additions & 2 deletions src/bin/crates-admin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![warn(clippy::all, rust_2018_idioms)]

use cargo_registry::admin::{
delete_crate, delete_version, populate, render_readmes, test_pagerduty, transfer_crates,
verify_token,
delete_crate, delete_version, populate, render_readmes, test_new_semver_release,
test_pagerduty, transfer_crates, verify_token,
};

use clap::Clap;
Expand All @@ -20,6 +20,7 @@ enum SubCommand {
DeleteVersion(delete_version::Opts),
Populate(populate::Opts),
RenderReadmes(render_readmes::Opts),
TestNewSemverRelease(test_new_semver_release::Opts),
TestPagerduty(test_pagerduty::Opts),
TransferCrates(transfer_crates::Opts),
VerifyToken(verify_token::Opts),
Expand All @@ -33,6 +34,7 @@ fn main() {
SubCommand::DeleteVersion(opts) => delete_version::run(opts),
SubCommand::Populate(opts) => populate::run(opts),
SubCommand::RenderReadmes(opts) => render_readmes::run(opts),
SubCommand::TestNewSemverRelease(opts) => test_new_semver_release::run(opts),
SubCommand::TestPagerduty(opts) => test_pagerduty::run(opts).unwrap(),
SubCommand::TransferCrates(opts) => transfer_crates::run(opts),
SubCommand::VerifyToken(opts) => verify_token::run(opts).unwrap(),
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub const MISSING_RIGHTS_ERROR_MESSAGE: &str =
to accept an invitation to be an owner before \
publishing.";

pub const WILDCARD_ERROR_MESSAGE: &str = "wildcard (`*`) dependency constraints are not allowed \
pub const WILDCARD_ERROR_MESSAGE: &str =
"wildcard (`*` or `>= 0`) dependency constraints are not allowed \
on crates.io. See https://doc.rust-lang.org/cargo/faq.html#can-\
libraries-use--as-a-version-for-their-dependencies for more \
information";
Expand Down
1 change: 1 addition & 0 deletions src/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ fn env(var: &str) -> String {
}
}

#[track_caller]
fn json<T>(r: &mut AppResponse) -> T
where
for<'de> T: serde::Deserialize<'de>,
Expand Down
25 changes: 25 additions & 0 deletions src/tests/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,28 @@ fn version_size() {
.expect("Could not find v2.0.0");
assert_eq!(version2.crate_size, Some(91));
}

#[test]
fn accepts_complicated_semver_prerelease_and_build_identifiers() {
#[track_caller]
fn parse(s: &str) {
semver::Version::parse(s).expect("couldn't parse as Version");
semver::VersionReq::parse(s).expect("couldn't parse as VersionReq");
}

// Must provide at least major, minor, and patch so that it can parse as a Version
parse("1.0.0");

parse("1.0.0-1a");
parse("1.0.0-1.a");
parse("1.0.0-a1");
parse("1.0.0-a.1");

parse("1.0.0+01a");
parse("1.0.0+1.a");
parse("1.0.0+a01");
parse("1.0.0+a.01");

parse("1.0.0-01+01");
parse("1.0.0-01.-.a+01.a-01a-01a");
}