-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.rs
More file actions
executable file
·228 lines (198 loc) · 7.41 KB
/
Copy pathpackage.rs
File metadata and controls
executable file
·228 lines (198 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env cargo
//! ```cargo
//! [dependencies]
//! ```
use std::fs;
use std::io::{self, Write};
use std::path::Path;
use std::process::Command;
const CRATES: &[&str] = &["idle-daemon"];
fn run_cmd(cmd: &mut Command) -> Result<(), String> {
let status = cmd.status().map_err(|e| e.to_string())?;
if !status.success() {
return Err(format!("Command failed with exit status: {}", status));
}
Ok(())
}
fn get_version() -> Result<String, String> {
let content = fs::read_to_string("idle-daemon/Cargo.toml").map_err(|e| e.to_string())?;
for line in content.lines() {
if line.starts_with("version =") {
let parts: Vec<&str> = line.split('"').collect();
if parts.len() >= 2 {
return Ok(parts[1].to_string());
}
}
}
Err("Could not find version in idle-daemon/Cargo.toml".to_string())
}
fn skip_tests() -> bool {
matches!(
std::env::var("SKIP_TESTS").as_deref(),
Ok("1") | Ok("true") | Ok("yes") | Ok("TRUE") | Ok("YES")
)
}
fn dry_run() -> bool {
matches!(
std::env::var("IDLE_PACKAGE_DRY_RUN").as_deref(),
Ok("1") | Ok("true") | Ok("yes") | Ok("TRUE") | Ok("YES")
)
}
/// Headless package gate — must pass before shipping packages.
/// See `scripts/qa_package_gate.sh` and `docs/QA_REGRESSION.md`.
fn run_qa_unit_gate() -> Result<(), String> {
let script = Path::new("scripts/qa_package_gate.sh");
if script.is_file() {
println!("QA package gate (headless): scripts/qa_package_gate.sh");
run_cmd(Command::new("bash").arg(script))?;
return Ok(());
}
// Fallback if script missing (partial checkout).
println!("QA gate fallback: core host crates");
run_cmd(Command::new("cargo").args([
"test",
"-p",
"idle-daemon",
"-p",
"idle-ipc",
"-p",
"idle-dbus",
"-p",
"idle-upscaler",
"-p",
"idle-runner",
"-p",
"idle-api",
"-p",
"wayland-present",
"-p",
"wayland-idle",
]))?;
println!("QA unit gate passed.");
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("==========================================");
println!("Building All IdleScreen Packages via Rust...");
println!("==========================================");
// Clean stale packaging directories to avoid copying old versions
if dry_run() {
println!("[dry-run] would clean: target/debian, target/generate-rpm");
} else {
let _ = fs::remove_dir_all("target/debian");
let _ = fs::remove_dir_all("target/generate-rpm");
}
// Ensure path to cargo bin
let home = std::env::var("HOME")?;
let path = std::env::var("PATH")?;
let cargo_bin = format!("{}/.cargo/bin", home);
if !path.contains(&cargo_bin) {
// SAFETY: single-threaded QA-gate setup before any other threads exist.
unsafe {
std::env::set_var("PATH", format!("{}:{}", cargo_bin, path));
}
}
if skip_tests() {
println!("SKIP_TESTS set — skipping QA unit gate (not for release cuts).");
} else {
run_qa_unit_gate()?;
}
println!("Compiling release binaries...");
run_cmd(Command::new("cargo").args(["build", "--release"]))?;
let apt_pool = Path::new("../packages/apt/pool/main");
let rpm_pool = Path::new("../packages/rpm/pool");
for crate_name in CRATES {
println!("Packaging: {}", crate_name);
println!("Building Debian package...");
run_cmd(Command::new("cargo").args(["deb", "--no-build", "-p", crate_name]))?;
// Deb/RPM metadata package names (may differ from crate name).
let pkg_name = crate_name;
// Find built .deb file
let deb_dir = Path::new("target/debian");
let prefix = format!("{}_", pkg_name);
let mut deb_file_path = None;
if let Ok(entries) = fs::read_dir(deb_dir) {
for entry in entries {
let entry = entry?;
let path = entry.path();
if path.is_file() {
if let Some(filename) = path.file_name().and_then(|s| s.to_str()) {
if filename.starts_with(&prefix) && filename.ends_with(".deb") {
deb_file_path = Some(path);
break;
}
}
}
}
}
if let Some(src_path) = deb_file_path {
if let Some(fname) = src_path.file_name() {
println!("Built: {:?}", fname);
let dest_path = apt_pool.join(fname);
fs::copy(&src_path, &dest_path)?;
println!("Copied to apt repository packages/apt/pool/main/");
}
} else {
return Err(format!(
"Debian package not found for {crate_name} (searched for: {pkg_name}). Refusing partial release."
)
.into());
}
println!("Building RPM package...");
run_cmd(Command::new("cargo").args(["generate-rpm", "-p", crate_name]))?;
// Find built .rpm file
let rpm_dir = Path::new("target/generate-rpm");
let rpm_prefix = format!("{}-", pkg_name);
let mut rpm_file_path = None;
if let Ok(entries) = fs::read_dir(rpm_dir) {
for entry in entries {
let entry = entry?;
let path = entry.path();
if path.is_file() {
if let Some(filename) = path.file_name().and_then(|s| s.to_str()) {
if filename.starts_with(&rpm_prefix) && filename.ends_with(".rpm") {
rpm_file_path = Some(path);
break;
}
}
}
}
}
if let Some(src_path) = rpm_file_path {
if let Some(fname) = src_path.file_name() {
println!("Built RPM: {:?}", fname);
let dest_path = rpm_pool.join(fname);
fs::copy(&src_path, &dest_path)?;
println!("Copied to rpm repository packages/rpm/pool/");
}
} else {
return Err(format!(
"RPM package not found for {crate_name} (searched for: {pkg_name}). Refusing partial release."
)
.into());
}
}
println!("==========================================");
println!("Updating packages index...");
println!("==========================================");
// Execute the unified update script at the packages root
run_cmd(Command::new("./update.sh").current_dir("../packages"))?;
println!("==========================================");
println!("IdleScreen build and package sync complete!");
println!("==========================================");
print!("\nDo you want to commit and push these package updates to GitHub? (y/n): ");
io::stdout().flush()?;
let mut response = String::new();
io::stdin().read_line(&mut response)?;
let response = response.trim().to_lowercase();
if response == "y" || response == "yes" {
let version = get_version()?;
// Tag/commit/push live in scripts/package_push_packages.sh (line budget).
run_cmd(
Command::new("bash")
.arg("../scripts/package_push_packages.sh")
.arg(&version),
)?;
}
Ok(())
}