Skip to content

Commit 07f7bd2

Browse files
committed
Create GitHub release if run on CI
1 parent d1c0581 commit 07f7bd2

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/main.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ fn main() {
1212
.find(|link| link.contains("git-ovmf-x64"))
1313
.expect("no ovmf link found");
1414
println!("Downloading {}", file_name);
15+
let (date, build_number, hash) = {
16+
let stripped = file_name.strip_prefix("edk2.git-ovmf-x64-0-").unwrap();
17+
let mut components = stripped.split('.');
18+
let date = components.next().unwrap();
19+
let build_number = components.next().unwrap();
20+
let hash = components.next().unwrap();
21+
(date, build_number, hash)
22+
};
1523

1624
let target_dir = Path::new("target").join("download");
1725
std::fs::create_dir_all(&target_dir).unwrap();
@@ -56,6 +64,16 @@ fn main() {
5664
.join("ovmf-x64");
5765
assert!(ovmf_root.exists());
5866

59-
// TODO: if run on ci (check env variable), create a new release using `gh` cli tool:
60-
// gh release create v<date> {ovmf_root}
67+
if std::env::var("CI").as_deref() == Ok("true") {
68+
let version = format!("v0.{}.{}+{}", date, build_number, hash);
69+
println!("Releasing version {}", version);
70+
let mut cmd = std::process::Command::new("gh");
71+
cmd.arg("release").arg("create").arg(&version);
72+
for entry in std::fs::read_dir(&ovmf_root).unwrap() {
73+
cmd.arg(entry.unwrap().path());
74+
}
75+
if !cmd.status().unwrap().success() {
76+
panic!("gh release failed")
77+
}
78+
}
6179
}

0 commit comments

Comments
 (0)