Skip to content

Commit

Permalink
feat: Generate flathub meta for a release
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Sep 22, 2024
1 parent 9b4f482 commit 77e4359
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ cmake = "0.1"

[dev-dependencies]
cmd_lib = "1.3.0"
xmltree = "0.11.0"
chrono = "0.4.38"

[profile.release]
codegen-units = 1
Expand Down
2 changes: 2 additions & 0 deletions create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ cargo check --no-default-features --features notan/glsl-to-spirv
cargo test shortcuts
cargo bump patch
cargo build
cargo test flathub
VERSION=`cargo pkgid | cut -d# -f2 | cut -d: -f2`
git add README.md
git add Cargo.toml
git add Cargo.lock
git add PKGBUILD
git add res/flathub/io.github.woelper.Oculante.metainfo.xml
# tag the commit with current version
git commit -m "Release version $VERSION"
git tag $VERSION
Expand Down
67 changes: 67 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,73 @@ fn dump_shortcuts() {
}
}

#[test]
/// Generate / update flathub meta
fn flathub() {
use chrono::offset::Utc;
use chrono::DateTime;
use std::time::SystemTime;
use xmltree::Element;
use xmltree::{EmitterConfig, XMLNode};

let kokai_result = std::process::Command::new("kokai")
.args(&["release", "--ref", "HEAD"])
.output()
.unwrap()
.stdout;
let release_notes = String::from_utf8_lossy(&kokai_result);

let metafile = "res/flathub/io.github.woelper.Oculante.metainfo.xml";
let s = std::fs::read_to_string(metafile).unwrap();
let mut doc = Element::parse(s.as_bytes()).unwrap();
let releases = doc.get_mut_child("releases").unwrap();
// check if this version is already present, we don't want duplicates
for c in &releases.children {
if c.as_element().unwrap().attributes.get("version").unwrap() == env!("CARGO_PKG_VERSION") {
panic!("This release already exists!");
}
}
let mut new_release = Element::new("release");

new_release
.attributes
.insert("version".into(), env!("CARGO_PKG_VERSION").into());

let datetime: DateTime<Utc> = SystemTime::now().into();
let date = format!("{}", datetime.format("%Y-%m-%d"));
new_release.attributes.insert("date".into(), date);
let mut url = Element::new("url");
let mut description = Element::new("description");
let mut changelog = Element::new("p");
changelog
.children
.insert(0, XMLNode::Text(format!("{release_notes}")));
description.children.insert(0, XMLNode::Element(changelog));

url.attributes.insert("type".into(), "details".into());
url.children.insert(
0,
XMLNode::Text(format!(
"https://github.com/woelper/oculante/releases/tag/{}",
env!("CARGO_PKG_VERSION")
)),
);

new_release.children.insert(0, XMLNode::Element(url));
new_release
.children
.insert(0, XMLNode::Element(description));
releases.children.insert(0, XMLNode::Element(new_release));
let config = EmitterConfig::new()
.autopad_comments(true)
.perform_indent(true);

// doc.write_with_config(File::create("result.xml").unwrap(), config)
// .unwrap();
doc.write_with_config(File::create(metafile).unwrap(), config)
.unwrap();
}

#[test]
fn bench_process_all() {
std::env::set_var("RUST_LOG", "info");
Expand Down

0 comments on commit 77e4359

Please sign in to comment.