forked from 1b-agent/opencadstudio-upstream
Automate weekly releases and synchronize application versions
This commit is contained in:
1 parent
28d3aa5be2
commit
13afc1479f
24 files changed
+659
-202
No files matched your search
@@ -67,7 +67,7 @@ fn port_arg() -> Option<u16> {
|
||||
}
|
||||
|
||||
fn ready() -> Value {
|
||||
json!({ "ok": true, "ready": true, "version": env!("CARGO_PKG_VERSION") })
|
||||
json!({ "ok": true, "ready": true, "version": env!("OCS_APP_VERSION") })
|
||||
}
|
||||
|
||||
fn serve_stdio(app: &mut OpenCADStudio) {
|
||||
|
||||
@@ -206,7 +206,7 @@ impl OpenCADStudio {
|
||||
let body = format!(
|
||||
"<!-- Describe the issue and the steps to reproduce it. -->\n\n\n\
|
||||
---\n- Open CAD Studio: v{}\n- Platform: {}\n",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
env!("OCS_APP_VERSION"),
|
||||
crate::sys::platform_info(),
|
||||
);
|
||||
let url = format!(
|
||||
|
||||
@@ -177,7 +177,7 @@ impl OpenCADStudio {
|
||||
"name":c.name(),"prompt":c.prompt(),"options":c.options().iter().map(|o|json!({"label":o.label,"keyword":o.keyword})).collect::<Vec<_>>(),
|
||||
"entity_pick":c.needs_entity_pick(),"structure_pick":c.needs_structure_point_pick(),"selection":c.is_selection_gathering(),"tangent_pick":c.needs_tangent_pick(),"free_text":c.is_free_text_step()
|
||||
}));
|
||||
json!({"ok":true,"protocol":1,"session_id":session_id(),"version":env!("CARGO_PKG_VERSION"),
|
||||
json!({"ok":true,"protocol":1,"session_id":session_id(),"version":env!("OCS_APP_VERSION"),
|
||||
"mode":if self.main_window.is_some(){"gui"}else{"headless"},"enabled":self.control.enabled,
|
||||
"document_id":tab.id,"revision":tab.edit_revision,"geometry_revision":tab.scene.geometry_epoch,"camera_revision":tab.scene.camera_generation,
|
||||
"plugins":plugin_ids(),
|
||||
|
||||
+3
-3
@@ -3951,9 +3951,9 @@ pub fn run() -> iced::Result {
|
||||
if let Some(tab) = state.tabs.get(state.active_tab) {
|
||||
let dot = if tab.dirty { "● " } else { "" };
|
||||
let name = tab.tab_display_name();
|
||||
format!("{}Open CAD Studio — {}", dot, name)
|
||||
format!("{}Open CAD Studio {} - {}", dot, env!("OCS_APP_VERSION"), name)
|
||||
} else {
|
||||
"Open CAD Studio".to_string()
|
||||
concat!("Open CAD Studio ", env!("OCS_APP_VERSION")).to_string()
|
||||
}
|
||||
})
|
||||
.theme(|state: &OpenCADStudio, _| state.active_theme.clone())
|
||||
@@ -3985,7 +3985,7 @@ pub fn run_web() -> iced::Result {
|
||||
OpenCADStudio::view_main,
|
||||
)
|
||||
.subscription(OpenCADStudio::subscription)
|
||||
.title(|_state: &OpenCADStudio| "Open CAD Studio".to_string())
|
||||
.title(|_state: &OpenCADStudio| concat!("Open CAD Studio ", env!("OCS_APP_VERSION")).to_string())
|
||||
.theme(|state: &OpenCADStudio| state.active_theme.clone())
|
||||
.backend(iced::Backend::Hardware(iced::backend::Api::OpenGL))
|
||||
.font(iced_aw::ICED_AW_FONT_BYTES)
|
||||
|
||||
@@ -6458,7 +6458,7 @@ impl OpenCADStudio {
|
||||
Message::AboutCopyInfo => {
|
||||
let info = format!(
|
||||
"Open CAD Studio v{}\nOS: {}\nArch: {}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
env!("OCS_APP_VERSION"),
|
||||
crate::ui::window::about::platform_name(),
|
||||
crate::ui::window::about::architecture_name(),
|
||||
);
|
||||
@@ -6676,7 +6676,7 @@ impl OpenCADStudio {
|
||||
if let Some(error) = &self.plugin_registry_error {
|
||||
return iced::clipboard::write(format!(
|
||||
"Open CAD Studio v{}\nOS: {}\nArchitecture: {}\nRegistry: {}\nError: {}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
env!("OCS_APP_VERSION"),
|
||||
std::env::consts::OS,
|
||||
std::env::consts::ARCH,
|
||||
crate::plugin::marketplace::REGISTRY_URL,
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ fn get_text(agent: &ureq::Agent, url: &str) -> Result<String, String> {
|
||||
.get(url)
|
||||
.header(
|
||||
"User-Agent",
|
||||
concat!("OpenCADStudio/", env!("CARGO_PKG_VERSION")),
|
||||
concat!("OpenCADStudio/", env!("OCS_APP_VERSION")),
|
||||
)
|
||||
.call()
|
||||
.map_err(|e| e.to_string())?
|
||||
|
||||
+1
-1
@@ -254,7 +254,7 @@ impl RecoveryReport {
|
||||
lines.push("Open CAD Studio drawing recovery report".to_string());
|
||||
lines.push(format!("Report schema: {}", REPORT_SCHEMA_VERSION));
|
||||
lines.push(format!("Report ID: {}", self.report_id));
|
||||
lines.push(format!("Application version: {}", env!("CARGO_PKG_VERSION")));
|
||||
lines.push(format!("Application version: {}", env!("OCS_APP_VERSION")));
|
||||
lines.push(format!("Application revision: {}", env!("OCS_GIT_REV")));
|
||||
lines.push(format!("Build profile: {}", env!("OCS_BUILD_PROFILE")));
|
||||
lines.push(format!("Build features: {}", env!("OCS_BUILD_FEATURES")));
|
||||
|
||||
+45
-71
@@ -1,10 +1,4 @@
|
||||
// One-shot update check.
|
||||
//
|
||||
// `check_for_update()` runs on a background thread (joined inside an
|
||||
// async wrapper, mirroring how the rest of `crate::io` wraps blocking
|
||||
// work for iced's `Task::perform`). It hits the GitHub releases API and
|
||||
// returns `Some(UpdateInfo)` when a newer release is available, or
|
||||
// `None` when up to date / on network failure / on parse error.
|
||||
// Check for a newer published native release.
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const RELEASES_API: &str =
|
||||
@@ -12,11 +6,7 @@ const RELEASES_API: &str =
|
||||
pub const RELEASES_PAGE: &str =
|
||||
"https://github.com/HakanSeven12/OpenCADStudio/releases/latest";
|
||||
|
||||
/// Minimum age before a freshly-published release is offered to the user.
|
||||
/// GitHub Actions takes ~15 min to build and attach the platform binaries
|
||||
/// after a tag is pushed, so suppressing notifications for the first hour
|
||||
/// prevents users from clicking through to a release page whose
|
||||
/// asset list is still empty.
|
||||
/// Give release assets time to propagate before offering an update.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const MIN_RELEASE_AGE_SECS: u64 = 60 * 60;
|
||||
|
||||
@@ -51,23 +41,37 @@ fn fetch_latest_if_outdated() -> Option<UpdateInfo> {
|
||||
let agent = crate::network::agent(std::time::Duration::from_secs(5));
|
||||
let body = agent
|
||||
.get(RELEASES_API)
|
||||
.header("User-Agent", concat!("OpenCADStudio/", env!("CARGO_PKG_VERSION")))
|
||||
.header("User-Agent", concat!("OpenCADStudio/", env!("OCS_APP_VERSION")))
|
||||
.header("Accept", "application/vnd.github+json")
|
||||
.call()
|
||||
.ok()?
|
||||
.body_mut()
|
||||
.read_to_string()
|
||||
.ok()?;
|
||||
let latest = extract_string_field(&body, "tag_name")?
|
||||
let metadata: serde_json::Value = serde_json::from_str(&body).ok()?;
|
||||
let suffix = if cfg!(target_os = "windows") {
|
||||
"-windows-x86_64-portable.exe"
|
||||
} else if cfg!(target_os = "macos") {
|
||||
"-macos-arm64.dmg"
|
||||
} else {
|
||||
"-linux-x86_64.AppImage"
|
||||
};
|
||||
if !metadata.get("assets")?.as_array()?.iter().any(|asset| {
|
||||
asset.get("name").and_then(|name| name.as_str()).is_some_and(|name| name.ends_with(suffix))
|
||||
&& asset.get("size").and_then(|size| size.as_u64()).unwrap_or(0) > 0
|
||||
}) {
|
||||
return None;
|
||||
}
|
||||
let latest = metadata.get("tag_name")?.as_str()?
|
||||
.trim_start_matches('v')
|
||||
.to_string();
|
||||
if latest == env!("CARGO_PKG_VERSION") {
|
||||
if !is_newer(&latest, env!("OCS_APP_VERSION")) {
|
||||
return None;
|
||||
}
|
||||
// Suppress the notification until the release is old enough for the
|
||||
// Actions build to have published binaries.
|
||||
if let Some(published) = extract_string_field(&body, "published_at")
|
||||
.as_deref()
|
||||
if let Some(published) = metadata.get("published_at")
|
||||
.and_then(|value| value.as_str())
|
||||
.and_then(parse_iso8601_utc)
|
||||
{
|
||||
let now = std::time::SystemTime::now()
|
||||
@@ -79,7 +83,7 @@ fn fetch_latest_if_outdated() -> Option<UpdateInfo> {
|
||||
}
|
||||
}
|
||||
// Release notes are optional; treat missing as empty.
|
||||
let notes = extract_string_field(&body, "body").unwrap_or_default();
|
||||
let notes = metadata.get("body").and_then(|value| value.as_str()).unwrap_or_default().to_string();
|
||||
Some(UpdateInfo { version: latest, body: notes })
|
||||
}
|
||||
|
||||
@@ -129,61 +133,31 @@ fn parse_iso8601_utc(s: &str) -> Option<u64> {
|
||||
)
|
||||
}
|
||||
|
||||
/// Minimal extractor for a top-level string field in the releases JSON.
|
||||
/// Avoids pulling in `serde_json` for two fields. Handles standard JSON
|
||||
/// string escapes (`\"`, `\\`, `\n`, `\r`, `\t`, `\/`) which are all the
|
||||
/// GitHub release body uses in practice.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn extract_string_field(body: &str, field: &str) -> Option<String> {
|
||||
let key = format!("\"{}\":\"", field);
|
||||
let start = body.find(&key)? + key.len();
|
||||
// Walk to the closing unescaped `"`, JSON-unescaping as we go.
|
||||
let mut out = String::new();
|
||||
let bytes = body.as_bytes();
|
||||
let mut i = start;
|
||||
while i < bytes.len() {
|
||||
let b = bytes[i];
|
||||
if b == b'"' {
|
||||
return Some(out);
|
||||
}
|
||||
if b == b'\\' && i + 1 < bytes.len() {
|
||||
match bytes[i + 1] {
|
||||
b'"' => out.push('"'),
|
||||
b'\\' => out.push('\\'),
|
||||
b'/' => out.push('/'),
|
||||
b'n' => out.push('\n'),
|
||||
b'r' => out.push('\r'),
|
||||
b't' => out.push('\t'),
|
||||
b'u' => {
|
||||
// \uXXXX — decode 4 hex digits. Surrogate pairs (BMP only
|
||||
// for now) are uncommon in release notes; skip on parse
|
||||
// failure.
|
||||
if i + 5 < bytes.len() {
|
||||
let hex = std::str::from_utf8(&bytes[i + 2..i + 6]).ok()?;
|
||||
if let Ok(code) = u32::from_str_radix(hex, 16) {
|
||||
if let Some(c) = char::from_u32(code) {
|
||||
out.push(c);
|
||||
}
|
||||
}
|
||||
i += 6;
|
||||
continue;
|
||||
}
|
||||
return None;
|
||||
}
|
||||
other => {
|
||||
// Unknown escape — keep the literal pair, GitHub doesn't emit these.
|
||||
out.push('\\');
|
||||
out.push(other as char);
|
||||
}
|
||||
fn is_newer(latest: &str, installed: &str) -> bool {
|
||||
let parse = |version: &str| {
|
||||
let version = version.trim_start_matches('v');
|
||||
if let Some((year, week)) = version.split_once('.') {
|
||||
if year.len() == 4 && year.starts_with("20") && !week.contains('.') {
|
||||
return Some(semver::Version::new(year.parse().ok()?, week.parse().ok()?, 0));
|
||||
}
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
// UTF-8 multi-byte chars: push the whole code-point so we don't
|
||||
// bisect a sequence.
|
||||
let ch = body[i..].chars().next()?;
|
||||
out.push(ch);
|
||||
i += ch.len_utf8();
|
||||
semver::Version::parse(version).ok()
|
||||
};
|
||||
matches!((parse(latest), parse(installed)), (Some(latest), Some(installed)) if latest > installed)
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn calendar_releases_compare_numerically() {
|
||||
assert!(is_newer("2026.35", "0.9.8"));
|
||||
assert!(is_newer("2026.10", "2026.09"));
|
||||
assert!(is_newer("2027.01", "2026.53"));
|
||||
assert!(!is_newer("2026.35", "2026.35"));
|
||||
assert!(!is_newer("0.9.8", "2026.35"));
|
||||
assert!(!is_newer("invalid", "2026.35"));
|
||||
}
|
||||
None
|
||||
}
|
||||
+1
-1
@@ -424,7 +424,7 @@ fn response(id: Value, result: Value) -> Value {
|
||||
}
|
||||
|
||||
fn server_info() -> Value {
|
||||
json!({"name":"OpenCADStudio","title":"Open CAD Studio","version":env!("CARGO_PKG_VERSION")})
|
||||
json!({"name":"OpenCADStudio","title":"Open CAD Studio","version":env!("OCS_APP_VERSION")})
|
||||
}
|
||||
|
||||
fn modern_request(params: &Value) -> bool {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ pub fn merge_manual(mut patrons: Vec<(String, i64)>) -> Vec<(String, i64)> {
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const UA: &str = concat!("OpenCADStudio/", env!("CARGO_PKG_VERSION"));
|
||||
const UA: &str = concat!("OpenCADStudio/", env!("OCS_APP_VERSION"));
|
||||
|
||||
/// Fetch patrons with a successful payment in the last month from the Patreon
|
||||
/// API as `(display name, amount in USD cents)`, highest payment first. `Err`
|
||||
|
||||
@@ -107,7 +107,7 @@ fn agent() -> ureq::Agent {
|
||||
crate::network::agent(std::time::Duration::from_secs(15))
|
||||
}
|
||||
|
||||
const UA: &str = concat!("OpenCADStudio/", env!("CARGO_PKG_VERSION"));
|
||||
const UA: &str = concat!("OpenCADStudio/", env!("OCS_APP_VERSION"));
|
||||
|
||||
/// Fetch releases without consuming GitHub API quota. The public Atom feed
|
||||
/// supplies tags and the expanded-assets endpoint supplies download links.
|
||||
|
||||
@@ -430,7 +430,7 @@ fn fetch_remote(url: &str) -> Option<Vec<u8>> {
|
||||
.get(url)
|
||||
.header(
|
||||
"User-Agent",
|
||||
concat!("OpenCADStudio/", env!("CARGO_PKG_VERSION")),
|
||||
concat!("OpenCADStudio/", env!("OCS_APP_VERSION")),
|
||||
)
|
||||
.call()
|
||||
.ok()?;
|
||||
|
||||
@@ -76,7 +76,7 @@ pub(crate) fn architecture_name() -> &'static str {
|
||||
pub fn view_window(
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'static, Message> {
|
||||
let version = format!("v{}", env!("CARGO_PKG_VERSION"));
|
||||
let version = format!("v{}", env!("OCS_APP_VERSION"));
|
||||
let content_width = if matches!(sizing.width, Length::Fill) {
|
||||
Fill
|
||||
} else {
|
||||
|
||||
@@ -156,7 +156,7 @@ pub fn view_window<'a>(
|
||||
// row layout. The arrow between them is purely decorative.
|
||||
let installed = version_card(
|
||||
t!("Installed"),
|
||||
format!("v{}", env!("CARGO_PKG_VERSION")),
|
||||
format!("v{}", env!("OCS_APP_VERSION")),
|
||||
false,
|
||||
sizing.width,
|
||||
);
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ pub fn watch_url(id: &str) -> String {
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const UA: &str = concat!("OpenCADStudio/", env!("CARGO_PKG_VERSION"));
|
||||
const UA: &str = concat!("OpenCADStudio/", env!("OCS_APP_VERSION"));
|
||||
|
||||
/// Directory of the on-disk thumbnail / listing cache.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
||||
Reference in new issue
Block a user