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