Skip to content

Commit 43e90b5

Browse files
committed
cargo-rail: fixing the time/date in the publish workflow
1 parent ed0b521 commit 43e90b5

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

src/commands/affected.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,19 +411,46 @@ fn format_names_only(analysis: &AffectedAnalysis) -> String {
411411
}
412412

413413
/// Format GitHub Actions output for $GITHUB_OUTPUT
414+
///
415+
/// Outputs all fields that GitHub Actions workflows commonly need:
416+
/// - Core: crates, affected_count, test_matrix
417+
/// - Classification: docs_only, rebuild_all
418+
/// - Details: direct, transitive, changed_files_count
419+
/// - Infrastructure: infrastructure_files (JSON array)
420+
/// - Custom: custom_categories (JSON object)
414421
fn format_github(analysis: &AffectedAnalysis, classification: &ChangeClassification) -> RailResult<String> {
415-
let (_, _, test_targets) = get_sorted_analysis(analysis);
422+
let (direct, dependents, test_targets) = get_sorted_analysis(analysis);
416423

417424
let test_matrix = serde_json::to_string(&test_targets)
418425
.map_err(|e| RailError::message(format!("JSON serialization failed: {}", e)))?;
419426

427+
let infrastructure_files = serde_json::to_string(&classification.infrastructure_files)
428+
.map_err(|e| RailError::message(format!("JSON serialization failed: {}", e)))?;
429+
430+
let custom_categories = serde_json::to_string(&classification.custom_categories)
431+
.map_err(|e| RailError::message(format!("JSON serialization failed: {}", e)))?;
432+
420433
Ok(format!(
421-
"docs_only={}\nrebuild_all={}\ntest_matrix={}\naffected_count={}\ncrates={}",
434+
"docs_only={}\n\
435+
rebuild_all={}\n\
436+
test_matrix={}\n\
437+
affected_count={}\n\
438+
crates={}\n\
439+
direct={}\n\
440+
transitive={}\n\
441+
changed_files_count={}\n\
442+
infrastructure_files={}\n\
443+
custom_categories={}",
422444
classification.docs_only,
423445
classification.rebuild_all,
424446
test_matrix,
425447
test_targets.len(),
426-
test_targets.join(" ")
448+
test_targets.join(" "),
449+
direct.join(" "),
450+
dependents.join(" "),
451+
analysis.changed_files.len(),
452+
infrastructure_files,
453+
custom_categories,
427454
))
428455
}
429456

src/release/publisher.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::release::changelog::ChangelogGenerator;
66
use crate::release::planner::{CrateReleasePlan, ReleasePlan};
77
use crate::release::version::VersionBumper;
88
use crate::workspace::WorkspaceContext;
9+
use chrono::Local;
910
use std::fs;
1011
use std::process::Command;
1112
use std::thread;
@@ -206,8 +207,8 @@ impl<'a> ReleasePublisher<'a> {
206207
updated.push_str("\n\n");
207208
}
208209

209-
// Add new version with current date (get from git commit date or system)
210-
let date = self.get_current_date()?;
210+
// Add new version with today's date
211+
let date = self.get_current_date();
211212
updated.push_str(&self.format_version_header(plan, previous_tag.as_deref(), &date, github_repo.as_ref()));
212213
updated.push_str(&new_entries);
213214
updated.push('\n');
@@ -366,30 +367,9 @@ impl<'a> ReleasePublisher<'a> {
366367
Ok(())
367368
}
368369

369-
/// Get current date in YYYY-MM-DD format (using system git)
370-
fn get_current_date(&self) -> RailResult<String> {
371-
// Use git to get current date (portable across platforms)
372-
let output = Command::new("git")
373-
.current_dir(self.ctx.workspace_root())
374-
.args(["log", "-1", "--format=%cd", "--date=short"])
375-
.output()
376-
.map_err(|e| RailError::message(format!("Failed to get date: {}", e)))?;
377-
378-
if output.status.success() {
379-
let date = String::from_utf8_lossy(&output.stdout).trim().to_string();
380-
if !date.is_empty() {
381-
return Ok(date);
382-
}
383-
}
384-
385-
// Fallback: use system date command
386-
let output = Command::new("date")
387-
.args(["+%Y-%m-%d"])
388-
.output()
389-
.map_err(|e| RailError::message(format!("Failed to get system date: {}", e)))?;
390-
391-
let date = String::from_utf8_lossy(&output.stdout).trim().to_string();
392-
Ok(date)
370+
/// Get current date in YYYY-MM-DD format
371+
fn get_current_date(&self) -> String {
372+
Local::now().format("%Y-%m-%d").to_string()
393373
}
394374

395375
fn format_version_header(

0 commit comments

Comments
 (0)