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

Add e2e test via Github workflow #1041

Merged
merged 26 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7ff1d5a
Add e2e test via Github workflow
foresterre Oct 25, 2024
d89f746
Rename RunCommand::default to RunCommand::from_cargo_command
foresterre Nov 3, 2024
6579346
Use macos-latest for e2e MSRV test
foresterre Nov 5, 2024
224f1d9
Add debug steps to msrv + e2e workflow
foresterre Nov 5, 2024
16363cf
Add debug log to rustup command for the current dir
foresterre Nov 6, 2024
923a783
Canonicalize the RustupCommand path
foresterre Nov 6, 2024
1cd1e25
Add trace for success status of a rustup command execution
foresterre Nov 6, 2024
a2dec8b
Try to overwrite the CARGO_HOME on windows in the workflow
foresterre Nov 6, 2024
0e4e9d9
Install toolchains without rustup self update
foresterre Nov 6, 2024
f25ba6c
Remove workaround for mixed path separators in Github actions on windows
foresterre Nov 6, 2024
5c4b309
Only run cargo msrv verify with debug logs enabled on failure
foresterre Nov 6, 2024
aae45f7
Try running cargo-msrv on Github actions with bash
foresterre Nov 6, 2024
3cf93a2
Add debug entries to github workflow
foresterre Nov 9, 2024
97fea61
Run rustup twice on windows
foresterre Nov 9, 2024
17b8a81
Change privacy of RustupCommand::execute to private
foresterre Nov 9, 2024
925755c
Add before and after methods to check
foresterre Nov 9, 2024
d3a7f40
Rename the even more generic 'check' to 'compatibility'
foresterre Nov 9, 2024
59c2b82
Rename 'check' module to 'compatibility'
foresterre Nov 9, 2024
6996561
Add doc comment to IsCompatible
foresterre Nov 9, 2024
c0e3c68
Move --no-self-update to front of rustup install
foresterre Nov 9, 2024
27e8b38
Add --no-self-update to debug step in Github workflow
foresterre Nov 10, 2024
402dedc
Acknowledge RUSTSEC-2024-0384: instant is unmaintained
foresterre Nov 10, 2024
0b6f6d3
Update changelog for `rustup install --no-self-update`
foresterre Nov 10, 2024
b71680d
Add known issues section to changelog
foresterre Nov 10, 2024
51fe57a
Add cargo msrv find --set to changelog
foresterre Nov 10, 2024
24b9368
Clean up MSRV workflow
foresterre Nov 10, 2024
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
31 changes: 24 additions & 7 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,44 @@ on:
schedule:
- cron: '00 06 * * *'
jobs:
# MSRV check and e2e test
msrv:
name: msrv
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [ ubuntu, macos ] # [, windows] ... Disabled Windows for now, see #1036
include:
- build: ubuntu
os: ubuntu-latest

- build: macos
os: macos-latest

# - build: windows
# os: windows-latest
continue-on-error: true
steps:
- name: checkout_repo
uses: actions/checkout@v4
- name: install_rust
uses: dtolnay/rust-toolchain@stable
- name: install_cargo_msrv
run: cargo install cargo-msrv --all-features
if: matrix.build == 'ubuntu'
run: cargo install cargo-msrv
- name: install_cargo_msrv_no_default
if: matrix.build != 'ubuntu'
run: cargo install cargo-msrv --no-default-features
- name: version_of_cargo_msrv
run: cargo msrv --version
- name: run_cargo_msrv
run: cargo msrv --output-format json verify
run: cargo msrv verify --output-format json
- name: run_cargo_msrv_on_verify_failure
if: ${{ failure() }}
run: cargo msrv find --output-format json

# The same as the 'msrv' job, except it takes the latest release, including beta releases
# We don't use --all-features here!
msrv_pre_release:
name: msrv_pre_release
runs-on: ubuntu-latest
Expand All @@ -43,11 +60,11 @@ jobs:
with:
tool: cargo-binstall
- name: install_cargo_msrv_bin
run: cargo binstall --version 0.16.0 --no-confirm cargo-msrv
run: cargo binstall --version 0.16.2 --no-confirm cargo-msrv
- name: version_of_cargo_msrv
run: cargo msrv --version
- name: run_cargo_msrv
run: cargo msrv --output-format json verify
run: cargo msrv verify --output-format json
- name: run_cargo_msrv_on_verify_failure
if: ${{ failure() }}
run: cargo msrv find --output-format json
Expand All @@ -68,7 +85,7 @@ jobs:
- name: version_of_cargo_msrv
run: cargo msrv --version
- name: run_cargo_msrv
run: cargo msrv --output-format json verify
run: cargo msrv verify --output-format json
- name: run_cargo_msrv_on_verify_failure
if: ${{ failure() }}
run: cargo msrv find --output-format json
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ the [discussions section](https://github.com/foresterre/cargo-msrv/discussions).

* Added `--workspace`, `--all`, `--package` and `--exclude` CLI options for package selection when in a Cargo project (
with limited workspace support for now)
* `cargo msrv find --write-msrv` is now aliased by `cargo msrv find --set`, which is consistent in terminology with
`cargo msrv set`

### Changed

* Toolchains installed with `rustup install` now use the `--no-self-update` flag

### Known issues

* Installing toolchains on GitHub Actions can fail for the windows runner (#1036)

## [0.16.2] - 2024-10-10

Expand Down
3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[advisories]
ignore = [
"RUSTSEC-2024-0370" # proc-macro-error is unmaintained (via tabled > tabled_derive)
"RUSTSEC-2024-0370", # https://rustsec.org/advisories/RUSTSEC-2024-0370 `proc-macro-error` is unmaintained (via `tabled` > `tabled_derive`)
"RUSTSEC-2024-0384", # https://rustsec.org/advisories/RUSTSEC-2024-0384 `instant` is unmaintained (via `indicatif`)
]

[licenses]
Expand Down
15 changes: 0 additions & 15 deletions src/check/mod.rs

This file was deleted.

26 changes: 26 additions & 0 deletions src/compatibility/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::rust::Toolchain;

mod rustup_toolchain_check;
#[cfg(test)]
mod testing;

use crate::{Compatibility, TResult};
pub use rustup_toolchain_check::{RunCommand, RustupToolchainCheck};

#[cfg(test)]
pub use testing::TestRunner;

/// Implementers of this trait must determine whether a Rust toolchain is _supported_
/// for a Rust project. This is a step in the process of determining the _minimally
/// supported_ Rust version; the MSRV.
pub trait IsCompatible {
fn before(&self, _toolchain: &Toolchain) -> TResult<()> {
Ok(())
}

fn is_compatible(&self, toolchain: &Toolchain) -> TResult<Compatibility>;

fn after(&self, _toolchain: &Toolchain) -> TResult<()> {
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::check::Check;
use crate::compatibility::IsCompatible;
use crate::context::EnvironmentContext;
use crate::error::{IoError, IoErrorSource};
use crate::external_command::cargo_command::CargoCommand;
Expand All @@ -7,7 +7,7 @@ use crate::lockfile::LockfileHandler;
use crate::reporter::event::{CheckMethod, CheckResult, CheckToolchain, Method};
use crate::rust::setup_toolchain::{SetupRustupToolchain, SetupToolchain};
use crate::rust::Toolchain;
use crate::{lockfile, CargoMSRVError, Outcome, Reporter, TResult};
use crate::{lockfile, CargoMSRVError, Compatibility, Reporter, TResult};
use camino::{Utf8Path, Utf8PathBuf};
use std::fmt;
use std::fmt::Formatter;
Expand Down Expand Up @@ -37,8 +37,8 @@ impl<'reporter, 'env, R: Reporter> RustupToolchainCheck<'reporter, 'env, R> {
}
}

impl<'reporter, 'env, R: Reporter> Check for RustupToolchainCheck<'reporter, 'env, R> {
fn check(&self, toolchain: &Toolchain) -> TResult<Outcome> {
impl<'reporter, 'env, R: Reporter> IsCompatible for RustupToolchainCheck<'reporter, 'env, R> {
fn is_compatible(&self, toolchain: &Toolchain) -> TResult<Compatibility> {
let settings = &self.settings;

self.reporter
Expand Down Expand Up @@ -98,7 +98,7 @@ fn run_check_command_via_rustup(
toolchain: &Toolchain,
dir: &Utf8Path,
check: &[String],
) -> TResult<Outcome> {
) -> TResult<Compatibility> {
let version = format!("{}", toolchain.version());
let mut cmd = vec![version.as_str()];
cmd.extend(check.iter().map(|s| s.as_str()));
Expand All @@ -121,7 +121,7 @@ fn run_check_command_via_rustup(
let status = rustup_output.exit_status();

if status.success() {
Ok(Outcome::new_success(toolchain.to_owned()))
Ok(Compatibility::new_success(toolchain.to_owned()))
} else {
let stderr = rustup_output.stderr();
let command = cmd.join(" ");
Expand All @@ -133,7 +133,7 @@ fn run_check_command_via_rustup(
"try_building run failed"
);

Ok(Outcome::new_failure(
Ok(Compatibility::new_failure(
toolchain.to_owned(),
stderr.to_string(),
))
Expand All @@ -142,22 +142,22 @@ fn run_check_command_via_rustup(

fn report_outcome(
reporter: &impl Reporter,
outcome: &Outcome,
outcome: &Compatibility,
no_error_report: bool,
) -> TResult<()> {
match outcome {
Outcome::Success(outcome) => {
Compatibility::Compatible(outcome) => {
// report compatibility with this toolchain
reporter.report_event(CheckResult::compatible(outcome.toolchain_spec.to_owned()))?
}
Outcome::Failure(outcome) if no_error_report => {
Compatibility::Incompatible(outcome) if no_error_report => {
// report incompatibility with this toolchain
reporter.report_event(CheckResult::incompatible(
outcome.toolchain_spec.to_owned(),
None,
))?
}
Outcome::Failure(outcome) => {
Compatibility::Incompatible(outcome) => {
// report incompatibility with this toolchain
reporter.report_event(CheckResult::incompatible(
outcome.toolchain_spec.to_owned(),
Expand Down Expand Up @@ -225,7 +225,7 @@ pub struct RunCommand {
}

impl RunCommand {
pub fn default(cargo_command: CargoCommand) -> Self {
pub fn from_cargo_command(cargo_command: CargoCommand) -> Self {
Self {
command: cargo_command.into_args(),
}
Expand Down
12 changes: 6 additions & 6 deletions src/check/testing.rs → src/compatibility/testing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::check::Check;
use crate::outcome::Outcome;
use crate::compatibility::IsCompatible;
use crate::outcome::Compatibility;
use crate::rust::Toolchain;
use crate::semver::Version;
use crate::TResult;
Expand All @@ -19,18 +19,18 @@ impl TestRunner {
}
}

impl Check for TestRunner {
fn check(&self, toolchain: &Toolchain) -> TResult<Outcome> {
impl IsCompatible for TestRunner {
fn is_compatible(&self, toolchain: &Toolchain) -> TResult<Compatibility> {
let v = toolchain.version();

if self.accept_versions.contains(toolchain.version()) {
Ok(Outcome::new_success(Toolchain::new(
Ok(Compatibility::new_success(Toolchain::new(
v.clone(),
self.target,
&[],
)))
} else {
Ok(Outcome::new_failure(
Ok(Compatibility::new_failure(
Toolchain::new(v.clone(), self.target, &[]),
"f".to_string(),
))
Expand Down
4 changes: 2 additions & 2 deletions src/context/find.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::check::RunCommand;
use crate::cli::{CargoMsrvOpts, SubCommand};
use crate::compatibility::RunCommand;
use crate::context::{
CheckCommandContext, EnvironmentContext, RustReleasesContext, SearchMethod, ToolchainContext,
};
Expand Down Expand Up @@ -83,7 +83,7 @@ impl FindContext {
.all_features(self.check_cmd.cargo_all_features)
.no_default_features(self.check_cmd.cargo_no_default_features);

RunCommand::default(cargo_command)
RunCommand::from_cargo_command(cargo_command)
}
}
}
4 changes: 2 additions & 2 deletions src/context/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::context::{
CheckCommandContext, EnvironmentContext, RustReleasesContext, ToolchainContext,
};

use crate::check::RunCommand;
use crate::compatibility::RunCommand;
use crate::error::CargoMSRVError;
use crate::external_command::cargo_command::CargoCommand;
use crate::sub_command::verify::RustVersion;
Expand Down Expand Up @@ -78,7 +78,7 @@ impl VerifyContext {
.all_features(self.check_cmd.cargo_all_features)
.no_default_features(self.check_cmd.cargo_no_default_features);

RunCommand::default(cargo_command)
RunCommand::from_cargo_command(cargo_command)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/external_command/cargo_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl CargoCommand {

/// Intended to be used in conjunction with [`RunCommand`] and/or [`RustupCommand`].
///
/// [`RunCommand`]: crate::check::RunCommand
/// [`RunCommand`]: crate::compatibility::RunCommand
/// [`RustupCommand`]: crate::external_command::rustup_command::RustupCommand
// Currently we don't invoke it from here directly, but we might eventually, if
// we want to also provide some nicer structs around parsing. However compared to
Expand Down
42 changes: 35 additions & 7 deletions src/external_command/rustup_command.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::error::{IoError, IoErrorSource, TResult};
use camino::Utf8Path;
use std::ffi::{OsStr, OsString};
use std::path::Path;
use std::process::{Command, Stdio};

use crate::error::{IoError, IoErrorSource, TResult};

pub struct RustupCommand {
command: Command,
args: Vec<OsString>,
stdout: Stdio,
stderr: Stdio,
// Span used to trace the path to execution of a RustupCommand
_span: tracing::Span,
}

impl RustupCommand {
Expand All @@ -18,11 +19,27 @@ impl RustupCommand {
args: Vec::new(),
stdout: Stdio::null(),
stderr: Stdio::null(),
_span: tracing::debug_span!("RustupCommand"),
}
}

pub fn with_dir(mut self, path: impl AsRef<Path>) -> Self {
let _ = self.command.current_dir(path);
pub fn with_dir(mut self, path: impl AsRef<Utf8Path>) -> Self {
// The block ensures the scope of the _span.enter() will exit before
// returning self at the end of the method scope.
{
let _span = self._span.enter();

let path = path.as_ref();

if let Ok(canonical_path) = path.canonicalize() {
debug!(name: "rustup_command_path", canonicalized = true, path = %canonical_path.display());
self.command.current_dir(canonical_path);
} else {
debug!(name: "rustup_command_path", canonicalized = false, %path);
self.command.current_dir(path);
}
}

self
}

Expand Down Expand Up @@ -70,10 +87,14 @@ impl RustupCommand {
/// * [RustupCommand::run](RustupCommand::run)
/// * [RustupCommand::install](RustupCommand::install)
/// * [RustupCommand::show](RustupCommand::show)
pub fn execute(mut self, cmd: &OsStr) -> TResult<RustupOutput> {
fn execute(mut self, cmd: &OsStr) -> TResult<RustupOutput> {
let _span = self._span.enter();

debug!(
name: "rustup_command_execute_start",
cmd = ?cmd,
args = ?self.args.as_slice()
args = ?self.args.as_slice(),
current_dir = ?self.command.get_current_dir(),
);

self.command.arg(cmd);
Expand All @@ -86,11 +107,18 @@ impl RustupCommand {
error,
source: IoErrorSource::SpawnProcess(cmd.to_owned()),
})?;

let output = child.wait_with_output().map_err(|error| IoError {
error,
source: IoErrorSource::WaitForProcessAndCollectOutput(cmd.to_owned()),
})?;

debug!(
name: "rustup_command_execute_finish",
cmd = ?cmd,
success = output.status.success(),
);

Ok(RustupOutput {
output,
stdout: once_cell::sync::OnceCell::new(),
Expand Down
Loading
Loading