Skip to content

Commit 11e1fdf

Browse files
committed
cargo-rail: improved the change detection && prepped for GHA integration
1 parent 558d67e commit 11e1fdf

29 files changed

+1929
-458
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: 'cargo-rail affected'
2+
description: 'Detect affected crates in a Rust monorepo using cargo-rail'
3+
author: 'cargo-rail'
4+
5+
inputs:
6+
since:
7+
description: 'Git ref to compare against (auto-detects if not specified)'
8+
required: false
9+
from:
10+
description: 'Start ref for SHA pair mode (use with `to`)'
11+
required: false
12+
to:
13+
description: 'End ref for SHA pair mode (use with `from`)'
14+
required: false
15+
format:
16+
description: 'Output format: github (default), github-matrix, json, jsonl, names-only'
17+
required: false
18+
default: 'github'
19+
cargo-rail-version:
20+
description: 'Version of cargo-rail to install (default: latest)'
21+
required: false
22+
default: 'latest'
23+
24+
outputs:
25+
crates:
26+
description: 'Space-separated list of affected crates'
27+
value: ${{ steps.affected.outputs.crates }}
28+
count:
29+
description: 'Number of affected crates'
30+
value: ${{ steps.affected.outputs.affected_count }}
31+
matrix:
32+
description: 'JSON array of affected crates for strategy.matrix'
33+
value: ${{ steps.affected.outputs.test_matrix }}
34+
rebuild_all:
35+
description: 'True if infrastructure files changed (rebuild all recommended)'
36+
value: ${{ steps.affected.outputs.rebuild_all }}
37+
docs_only:
38+
description: 'True if only documentation files changed'
39+
value: ${{ steps.affected.outputs.docs_only }}
40+
41+
runs:
42+
using: 'composite'
43+
steps:
44+
- name: Install cargo-rail
45+
shell: bash
46+
run: |
47+
if [ "${{ inputs.cargo-rail-version }}" = "latest" ]; then
48+
cargo install cargo-rail
49+
else
50+
cargo install cargo-rail --version "${{ inputs.cargo-rail-version }}"
51+
fi
52+
53+
- name: Detect affected crates
54+
id: affected
55+
shell: bash
56+
run: |
57+
# Determine the ref to compare against
58+
if [ -n "${{ inputs.from }}" ] && [ -n "${{ inputs.to }}" ]; then
59+
# SHA pair mode
60+
ARGS="--from ${{ inputs.from }} --to ${{ inputs.to }}"
61+
elif [ -n "${{ inputs.since }}" ]; then
62+
ARGS="--since ${{ inputs.since }}"
63+
else
64+
# Auto-detect: use origin/main, origin/master, or HEAD~1
65+
if git rev-parse --verify origin/main >/dev/null 2>&1; then
66+
ARGS="--since origin/main"
67+
elif git rev-parse --verify origin/master >/dev/null 2>&1; then
68+
ARGS="--since origin/master"
69+
else
70+
ARGS="--since HEAD~1"
71+
fi
72+
fi
73+
74+
# Run cargo-rail affected with github format and output to $GITHUB_OUTPUT
75+
cargo rail affected $ARGS --format "${{ inputs.format }}" --output-file "$GITHUB_OUTPUT"
76+
77+
branding:
78+
icon: 'package'
79+
color: 'orange'

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ semver = "1.0.27"
3030
rayon = "1.11.0"
3131
winnow = "0.7.13"
3232
chrono = "0.4.42"
33+
glob = "0.3.3"
3334

3435
[dev-dependencies]
3536
tempfile = "3.23.0"

src/cargo/unify_analyzer.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,34 +349,19 @@ impl UnifyAnalyzer {
349349
// Use pre-loaded multi-target metadata if available, otherwise load it
350350
let metadata = if let Some(ref cached) = ctx.multi_target_metadata {
351351
// Already loaded in WorkspaceContext - just clone Arc (cheap)
352-
println!("Using pre-loaded multi-target metadata");
353352
(**cached).clone()
354353
} else {
355354
// Not pre-loaded (no targets configured) - load default
356355
let targets = ctx.config.as_ref().map(|c| c.targets.clone()).unwrap_or_default();
357-
358-
println!(
359-
"Loading metadata for {} target(s)...",
360-
if targets.is_empty() { 1 } else { targets.len() }
361-
);
362-
363356
MultiTargetMetadata::load_parallel(ctx.workspace_root(), &targets)?
364357
};
365358

366-
println!("Parsing workspace manifests...");
367-
368359
// Parse all manifests once
369360
let workspace_packages = metadata.workspace_packages();
370361
let manifests = ManifestAnalyzer::parse_workspace(ctx.workspace_root(), &workspace_packages)?;
371362

372363
// Parse existing workspace.dependencies to avoid duplicates
373364
let existing_workspace_deps = parse_existing_workspace_deps(ctx.workspace_root())?;
374-
if !existing_workspace_deps.is_empty() {
375-
println!(
376-
"Found {} existing workspace dependencies",
377-
existing_workspace_deps.len()
378-
);
379-
}
380365

381366
// Build config from context
382367
let config = ctx.config.as_ref().map(|c| c.unify.clone()).unwrap_or_default();

0 commit comments

Comments
 (0)