BlueGit

golden-age paperdoll-renderer

Files

paperdoll-renderer / tests / release_publish.rs

release_publish.rs

59dd3616 History
release_publish.rs 4.1 KiB Download Raw
1//! The tag publish step must not recreate the git tag and must not send
2//! replace. BlueGit has no attach-to-existing-tag route; the script refuses
3//! the create-release call instead of issuing it.
4
5#![cfg(unix)]
6
7use std::fs;
8use std::os::unix::fs::PermissionsExt;
9use std::path::PathBuf;
10use std::process::Command;
11
12fn repo_root() -> PathBuf {
13 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
14}
15
16fn path_prefix_env(prefix: &std::path::Path) -> std::ffi::OsString {
17 let mut path = std::ffi::OsString::from(prefix);
18 path.push(":");
19 path.push(std::env::var_os("PATH").unwrap_or_default());
20 path
21}
22
23fn install_curl_trap(dir: &std::path::Path) -> PathBuf {
24 let curl = dir.join("curl");
25 fs::write(
26 &curl,
27 "#!/bin/sh\nprintf '%s\\n' \"$*\" >> \"${CURL_TRAP_LOG:?}\"\nexit 0\n",
28 )
29 .unwrap();
30 let mut permissions = fs::metadata(&curl).unwrap().permissions();
31 permissions.set_mode(0o755);
32 fs::set_permissions(&curl, permissions).unwrap();
33 curl
34}
35
36fn executable_lines(script: &str) -> String {
37 script
38 .lines()
39 .map(str::trim)
40 .filter(|line| !line.is_empty() && !line.starts_with('#'))
41 .collect::<Vec<_>>()
42 .join("\n")
43}
44
45#[test]
46fn tag_publish_does_not_call_create_release_or_send_replace() {
47 let dir = std::env::temp_dir().join(format!("paperdoll-release-trap-{}", std::process::id()));
48 let _ = fs::remove_dir_all(&dir);
49 fs::create_dir_all(&dir).unwrap();
50 let log = dir.join("curl.log");
51 install_curl_trap(&dir);
52
53 let output = Command::new("bash")
54 .arg(repo_root().join("scripts/ci/release.sh"))
55 .env("PATH", path_prefix_env(&dir))
56 .env("CURL_TRAP_LOG", &log)
57 .env("CI_API_URL", "https://git.example.invalid/api/v1")
58 .env("CI_JOB_TOKEN", "bgj_test_token_not_secret")
59 .env("CI_COMMIT_SHA", "0123456789abcdef0123456789abcdef01234567")
60 .env("CI_PROJECT_PATH", "golden-age/paperdoll-renderer")
61 .env("CI_COMMIT_TAG", "v0.1.0")
62 .env_remove("PACKAGE_VERSION")
63 .output()
64 .unwrap();
65
66 let stderr = String::from_utf8_lossy(&output.stderr);
67 let stdout = String::from_utf8_lossy(&output.stdout);
68 assert_eq!(
69 output.status.code(),
70 Some(3),
71 "stdout:\n{stdout}\nstderr:\n{stderr}"
72 );
73 assert!(
74 stderr.contains("release-blocked: no-attach-endpoint"),
75 "{stderr}"
76 );
77 assert!(
78 !log.exists(),
79 "curl was invoked:\n{}",
80 fs::read_to_string(&log).unwrap_or_default()
81 );
82 let script = fs::read_to_string(repo_root().join("scripts/ci/release.sh")).unwrap();
83 let executable = executable_lines(&script);
84 assert!(
85 !executable.contains("curl"),
86 "executable release script must not call curl:\n{executable}"
87 );
88 assert!(
89 !executable.contains("replace"),
90 "executable release script must not send replace:\n{executable}"
91 );
92 let _ = fs::remove_dir_all(&dir);
93}
94
95#[test]
96fn tag_publish_still_rejects_a_non_semver_tag_before_the_api_block() {
97 let dir =
98 std::env::temp_dir().join(format!("paperdoll-release-trap-bad-{}", std::process::id()));
99 let _ = fs::remove_dir_all(&dir);
100 fs::create_dir_all(&dir).unwrap();
101 let log = dir.join("curl.log");
102 install_curl_trap(&dir);
103 let output = Command::new("bash")
104 .arg(repo_root().join("scripts/ci/release.sh"))
105 .env("PATH", path_prefix_env(&dir))
106 .env("CURL_TRAP_LOG", &log)
107 .env("CI_API_URL", "https://git.example.invalid/api/v1")
108 .env("CI_JOB_TOKEN", "bgj_test_token_not_secret")
109 .env("CI_COMMIT_SHA", "0123456789abcdef0123456789abcdef01234567")
110 .env("CI_PROJECT_PATH", "golden-age/paperdoll-renderer")
111 .env("CI_COMMIT_TAG", "not-a-version")
112 .env_remove("PACKAGE_VERSION")
113 .output()
114 .unwrap();
115 assert_ne!(output.status.code(), Some(0));
116 assert_ne!(output.status.code(), Some(3));
117 let stderr = String::from_utf8_lossy(&output.stderr);
118 assert!(stderr.contains("package version must be X.Y.Z"), "{stderr}");
119 assert!(!log.exists(), "curl was invoked for an invalid tag");
120 let _ = fs::remove_dir_all(&dir);
121}