Skip to content

Commit

Permalink
Merge pull request #743 from wookietreiber/book/verification-in-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
foresterre committed Jul 16, 2023
2 parents 9077d45 + 59cf8d9 commit 0569209
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 127 deletions.
10 changes: 6 additions & 4 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
- [minimal](output-formats/minimal.md)
- [no-user-output](output-formats/no-user-output.md)
- [Commands](./commands/index.md)
- [cargo-msrv](./commands/find.md)
- [cargo-msrv help](./commands/help.md)
- [cargo-msrv list](./commands/list.md)
- [cargo-msrv show](./commands/show.md)
- [cargo-msrv](./commands/find.md)
- [cargo-msrv help](./commands/help.md)
- [cargo-msrv list](./commands/list.md)
- [cargo-msrv show](./commands/show.md)
- [cargo-msrv verify](./commands/verify.md)
- [Verification in CI](./ci/index.md)
- [GitLab](./ci/gitlab.md)
22 changes: 22 additions & 0 deletions book/src/ci/gitlab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# GitLab CI/CD

Use this snippet to have a dedicated [job](https://docs.gitlab.com/ee/ci/jobs/)
in the [test stage of your pipeline](https://docs.gitlab.com/ee/ci/pipelines/):

```yml
msrv:
stage: test
image:
name: foresterre/cargo-msrv:latest
entrypoint: [""]
before_script:
- rustc --version
- cargo --version
- cargo msrv --version
script:
- cargo msrv --output-format minimal verify
```

**Note:** The empty `entrypoint` is necessary because the image has
`cargo-msrv` as its entrypoint. Since we want to run other commands, like
`cargo --version`, GitLab requires either an empty entrypoint or a shell.
4 changes: 4 additions & 0 deletions book/src/ci/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Verification in CI

You can run `cargo msrv verify` in continuous integration services to check the
MSRV with every contribution.
2 changes: 1 addition & 1 deletion src/bin/cargo-msrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn init_and_run(ctx: &Context) -> Result<ExitCode, InstanceError> {
"initializing"
);

let setup = ReporterSetup::default();
let setup = ReporterSetup;
let (reporter, listener) = setup.create();

tracing::info!("storyteller channel created");
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ pub fn run_app(ctx: &Context, reporter: &impl Reporter) -> TResult<()> {
Find::new(&index, runner).run(ctx, reporter)?;
}
Context::List(ctx) => {
List::default().run(ctx, reporter)?;
List.run(ctx, reporter)?;
}
Context::Set(ctx) => {
let index = release_index::fetch_index(reporter, ctx.rust_releases.release_source).ok();
Set::new(index.as_ref()).run(ctx, reporter)?;
}
Context::Show(ctx) => {
Show::default().run(ctx, reporter)?;
Show.run(ctx, reporter)?;
}
Context::Verify(ctx) => {
let index = release_index::fetch_index(reporter, ctx.rust_releases.release_source)?;
Expand Down
44 changes: 11 additions & 33 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ edition = "2018"
[dependencies]
"#;

assert!(CargoManifestParser::default()
.parse::<Document>(contents)
.is_ok());
assert!(CargoManifestParser.parse::<Document>(contents).is_ok());
}

#[test]
Expand All @@ -152,9 +150,7 @@ edition = "2018"
[dependencies]
"#;

assert!(CargoManifestParser::default()
.parse::<Document>(contents)
.is_err());
assert!(CargoManifestParser.parse::<Document>(contents).is_err());
}

#[test]
Expand All @@ -167,9 +163,7 @@ edition = "2018"
[dependencies]
"#;

let manifest = CargoManifestParser::default()
.parse::<Document>(contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(contents).unwrap();

let manifest = CargoManifest::try_from(manifest).unwrap();

Expand All @@ -187,9 +181,7 @@ rust-version = "1.56.0"
[dependencies]
"#;

let manifest = CargoManifestParser::default()
.parse::<Document>(contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(contents).unwrap();

let manifest = CargoManifest::try_from(manifest).unwrap();
let version = manifest.minimum_rust_version.unwrap();
Expand All @@ -208,9 +200,7 @@ rust-version = "1.56.0-nightly"
[dependencies]
"#;

let manifest = CargoManifestParser::default()
.parse::<Document>(contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(contents).unwrap();

let parse_err = CargoManifest::try_from(manifest).unwrap_err();

Expand All @@ -229,9 +219,7 @@ rust-version = "1.56"
[dependencies]
"#;

let manifest = CargoManifestParser::default()
.parse::<Document>(contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(contents).unwrap();

let manifest = CargoManifest::try_from(manifest).unwrap();
let version = manifest.minimum_rust_version.unwrap();
Expand Down Expand Up @@ -263,9 +251,7 @@ rust-version = "{}"
version
);

let manifest = CargoManifestParser::default()
.parse::<Document>(&contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(&contents).unwrap();

let manifest = CargoManifest::try_from(manifest);

Expand All @@ -285,9 +271,7 @@ msrv = "1.51.0"
[dependencies]
"#;

let manifest = CargoManifestParser::default()
.parse::<Document>(contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(contents).unwrap();

let manifest = CargoManifest::try_from(manifest).unwrap();
let version = manifest.minimum_rust_version.unwrap();
Expand All @@ -308,9 +292,7 @@ msrv = "1.51"
[dependencies]
"#;

let manifest = CargoManifestParser::default()
.parse::<Document>(contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(contents).unwrap();

let manifest = CargoManifest::try_from(manifest).unwrap();
let version = manifest.minimum_rust_version.unwrap();
Expand All @@ -336,9 +318,7 @@ metadata = { msrv = "1.51" }
[dependencies]
"#;

let manifest = CargoManifestParser::default()
.parse::<Document>(contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(contents).unwrap();

let manifest = CargoManifest::try_from(manifest).unwrap();
let version = manifest.minimum_rust_version.unwrap();
Expand Down Expand Up @@ -372,9 +352,7 @@ msrv = "{}"
version
);

let manifest = CargoManifestParser::default()
.parse::<Document>(&contents)
.unwrap();
let manifest = CargoManifestParser.parse::<Document>(&contents).unwrap();

let manifest = CargoManifest::try_from(manifest);

Expand Down
2 changes: 1 addition & 1 deletion src/manifest/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl DocumentReader for TomlDocumentReader {
source: IoErrorSource::ReadFile(path.to_path_buf()),
})?;

CargoManifestParser::default()
CargoManifestParser
.parse(&contents)
.map_err(ManifestReaderError::Toml)
}
Expand Down
4 changes: 2 additions & 2 deletions src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod tests {

#[test]
fn report_event() {
let setup = ReporterSetup::default();
let setup = ReporterSetup;

let (reporter, _listener) = setup.create();

Expand All @@ -185,7 +185,7 @@ mod tests {
fn scopes() {
use std::iter;

let setup = ReporterSetup::default();
let setup = ReporterSetup;

let (reporter, _listener) = setup.create();
let gen = reporter.scope_generator();
Expand Down
6 changes: 1 addition & 5 deletions src/reporter/event/types/list_result/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ pub fn parse_manifest_workaround<P: AsRef<Path>>(path: P) -> Option<crate::semve
fn parse(path: &Path) -> Option<semver::Version> {
std::fs::read_to_string(path)
.ok()
.and_then(|contents| {
CargoManifestParser::default()
.parse::<Document>(&contents)
.ok()
})
.and_then(|contents| CargoManifestParser.parse::<Document>(&contents).ok())
.and_then(|map| CargoManifest::try_from(map).ok())
.and_then(|manifest| manifest.minimum_rust_version().map(ToOwned::to_owned))
.map(|version: BareVersion| version.to_semver_version())
Expand Down
Loading

0 comments on commit 0569209

Please sign in to comment.