diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 8e34967..1a25bd0 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -17,12 +17,13 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - name: Get Git commit timestamps - run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV + - name: Set timestamp and release version + run: | + echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV + git fetch --prune --unshallow --tags + echo "RELEASE_VERSION=$(git describe --always --dirty='--modified')" >> $GITHUB_ENV + echo $GITHUB_ENV - name: Login to registry uses: docker/login-action@v3 @@ -67,6 +68,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..bd7222e 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..f20a9a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,4 +5,7 @@ mod io; pub mod ldap; pub mod ssh; pub mod tunnel; +mod version; pub mod web; + +pub use version::VERSION; diff --git a/src/main.rs b/src/main.rs index 2e1778c..bd5bf16 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::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 = 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/handler.rs b/src/ssh/handler.rs index 74f3473..1a36dca 100644 --- a/src/ssh/handler.rs +++ b/src/ssh/handler.rs @@ -2,7 +2,6 @@ use std::cmp::min; use std::iter::once; use clap::Parser; -use git_version::git_version; use ratatui::layout::Rect; use ratatui::prelude::CrosstermBackend; use ratatui::{Terminal, TerminalOptions, Viewport}; @@ -11,13 +10,14 @@ use russh::keys::ssh_key::PublicKey; use russh::server::{Auth, Msg, Session}; use tracing::{debug, trace, warn}; +use crate::VERSION; use crate::io::{Input, TerminalHandle}; use crate::ldap::{Ldap, LdapError}; use crate::tunnel::{Registry, Tunnel, TunnelAccess}; /// Quickly create http tunnels for development #[derive(Parser, Debug)] -#[command(version = git_version!(), about, long_about = None)] +#[command(version = VERSION, about, long_about = None)] pub struct Args { /// Make all tunnels public by default instead of private #[arg(long, group = "access")] diff --git a/src/ssh/renderer.rs b/src/ssh/renderer.rs index 5d98db3..ff97f24 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::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"), VERSION).bold(); let title = Line::from(title).centered(); frame.render_widget(title, rect); } diff --git a/src/version.rs b/src/version.rs new file mode 100644 index 0000000..8eb59de --- /dev/null +++ b/src/version.rs @@ -0,0 +1,11 @@ +pub const VERSION: &str = get_version(); + +const fn get_version() -> &'static str { + if let Some(version) = std::option_env!("RELEASE_VERSION") + && !version.is_empty() + { + version + } else { + git_version::git_version!(fallback = "unknown") + } +}