BlueGit

timfa posprint

Files

posprint / tests / release_scripts.rs

release_scripts.rs

release_scripts.rs 9.7 KiB Download Raw
1//! Regression tests for tag-release packaging scripts and CI asset names.
2//!
3//! Shell-script integration tests run on Unix only. Windows SaaS runners do not
4//! have bash; the Linux release path is unchanged and still covered by `test:linux`.
5
6#[cfg(unix)]
7mod unix_scripts {
8 use std::fs;
9 use std::path::Path;
10 use std::process::Command;
11
12 fn repo_root() -> std::path::PathBuf {
13 Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf()
14 }
15
16 fn write_fake_usr_tree(dir: &Path, marker: &str) {
17 let bin = dir.join("usr/bin");
18 fs::create_dir_all(&bin).unwrap();
19 fs::write(bin.join("posprint"), marker).unwrap();
20 }
21
22 fn tar_usr(src_root: &Path, dest_pkg: &Path) {
23 let status = Command::new("tar")
24 .args(["-C", src_root.to_str().unwrap(), "-cf"])
25 .arg(dest_pkg)
26 .arg("usr")
27 .status()
28 .expect("spawn tar");
29 assert!(status.success(), "tar failed creating {}", dest_pkg.display());
30 }
31
32 fn run_tarball_script(args: &[&str]) -> std::process::Output {
33 let script = repo_root().join("scripts/make-linux-bin-tarball.sh");
34 Command::new("bash")
35 .arg(&script)
36 .args(args)
37 .output()
38 .unwrap_or_else(|e| panic!("run make-linux-bin-tarball.sh: {e}"))
39 }
40
41 fn run_publish_release(args: &[&str]) -> std::process::Output {
42 let script = repo_root().join("scripts/publish-gitlab-release.sh");
43 Command::new("bash")
44 .arg(&script)
45 .args(args)
46 .output()
47 .unwrap_or_else(|e| panic!("run publish-gitlab-release.sh: {e}"))
48 }
49
50 #[test]
51 fn tarball_script_ignores_debug_package_when_glob_expands_to_two() {
52 let tmp = tempfile::tempdir().unwrap();
53 let main_root = tmp.path().join("main");
54 let debug_root = tmp.path().join("debug");
55 write_fake_usr_tree(&main_root, "main-bin");
56 write_fake_usr_tree(&debug_root, "debug-bin");
57
58 let main_pkg = tmp.path().join("posprint-0.5.7-1-x86_64.pkg.tar");
59 let debug_pkg = tmp.path().join("posprint-debug-0.5.7-1-x86_64.pkg.tar");
60 tar_usr(&main_root, &main_pkg);
61 tar_usr(&debug_root, &debug_pkg);
62 let debug_before = fs::read(&debug_pkg).unwrap();
63
64 let out = tmp.path().join("posprint-0.5.7-x86_64.tar.gz");
65 let output = run_tarball_script(&[
66 main_pkg.to_str().unwrap(),
67 debug_pkg.to_str().unwrap(),
68 out.to_str().unwrap(),
69 "0.5.7",
70 ]);
71 assert!(
72 output.status.success(),
73 "stdout:\n{}\nstderr:\n{}",
74 String::from_utf8_lossy(&output.stdout),
75 String::from_utf8_lossy(&output.stderr)
76 );
77 assert!(out.is_file(), "tarball was not written to the intended out path");
78 assert_ne!(out.metadata().unwrap().len(), 0);
79 assert_eq!(
80 fs::read(&debug_pkg).unwrap(),
81 debug_before,
82 "debug package must not be overwritten when it is $2"
83 );
84
85 let extract = tmp.path().join("extract");
86 fs::create_dir_all(&extract).unwrap();
87 let status = Command::new("tar")
88 .args(["-C", extract.to_str().unwrap(), "-xzf"])
89 .arg(&out)
90 .status()
91 .unwrap();
92 assert!(status.success());
93 let packed = fs::read_to_string(extract.join("usr/bin/posprint")).unwrap();
94 assert_eq!(packed, "main-bin");
95 }
96
97 #[test]
98 fn tarball_script_rejects_only_debug_packages() {
99 let tmp = tempfile::tempdir().unwrap();
100 let debug_root = tmp.path().join("debug");
101 write_fake_usr_tree(&debug_root, "debug-bin");
102 let debug_pkg = tmp.path().join("posprint-debug-0.5.7-1-x86_64.pkg.tar");
103 tar_usr(&debug_root, &debug_pkg);
104 let out = tmp.path().join("posprint-0.5.7-x86_64.tar.gz");
105
106 let output = run_tarball_script(&[
107 debug_pkg.to_str().unwrap(),
108 out.to_str().unwrap(),
109 "0.5.7",
110 ]);
111 assert!(!output.status.success());
112 let stderr = String::from_utf8_lossy(&output.stderr);
113 assert!(
114 stderr.contains("No non-debug"),
115 "unexpected stderr: {stderr}"
116 );
117 assert!(!out.exists());
118 }
119
120 #[test]
121 fn tarball_script_classic_three_args_still_works() {
122 let tmp = tempfile::tempdir().unwrap();
123 let main_root = tmp.path().join("main");
124 write_fake_usr_tree(&main_root, "only-main");
125 let main_pkg = tmp.path().join("posprint-0.5.7-1-x86_64.pkg.tar");
126 tar_usr(&main_root, &main_pkg);
127 let out = tmp.path().join("out.tar.gz");
128
129 let output = run_tarball_script(&[main_pkg.to_str().unwrap(), out.to_str().unwrap(), "0.5.7"]);
130 assert!(
131 output.status.success(),
132 "stderr: {}",
133 String::from_utf8_lossy(&output.stderr)
134 );
135 assert!(out.is_file());
136 }
137
138 #[test]
139 fn publish_release_dry_run_uses_real_filenames() {
140 let tmp = tempfile::tempdir().unwrap();
141 let dist = tmp.path();
142 fs::write(dist.join("posprint_0.5.7-1_amd64.deb"), b"deb").unwrap();
143 fs::write(
144 dist.join("posprint-0.5.7-1-x86_64.pkg.tar.zst"),
145 b"pkg",
146 )
147 .unwrap();
148 fs::write(dist.join("posprint-debug-0.5.7-1-x86_64.pkg.tar.zst"), b"dbg").unwrap();
149 fs::write(dist.join("posprint-0.5.7-x86_64.tar.gz"), b"tgz").unwrap();
150 fs::write(dist.join("posprint.exe"), b"exe").unwrap();
151
152 let output = run_publish_release(&[
153 "--dry-run",
154 "--dist",
155 dist.to_str().unwrap(),
156 "0.5.7",
157 ]);
158 assert!(
159 output.status.success(),
160 "stdout:\n{}\nstderr:\n{}",
161 String::from_utf8_lossy(&output.stdout),
162 String::from_utf8_lossy(&output.stderr)
163 );
164 let stdout = String::from_utf8_lossy(&output.stdout);
165 assert!(stdout.contains("posprint_0.5.7-1_amd64.deb"));
166 assert!(stdout.contains("posprint-0.5.7-1-x86_64.pkg.tar.zst"));
167 assert!(
168 !stdout.contains("posprint-debug-"),
169 "debug package must not be a release asset:\n{stdout}"
170 );
171 assert!(
172 !stdout.contains("posprint_0.5.7-1-x86_64"),
173 "Arch package must use hyphens, not posprint_ver:\n{stdout}"
174 );
175 assert!(stdout.contains("posprint-0.5.7-x86_64.tar.gz"));
176 assert!(stdout.contains("posprint.exe"));
177 }
178
179 #[test]
180 fn publish_release_dry_run_rejects_missing_tarball() {
181 let tmp = tempfile::tempdir().unwrap();
182 let dist = tmp.path();
183 fs::write(dist.join("posprint_0.5.7-1_amd64.deb"), b"deb").unwrap();
184 fs::write(
185 dist.join("posprint-0.5.7-1-x86_64.pkg.tar.zst"),
186 b"pkg",
187 )
188 .unwrap();
189 fs::write(dist.join("posprint.exe"), b"exe").unwrap();
190
191 let output = run_publish_release(&[
192 "--dry-run",
193 "--dist",
194 dist.to_str().unwrap(),
195 "0.5.7",
196 ]);
197 assert!(!output.status.success());
198 let stderr = String::from_utf8_lossy(&output.stderr);
199 assert!(
200 stderr.contains("tar.gz"),
201 "expected missing-tarball error, got: {stderr}"
202 );
203 }
204
205 #[test]
206 fn macos_build_script_help_succeeds() {
207 let script = repo_root().join("scripts/build-macos.sh");
208 let output = Command::new("bash")
209 .arg(&script)
210 .arg("--help")
211 .output()
212 .expect("run build-macos.sh --help");
213 assert!(output.status.success());
214 let stdout = String::from_utf8_lossy(&output.stdout);
215 assert!(stdout.contains("--app"));
216 assert!(stdout.contains("--dmg"));
217 assert!(stdout.contains("--install"));
218 }
219}
220
221#[test]
222fn bluegit_ci_uses_release_api_and_aur_dry_run() {
223 let yml = include_str!("../blue-ci-cd.yml");
224 assert!(!yml.contains("jobs/artifacts/"));
225 assert!(yml.contains("scripts/ci/release.sh"));
226 assert!(yml.contains("make-linux-bin-tarball.sh"));
227 assert!(yml.contains("AUR_DRY_RUN"));
228 assert!(yml.contains("allow_failure: true"));
229}
230
231#[test]
232fn aur_bin_uses_bluegit_release_assets() {
233 let pkgbuild = include_str!("../packaging/aur-bin/PKGBUILD");
234 let srcinfo = include_str!("../packaging/aur-bin/.SRCINFO");
235 let publish = include_str!("../scripts/publish-aur.sh");
236 for text in [pkgbuild, srcinfo, publish] {
237 assert!(!text.contains("jobs/artifacts"));
238 assert!(!text.contains("gitlab.com"), "no GitLab URLs after the BlueGit move");
239 assert!(text.contains("git.timfalken.com/timfa/posprint/-/releases/"));
240 }
241 assert!(publish.contains("Using local binary tarball"));
242 assert!(publish.contains("AUR_DRY_RUN"));
243}
244
245#[test]
246fn expected_release_filenames_match_packaging_tools() {
247 // cargo-deb: <name>_<version>-<revision>_<arch>.deb (revision defaults to 1)
248 // makepkg: <pkgname>-<pkgver>-<pkgrel>-<arch>.pkg.tar.zst
249 let version = "0.5.7";
250 assert_eq!(
251 format!("posprint_{version}-1_amd64.deb"),
252 "posprint_0.5.7-1_amd64.deb"
253 );
254 assert_eq!(
255 format!("posprint-{version}-1-x86_64.pkg.tar.zst"),
256 "posprint-0.5.7-1-x86_64.pkg.tar.zst"
257 );
258 assert_eq!(
259 format!("posprint-{version}-x86_64.tar.gz"),
260 "posprint-0.5.7-x86_64.tar.gz"
261 );
262}
263
264#[test]
265fn macos_info_plist_registers_posprint_url_scheme_and_pos_extension() {
266 let plist = include_str!("../packaging/macos/Info.plist");
267 assert!(plist.contains("<string>com.timfa.posprint</string>"));
268 assert!(plist.contains("<string>posprint-launcher</string>"));
269 assert!(plist.contains("<string>posprint</string>"));
270 assert!(plist.contains("<string>pos</string>"));
271 assert!(plist.contains("@VERSION@"));
272}