From 60fce326dd7365a36788d7ae2f7d7828ce7091ab Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 23:30:26 +0100 Subject: [PATCH] Use commit for version again --- Cargo.lock | 5 +++-- Cargo.toml | 1 + Jenkinsfile | 2 +- src/main.rs | 2 +- src/update.rs | 11 ++++------- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b41dc0..2dddb2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,7 @@ dependencies = [ "dialoguer", "indicatif", "serde", + "serde_json", "toml", ] @@ -354,9 +355,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" dependencies = [ "itoa", "ryu", diff --git a/Cargo.toml b/Cargo.toml index 7559aee..17f67b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" dialoguer = "0.10.3" indicatif = "0.17.3" toml = "0.6.0" +serde_json = "1.0.93" [dependencies.serde] version = "1.0.152" diff --git a/Jenkinsfile b/Jenkinsfile index 14b8caf..3c49e99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${GIT_COMMIT}/installer-amd64' } } } diff --git a/src/main.rs b/src/main.rs index 9f23690..7592212 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ impl ToString for MainMenu { } fn main() { - if let Some(version) = option_env!("BUILD_NUMBER") { + if let Some(version) = option_env!("GIT_COMMIT") { println!("Starting installer version {}", version); update::check_for_updates(version); } else { diff --git a/src/update.rs b/src/update.rs index 263f9c7..5fa13cc 100644 --- a/src/update.rs +++ b/src/update.rs @@ -10,19 +10,16 @@ struct PackageEntry { version: String } -const GITEA_KEY: &str = "1e9527c38c98b297dbdaaf39c060e075b2729464"; +const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802"; pub fn check_for_updates(version: &str) { - let version: u64 = version.parse().unwrap(); print!("Checking for updates... "); - let resp: Vec = attohttpc::get("https://gitea.mattv.de/api/v1/packages/root?type=generic&q=installer") + let resp: serde_json::Value = attohttpc::get("https://gitea.mattv.de/api/v1/repos/root/dotfiles/branches/installer") .header("accept", "application/json") .header("Authorization", format!("token {GITEA_KEY}")) .send().unwrap().json().unwrap(); - let newest = resp.into_iter() - .map(|entry| entry.version.parse::().unwrap()) - .max().unwrap(); - if newest > version { + let newest = resp["commit"]["id"].as_str().unwrap(); + if newest != version { println!("New version {newest}"); let exe = current_exe().unwrap(); let temp = Path::new("temp");