feat: include git commit in version info (#249)

* feat: report git commit in version info, check commit for mismatches

* feat: use vergen to get commit info

* fix: install git in recipes

* fix: include git dir in pkger builds
This commit is contained in:
Ilya Zlobintsev 2024-03-02 13:07:23 +02:00 committed by GitHub
parent 9fc0eae90a
commit d99cfdf3f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 117 additions and 17 deletions

82
Cargo.lock generated
View File

@ -633,6 +633,15 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7762d17f1241643615821a8455a0b2c3e803784b058693d990b11f2dce25a0ca"
[[package]]
name = "deranged"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
dependencies = [
"powerfmt",
]
[[package]]
name = "derivative"
version = "2.2.0"
@ -1383,6 +1392,7 @@ dependencies = [
"serde",
"serde_json",
"serde_with",
"vergen",
]
[[package]]
@ -1605,6 +1615,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-traits"
version = "0.2.17"
@ -1614,6 +1630,15 @@ dependencies = [
"autocfg",
]
[[package]]
name = "num_threads"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
@ -1784,6 +1809,12 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@ -1998,6 +2029,12 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "rustversion"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "ryu"
version = "1.0.16"
@ -2273,6 +2310,39 @@ dependencies = [
"once_cell",
]
[[package]]
name = "time"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
dependencies = [
"deranged",
"itoa",
"libc",
"num-conv",
"num_threads",
"powerfmt",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774"
dependencies = [
"num-conv",
"time-core",
]
[[package]]
name = "tokio"
version = "1.35.1"
@ -2460,6 +2530,18 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vergen"
version = "8.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525"
dependencies = [
"anyhow",
"cfg-if",
"rustversion",
"time",
]
[[package]]
name = "version-compare"
version = "0.1.1"

View File

@ -98,6 +98,7 @@ As some of the GPU settings may get reset when suspending the system, LACT will
Dependencies:
- rust
- gtk4
- git
- pkg-config
- make
- hwdata

View File

@ -1,5 +1,5 @@
use anyhow::{anyhow, Context};
use lact_schema::{InitramfsType, SystemInfo};
use lact_schema::{InitramfsType, SystemInfo, GIT_COMMIT};
use os_release::{OsRelease, OS_RELEASE};
use std::{
fs::{self, File, Permissions},
@ -41,6 +41,7 @@ pub fn info() -> anyhow::Result<SystemInfo<'static>> {
profile,
kernel_version,
amdgpu_overdrive_enabled,
commit: Some(GIT_COMMIT),
})
}

View File

@ -13,6 +13,7 @@ use gtk::glib::{timeout_future, ControlFlow};
use gtk::{gio::ApplicationFlags, prelude::*, *};
use header::Header;
use lact_client::schema::request::{ConfirmCommand, SetClocksCommand};
use lact_client::schema::GIT_COMMIT;
use lact_client::DaemonClient;
use lact_daemon::MODULE_CONF_PATH;
use root_stack::RootStack;
@ -56,8 +57,8 @@ impl App {
.icon_name(APP_ID)
.build();
if system_info.version != GUI_VERSION {
let err = anyhow!("Version mismatch between GUI and daemon ({GUI_VERSION} vs {})! Make sure you have restarted the service if you have updated LACT.", system_info.version);
if system_info.version != GUI_VERSION || system_info.commit != Some(GIT_COMMIT) {
let err = anyhow!("Version mismatch between GUI and daemon ({GUI_VERSION}-{GIT_COMMIT} vs {}-{})! Make sure you have restarted the service if you have updated LACT.", system_info.version, system_info.commit.unwrap_or_default());
show_error(&window, err);
}

View File

@ -1,6 +1,7 @@
use crate::GUI_VERSION;
use gtk::glib::{self, Object};
use lact_client::schema::SystemInfo;
use lact_client::schema::{SystemInfo, GIT_COMMIT};
use std::fmt::Write;
glib::wrapper! {
pub struct SoftwarePage(ObjectSubclass<imp::SoftwarePage>)
@ -14,13 +15,16 @@ impl SoftwarePage {
if embedded {
daemon_version.push_str("-embedded");
}
if let Some(commit) = system_info.commit {
write!(daemon_version, " (commit {commit})").unwrap();
}
let gui_profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
let gui_version = format!("{GUI_VERSION}-{gui_profile}");
let gui_version = format!("{GUI_VERSION}-{gui_profile} (commit {GIT_COMMIT})");
Object::builder()
.property("daemon-version", daemon_version)

View File

@ -14,5 +14,8 @@ serde_with = { workspace = true }
indexmap = { version = "*", features = ["serde"] }
clap = { version = "4.4.18", features = ["derive"], optional = true }
[build-dependencies]
vergen = { version = "8.0.0", features = ["git", "gitcl"] }
[dev-dependencies]
serde_json = { workspace = true }

5
lact-schema/build.rs Normal file
View File

@ -0,0 +1,5 @@
use vergen::EmitBuilder;
fn main() {
EmitBuilder::builder().git_sha(true).emit().unwrap()
}

View File

@ -26,6 +26,8 @@ use std::{
str::FromStr,
};
pub const GIT_COMMIT: &str = env!("VERGEN_GIT_SHA");
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum FanControlMode {
@ -58,6 +60,7 @@ pub struct Pong;
#[derive(Serialize, Deserialize, Debug)]
pub struct SystemInfo<'a> {
pub version: &'a str,
pub commit: Option<&'a str>,
pub profile: &'a str,
pub kernel_version: String,
pub amdgpu_overdrive_enabled: Option<bool>,

View File

@ -7,7 +7,7 @@ metadata:
maintainer: ilya-zlobintsev
url: https://github.com/ilya-zlobintsev/lact
source:
- '../../..'
- '../../../../LACT'
provides: [ lact ]
conflicts: [ lact, lact-libadwaita ]
depends:
@ -17,7 +17,7 @@ metadata:
arch: [ libdrm ]
opensuse-tumbleweed: [ libdrm ]
build_depends:
all: [ curl, make, clang ]
all: [ curl, make, clang, git ]
debian-12+ubuntu-2204: [ pkg-config, build-essential, libdrm-dev, dbus ]
fedora-38+fedora-39: [ gcc, libdrm-devel, dbus ]
arch: [ libdrm, dbus ]
@ -31,8 +31,8 @@ configure:
- cmd: sh /tmp/install_rust.sh -y --default-toolchain stable
build:
steps:
- cmd: bash -c "source $HOME/.cargo/env && make build-release-headless"
- cmd: bash -c "source $HOME/.cargo/env && cd LACT && make build-release-headless"
install:
steps:
- cmd: bash -c "cd $PKGER_BLD_DIR && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"
- cmd: bash -c "cd $PKGER_BLD_DIR/LACT && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"

View File

@ -7,7 +7,7 @@ metadata:
maintainer: ilya-zlobintsev
url: https://github.com/ilya-zlobintsev/lact
source:
- '../../..'
- '../../../../LACT'
provides: [ lact ]
conflicts: [ lact, lact-headless ]
depends:
@ -16,7 +16,7 @@ metadata:
arch: [ gtk4, libadwaita ]
opensuse-tumbleweed: [ libdrm, libadwaita ]
build_depends:
all: [ curl, make, clang ]
all: [ curl, make, clang, git ]
fedora-39: [ gtk4-devel, gcc, libdrm-devel, blueprint-compiler, libadwaita-devel, dbus ]
arch: [ gtk4, blueprint-compiler, libadwaita, dbus ]
opensuse-tumbleweed: [ libdrm-devel, blueprint-compiler, libadwaita-devel ]
@ -33,8 +33,8 @@ configure:
deb: true
build:
steps:
- cmd: bash -c "source $HOME/.cargo/env && make build-release-libadwaita"
- cmd: bash -c "source $HOME/.cargo/env && cd LACT && make build-release-libadwaita"
install:
steps:
- cmd: bash -c "cd $PKGER_BLD_DIR && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"
- cmd: bash -c "cd $PKGER_BLD_DIR/LACT && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"

View File

@ -7,7 +7,7 @@ metadata:
maintainer: ilya-zlobintsev
url: https://github.com/ilya-zlobintsev/lact
source:
- '../../..'
- '../../../../LACT'
provides: [ lact ]
conflicts: [ lact-headless, lact-libadwaita ]
depends:
@ -17,7 +17,7 @@ metadata:
arch: [ gtk4 ]
opensuse-tumbleweed: [ gtk4 ]
build_depends:
all: [ curl, make, clang ]
all: [ curl, make, clang, git ]
debian-12+ubuntu-2204: [ libgtk-4-dev, pkg-config, build-essential, libdrm-dev, dbus ]
fedora-38+fedora-39: [ gtk4-devel, gcc, libdrm-devel, blueprint-compiler, dbus ]
arch: [ gtk4, blueprint-compiler, dbus ]
@ -35,8 +35,8 @@ configure:
deb: true
build:
steps:
- cmd: bash -c "source $HOME/.cargo/env && make build-release"
- cmd: bash -c "source $HOME/.cargo/env && cd LACT && make build-release"
install:
steps:
- cmd: bash -c "cd $PKGER_BLD_DIR && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"
- cmd: bash -c "cd $PKGER_BLD_DIR/LACT && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"