Skip to content

Commit 7d20791

Browse files
committed
Merge rust-bitcoin#40: Introduce CI to rbmt
64a68b0 cargo-rbmt: add dogfood ci workflow (Nick Johnson) df2e43c cargo-rbmt: walk back cargo method (Nick Johnson) 39ddd4d cargo-rbmt: add "existing" variant for simple setups (Nick Johnson) Pull request description: Slinging things too fast broke so introducing a dogfood CI task to try and raise the bar. Adds an `existing` variant to the lock file management for simpler workspaces like this which don't use a minimal and recent, instead shipping a Cargo.lock. I would like to iron out the dependency requirements here to test the min/recent, but saving that for later since its non-trivial. ACKs for top commit: tcharding: ACK 64a68b0 Tree-SHA512: ec838f83ab23159591380e1daa28dddd0a56ca82be432fb04658b1011da386602352811cee0404b492a92e8cb5e248ea9e2e6c89d314ec5b9f251f102e038da6
2 parents e5245bb + 64a68b0 commit 7d20791

File tree

9 files changed

+92
-36
lines changed

9 files changed

+92
-36
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
8+
jobs:
9+
dogfood:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v6
13+
14+
- name: Install Rust toolchains
15+
uses: actions-rust-lang/setup-rust-toolchain@v1
16+
with:
17+
toolchain: nightly,1.74.0,stable
18+
components: clippy,rustfmt
19+
20+
- name: Install cargo-rbmt from current commit
21+
run: cargo install --locked --path cargo-rbmt
22+
23+
- name: Run lint on workspace
24+
run: cargo +nightly rbmt --lock-file existing lint
25+
26+
- name: Build documentation (stable)
27+
run: cargo rbmt --lock-file existing docs
28+
29+
- name: Build documentation (docs.rs / nightly)
30+
run: cargo +nightly rbmt --lock-file existing docsrs
31+
32+
- name: Run tests with stable
33+
run: cargo rbmt --lock-file existing test stable
34+
35+
- name: Run tests with nightly
36+
run: cargo +nightly rbmt --lock-file existing test nightly
37+
38+
- name: Run tests with MSRV
39+
run: cargo +1.74.0 rbmt --lock-file existing test msrv

cargo-rbmt/src/bench.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Benchmark testing tasks.
22
3-
use crate::environment::{cargo, get_crate_dirs, quiet_println};
3+
use crate::environment::{get_crate_dirs, quiet_println};
4+
use crate::quiet_cmd;
45
use crate::toolchain::{check_toolchain, Toolchain};
56
use xshell::Shell;
67

@@ -21,7 +22,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er
2122
// Use pushd pattern to change and restore directory.
2223
let _dir = sh.push_dir(crate_dir);
2324

24-
cargo(sh, "bench")
25+
quiet_cmd!(sh, "cargo --locked bench")
2526
.env("RUSTFLAGS", "--cfg=bench")
2627
.run()?;
2728
}

cargo-rbmt/src/docs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Documentation building tasks.
22
3-
use crate::environment::cargo;
3+
use crate::quiet_cmd;
44
use crate::toolchain::{check_toolchain, Toolchain};
55
use xshell::Shell;
66

@@ -11,7 +11,7 @@ use xshell::Shell;
1111
pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Error>> {
1212
check_toolchain(sh, Toolchain::Stable)?;
1313

14-
let mut cmd = cargo(sh, "doc --all-features --no-deps");
14+
let mut cmd = quiet_cmd!(sh, "cargo --locked doc --all-features --no-deps");
1515

1616
// Add package filters if specified.
1717
for package in packages {
@@ -30,7 +30,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er
3030
pub fn run_docsrs(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Error>> {
3131
check_toolchain(sh, Toolchain::Nightly)?;
3232

33-
let mut cmd = cargo(sh, "doc --all-features --no-deps");
33+
let mut cmd = quiet_cmd!(sh, "cargo --locked doc --all-features --no-deps");
3434

3535
// Add package filters if specified.
3636
for package in packages {

cargo-rbmt/src/environment.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,3 @@ pub fn get_target_directory(sh: &Shell) -> Result<String, Box<dyn std::error::Er
109109

110110
Ok(target_dir.to_string())
111111
}
112-
113-
/// Helper function to run cargo commands with CI flags.
114-
///
115-
/// The locked flag ensures using existing Cargo.lock file without
116-
/// updating dependencies.
117-
pub fn cargo<'a>(sh: &'a Shell, args: &str) -> xshell::Cmd<'a> {
118-
quiet_cmd!(sh, "cargo --locked {args}")
119-
}

cargo-rbmt/src/integration.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Integration test tasks for packages with bitcoind-tests or similar test packages.
22
3-
use crate::environment::{cargo, get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
3+
use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
4+
use crate::quiet_cmd;
45
use serde::Deserialize;
56
use std::path::{Path, PathBuf};
67
use xshell::{cmd, Shell};
@@ -109,7 +110,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er
109110
// Run tests for each version.
110111
for version in &versions_to_test {
111112
quiet_println(&format!(" Testing with version: {}", version));
112-
cargo(sh, "test --features={version}").run()?;
113+
quiet_cmd!(sh, "cargo --locked test --features={version}").run()?;
113114
}
114115
}
115116

cargo-rbmt/src/lint.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::fs;
22
use std::path::Path;
33
use xshell::Shell;
44

5-
use crate::environment::{cargo, get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
5+
use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
6+
use crate::quiet_cmd;
67
use crate::toolchain::{check_toolchain, Toolchain};
78

89
/// Lint configuration loaded from rbmt.toml.
@@ -57,12 +58,12 @@ fn lint_workspace(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
5758
quiet_println("Linting workspace...");
5859

5960
// Run clippy on workspace with all features.
60-
cargo(sh, "clippy --workspace --all-targets --all-features --keep-going")
61+
quiet_cmd!(sh, "cargo --locked clippy --workspace --all-targets --all-features --keep-going")
6162
.args(&["--", "-D", "warnings"])
6263
.run()?;
6364

6465
// Run clippy on workspace without features.
65-
cargo(sh, "clippy --workspace --all-targets --keep-going")
66+
quiet_cmd!(sh, "cargo --locked clippy --workspace --all-targets --keep-going")
6667
.args(&["--", "-D", "warnings"])
6768
.run()?;
6869

@@ -89,7 +90,7 @@ fn lint_crates(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error
8990
let _old_dir = sh.push_dir(&crate_dir);
9091

9192
// Run clippy without default features.
92-
cargo(sh, "clippy --all-targets --no-default-features --keep-going")
93+
quiet_cmd!(sh, "cargo --locked clippy --all-targets --no-default-features --keep-going")
9394
.args(&["--", "-D", "warnings"])
9495
.run()?;
9596
}
@@ -105,7 +106,7 @@ fn check_duplicate_deps(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
105106
let allowed_duplicates = &config.allowed_duplicates;
106107

107108
// Run cargo tree to find duplicates.
108-
let output = cargo(sh, "tree --target=all --all-features --duplicates")
109+
let output = quiet_cmd!(sh, "cargo --locked tree --target=all --all-features --duplicates")
109110
.ignore_status()
110111
.read()?;
111112

@@ -123,7 +124,7 @@ fn check_duplicate_deps(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
123124

124125
if !duplicates.is_empty() {
125126
// Show full tree for context.
126-
cargo(sh, "tree --target=all --all-features --duplicates").run()?;
127+
quiet_cmd!(sh, "cargo --locked tree --target=all --all-features --duplicates").run()?;
127128
eprintln!("Error: Found duplicate dependencies in workspace!");
128129
for dup in &duplicates {
129130
eprintln!(" {}", dup);

cargo-rbmt/src/lock.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Manage cargo lock files for minimal and recent dependency versions.
22
//!
3-
//! Note: This module uses `quiet_cmd!` directly instead of the `cargo()` helper
4-
//! because these commands intentionally generate and modify lockfiles. Using
5-
//! `--locked` would prevent the dependency resolution we need here.
3+
//! Note: These commands intentionally omit `--locked` because they need to
4+
//! generate and modify lockfiles. Using `--locked` would prevent the dependency
5+
//! resolution we need here.
66
77
use crate::environment::quiet_println;
88
use crate::quiet_cmd;
@@ -22,6 +22,8 @@ pub enum LockFile {
2222
/// Uses recent/updated versions of dependencies.
2323
#[default]
2424
Recent,
25+
/// Uses the existing Cargo.lock as-is (for binary crates).
26+
Existing,
2527
}
2628

2729
impl LockFile {
@@ -30,6 +32,7 @@ impl LockFile {
3032
match self {
3133
LockFile::Minimal => "Cargo-minimal.lock",
3234
LockFile::Recent => "Cargo-recent.lock",
35+
LockFile::Existing => CARGO_LOCK,
3336
}
3437
}
3538
}
@@ -105,6 +108,11 @@ fn copy_lock_file(sh: &Shell, target: LockFile) -> Result<(), Box<dyn std::error
105108

106109
/// Restore a specific lock file to Cargo.lock.
107110
pub fn restore_lock_file(sh: &Shell, source: LockFile) -> Result<(), Box<dyn std::error::Error>> {
111+
// Existing uses Cargo.lock as-is, no need to restore.
112+
if matches!(source, LockFile::Existing) {
113+
return Ok(());
114+
}
115+
108116
let src_path = sh.current_dir().join(source.filename());
109117
let dest_path = sh.current_dir().join(CARGO_LOCK);
110118
fs::copy(&src_path, &dest_path)?;

cargo-rbmt/src/test.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Test tasks with feature matrix testing.
22
3-
use crate::environment::{cargo, get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
3+
use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
4+
use crate::quiet_cmd;
45
use crate::toolchain::{check_toolchain, Toolchain};
56
use serde::Deserialize;
67
use std::ffi::OsStr;
@@ -173,7 +174,7 @@ fn do_test(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std::error::Er
173174
quiet_println("Running basic tests");
174175

175176
// Basic test (includes build).
176-
cargo(sh, "test").run()?;
177+
quiet_cmd!(sh, "cargo --locked test").run()?;
177178

178179
// Run examples.
179180
for example in &config.examples {
@@ -183,18 +184,18 @@ fn do_test(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std::error::Er
183184
1 => {
184185
// Format: "name" - run with default features.
185186
let name = parts[0];
186-
cargo(sh, "run --example {name}").run()?;
187+
quiet_cmd!(sh, "cargo --locked run --example {name}").run()?;
187188
}
188189
2 => {
189190
let name = parts[0];
190191
let features = parts[1];
191192

192193
if features == "-" {
193194
// Format: "name:-" - run with no-default-features.
194-
cargo(sh, "run --no-default-features --example {name}").run()?;
195+
quiet_cmd!(sh, "cargo --locked run --no-default-features --example {name}").run()?;
195196
} else {
196197
// Format: "name:features" - run with specific features.
197-
cargo(sh, "run --example {name} --features={features}").run()?;
198+
quiet_cmd!(sh, "cargo --locked run --example {name} --features={features}").run()?;
198199
}
199200
}
200201
_ => {
@@ -219,7 +220,7 @@ fn do_feature_matrix(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std:
219220
for features in &config.exact_features {
220221
let features_str = features.join(" ");
221222
quiet_println(&format!("Testing exact features: {}", features_str));
222-
cargo(sh, "test --no-default-features --features={features_str}").run()?;
223+
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={features_str}").run()?;
223224
}
224225
return Ok(());
225226
}
@@ -228,17 +229,17 @@ fn do_feature_matrix(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std:
228229
if !config.features_with_no_std.is_empty() {
229230
let no_std = FeatureFlag::NoStd;
230231
quiet_println("Testing no-std");
231-
cargo(sh, "test --no-default-features --features={no_std}").run()?;
232+
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={no_std}").run()?;
232233

233234
loop_features(sh, Some(FeatureFlag::NoStd), &config.features_with_no_std)?;
234235
} else {
235236
quiet_println("Testing no-default-features");
236-
cargo(sh, "test --no-default-features").run()?;
237+
quiet_cmd!(sh, "cargo --locked test --no-default-features").run()?;
237238
}
238239

239240
// Test all features.
240241
quiet_println("Testing all-features");
241-
cargo(sh, "test --all-features").run()?;
242+
quiet_cmd!(sh, "cargo --locked test --all-features").run()?;
242243

243244
// Test features with std.
244245
if !config.features_with_std.is_empty() {
@@ -290,21 +291,21 @@ fn loop_features<S: AsRef<str>>(
290291
// Test all features together.
291292
let all_features = combine_features(base, features);
292293
quiet_println(&format!("Testing features: {}", all_features));
293-
cargo(sh, "test --no-default-features --features={all_features}").run()?;
294+
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={all_features}").run()?;
294295

295296
// Test each feature individually and all pairs (only if more than one feature).
296297
if features.len() > 1 {
297298
for i in 0..features.len() {
298299
let feature_combo = combine_features(base, &features[i..=i]);
299300
quiet_println(&format!("Testing features: {}", feature_combo));
300-
cargo(sh, "test --no-default-features --features={feature_combo}").run()?;
301+
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={feature_combo}").run()?;
301302

302303
// Test all pairs with features[i].
303304
for j in (i + 1)..features.len() {
304305
let pair = [&features[i], &features[j]];
305306
let feature_combo = combine_features(base, &pair);
306307
quiet_println(&format!("Testing features: {}", feature_combo));
307-
cargo(sh, "test --no-default-features --features={feature_combo}").run()?;
308+
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={feature_combo}").run()?;
308309
}
309310
}
310311
}

rbmt.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[lint]
2+
allowed_duplicates = [
3+
"windows-sys",
4+
"windows-targets",
5+
"windows_aarch64_gnullvm",
6+
"windows_aarch64_msvc",
7+
"windows_i686_gnu",
8+
"windows_i686_gnullvm",
9+
"windows_i686_msvc",
10+
"windows_x86_64_gnu",
11+
"windows_x86_64_gnullvm",
12+
"windows_x86_64_msvc",
13+
]

0 commit comments

Comments
 (0)