From 4a9dec7e34216d5bcf20437f9900189e1c40e989 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Fri, 18 Apr 2025 12:01:47 +0200 Subject: [PATCH] Fixed version string --- .gitea/workflows/build.yaml | 8 ++++++-- Dockerfile | 3 +++ src/lib.rs | 6 ++++++ src/main.rs | 8 ++------ src/ssh/renderer.rs | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 8e34967..2a15a02 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -21,8 +21,10 @@ jobs: fetch-depth: 0 fetch-tags: true - - name: Get Git commit timestamps - run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV + - name: Set git based environment variables + run: | + echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV + echo "RELEASE_VERSION=$(git describe --always --dirty='--modified)" >> $GITHUB_ENV - name: Login to registry uses: docker/login-action@v3 @@ -67,6 +69,8 @@ jobs: annotations: ${{ steps.meta.outputs.annotations }} cache-from: type=gha cache-to: type=gha,mode=max + build-args: | + "RELEASE_VERSION=${{ env.RELEASE_VERSION }}" env: SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} diff --git a/Dockerfile b/Dockerfile index 1a9bbfd..de50f1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,9 @@ ENV RUSTC_BOOTSTRAP=1 RUN cargo chef cook --release --recipe-path recipe.json COPY . . +ARG RELEASE_VERSION +ENV RELEASE_VERSION ${RELEASE_VERSION} +# HACK: Enable the use of features on stable ENV RUSTC_BOOTSTRAP=1 RUN cargo auditable build --release diff --git a/src/lib.rs b/src/lib.rs index acf1da5..c720881 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,3 +6,9 @@ pub mod ldap; pub mod ssh; pub mod tunnel; pub mod web; + +pub fn get_version() -> &'static str { + std::option_env!("RELEASE_VERSION") + .filter(|version| !version.is_empty()) + .unwrap_or(git_version::git_version!()) +} diff --git a/src/main.rs b/src/main.rs index 2e1778c..bfb51af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,10 @@ use std::path::Path; use color_eyre::eyre::Context; use dotenvy::dotenv; -use git_version::git_version; use hyper::server::conn::http1::{self}; use hyper_util::rt::TokioIo; use rand::rngs::OsRng; +use siranga::get_version; use siranga::ldap::Ldap; use siranga::ssh::Server; use siranga::tunnel::Registry; @@ -38,11 +38,7 @@ async fn main() -> color_eyre::Result<()> { .init(); } - info!( - "Starting {} ({})", - std::env!("CARGO_PKG_NAME"), - git_version!(), - ); + info!(version = get_version(), "Starting",); let key = if let Ok(path) = std::env::var("PRIVATE_KEY_FILE") { russh::keys::PrivateKey::read_openssh_file(Path::new(&path)) diff --git a/src/ssh/renderer.rs b/src/ssh/renderer.rs index 5d98db3..81f2645 100644 --- a/src/ssh/renderer.rs +++ b/src/ssh/renderer.rs @@ -4,7 +4,6 @@ use std::iter::once; use std::time::Duration; use futures::StreamExt; -use git_version::git_version; use ratatui::layout::{Constraint, Flex, Layout, Position, Rect}; use ratatui::prelude::CrosstermBackend; use ratatui::style::{Style, Stylize as _}; @@ -18,6 +17,7 @@ use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel}; use tracing::error; use unicode_width::UnicodeWidthStr; +use crate::get_version; use crate::io::TerminalHandle; use crate::tunnel::{Tunnel, TunnelRow}; @@ -165,7 +165,7 @@ impl RendererInner { } fn render_title(&self, frame: &mut Frame, rect: Rect) { - let title = format!("{} ({})", std::env!("CARGO_PKG_NAME"), git_version!()).bold(); + let title = format!("{} ({})", std::env!("CARGO_PKG_NAME"), get_version()).bold(); let title = Line::from(title).centered(); frame.render_widget(title, rect); }