Skip to content

Commit

Permalink
feat: publish script and better updater
Browse files Browse the repository at this point in the history
  • Loading branch information
filipton committed Jul 13, 2023
1 parent 6769518 commit 2b26531
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
11 changes: 11 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

last=$(curl -s https://api.github.com/repos/filipton/dgus-moonraker-screen/releases/latest | jq -r .tag_name)
echo "Last release: $last"

echo -n "Release version (for eg. 2.4.1): "
read version

echo "pub const VERSION: &str = \"$version\";" > ./serial-screen/src/version.rs
bash ./build-all.sh
gh release create --latest --generate-notes $version ./dist/*
3 changes: 2 additions & 1 deletion serial-screen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use moonraker::{MoonrakerRx, MoonrakerTx};
use rppal::uart::Uart;
use screen_state::ScreenState;
use serial_utils::construct_change_page;
use updater::check_for_updates;
use std::sync::Arc;
use tokio::{
sync::{Mutex, RwLock},
time::Instant,
};
use updater::check_for_updates;
use utils::subscribe_websocket_events;

mod buttons;
Expand All @@ -19,6 +19,7 @@ mod serial_utils;
mod structs;
mod updater;
mod utils;
mod version;

const RETRY_TIMEOUT: u64 = 5000;
const BOOT_TIMEOUT: u128 = 1000;
Expand Down
9 changes: 3 additions & 6 deletions serial-screen/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use anyhow::Result;
use reqwest::header::HeaderMap;
use serde::Deserialize;

use crate::version::VERSION;

#[cfg(any(target_arch = "x86_64"))]
pub const PLATFORM: &str = "x86_64";

Expand All @@ -19,7 +21,6 @@ struct GithubReleasesRoot {
#[derive(Debug, Clone, Deserialize)]
struct GithubReleaseAsset {
name: String,
size: u64,
browser_download_url: String,
}

Expand All @@ -34,10 +35,6 @@ pub async fn check_for_updates() {
}

let client = reqwest::Client::new();
let current_file_size = tokio::fs::metadata("/opt/serial-screen/serial-screen")
.await
.unwrap()
.len();

let headers = reqwest::header::HeaderMap::from_iter(vec![(
reqwest::header::USER_AGENT,
Expand All @@ -60,7 +57,7 @@ pub async fn check_for_updates() {
.find(|asset| asset.name.contains(PLATFORM));

if let Some(current_arch_release) = current_arch_release {
if current_arch_release.size != current_file_size {
if current_arch_release.name != VERSION {
let res = update(&client, headers, &current_arch_release.browser_download_url)
.await;

Expand Down
1 change: 1 addition & 0 deletions serial-screen/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const VERSION: &str = "0.2.3";

0 comments on commit 2b26531

Please sign in to comment.