Read crate version from cargo.toml (fixes #4583) (#4584)

This commit is contained in:
Nutomic 2024-04-02 17:19:51 +02:00 committed by GitHub
parent 007e9b7aab
commit ae9f82b452
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 12 additions and 20 deletions

View file

@ -15,7 +15,7 @@ use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView};
use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::{
error::{LemmyError, LemmyErrorType},
version,
VERSION,
};
#[tracing::instrument(skip(context))]
@ -68,7 +68,7 @@ pub async fn leave_admin(
Ok(Json(GetSiteResponse {
site_view,
admins,
version: version::VERSION.to_string(),
version: VERSION.to_string(),
my_user: None,
all_languages,
discussion_languages,

View file

@ -19,8 +19,8 @@ use lemmy_utils::{
error::{LemmyError, LemmyErrorType},
settings::structs::{PictrsImageMode, Settings},
spawn_try_task,
version::VERSION,
REQWEST_TIMEOUT,
VERSION,
};
use mime::Mime;
use reqwest::{header::CONTENT_TYPE, Client, ClientBuilder};
@ -32,11 +32,7 @@ use urlencoding::encode;
use webpage::HTML;
pub fn client_builder(settings: &Settings) -> ClientBuilder {
let user_agent = format!(
"Lemmy/{}; +{}",
VERSION,
settings.get_protocol_and_hostname()
);
let user_agent = format!("Lemmy/{VERSION}; +{}", settings.get_protocol_and_hostname());
Client::builder()
.user_agent(user_agent.clone())

View file

@ -20,7 +20,7 @@ use lemmy_db_views_actor::structs::{
};
use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
version,
VERSION,
};
use moka::future::Cache;
use once_cell::sync::Lazy;
@ -52,7 +52,7 @@ pub async fn get_site(
Ok(GetSiteResponse {
site_view,
admins,
version: version::VERSION.to_string(),
version: VERSION.to_string(),
my_user: None,
all_languages,
discussion_languages,

View file

@ -6,7 +6,7 @@ use lemmy_db_views::structs::SiteView;
use lemmy_utils::{
cache_header::{cache_1hour, cache_3days},
error::LemmyError,
version,
VERSION,
};
use serde::{Deserialize, Serialize};
use url::Url;
@ -56,7 +56,7 @@ async fn node_info(context: web::Data<LemmyContext>) -> Result<HttpResponse, Err
version: Some("2.0".to_string()),
software: Some(NodeInfoSoftware {
name: Some("lemmy".to_string()),
version: Some(version::VERSION.to_string()),
version: Some(VERSION.to_string()),
}),
protocols,
usage: Some(NodeInfoUsage {

View file

@ -10,7 +10,6 @@ cfg_if! {
pub mod response;
pub mod settings;
pub mod utils;
pub mod version;
}
}
@ -20,6 +19,8 @@ use std::time::Duration;
pub type ConnectionId = usize;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
#[macro_export]

View file

@ -1 +0,0 @@
pub const VERSION: &str = "unknown version";

View file

@ -28,7 +28,6 @@ COPY . ./
# Debug build
RUN --mount=type=cache,target=/lemmy/target set -ex; \
if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
cargo build --features "${CARGO_BUILD_FEATURES}"; \
mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \
fi
@ -36,7 +35,6 @@ RUN --mount=type=cache,target=/lemmy/target set -ex; \
# Release build
RUN --mount=type=cache,target=/lemmy/target set -ex; \
if [ "${RUST_RELEASE_MODE}" = "release" ]; then \
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
[ -z "$USE_RELEASE_CACHE" ] && cargo clean --release; \
cargo build --features "${CARGO_BUILD_FEATURES}" --release; \
mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \
@ -63,7 +61,6 @@ ENV RUST_RELEASE_MODE=${RUST_RELEASE_MODE} \
# Debug build
RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \
if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
cargo build --features "${CARGO_BUILD_FEATURES}"; \
mv "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server; \
fi
@ -71,7 +68,6 @@ RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \
# Release build
RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \
if [ "${RUST_RELEASE_MODE}" = "release" ]; then \
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
[ -z "$USE_RELEASE_CACHE" ] && cargo clean --release; \
cargo build --features "${CARGO_BUILD_FEATURES}" --release; \
mv "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server; \

View file

@ -49,7 +49,7 @@ use lemmy_utils::{
rate_limit::RateLimitCell,
response::jsonify_plain_text_errors,
settings::{structs::Settings, SETTINGS},
version,
VERSION,
};
use prometheus::default_registry;
use prometheus_metrics::serve_prometheus;
@ -109,7 +109,7 @@ pub struct CmdArgs {
/// Placing the main function in lib.rs allows other crates to import it and embed Lemmy
pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> {
// Print version number to log
println!("Lemmy v{}", version::VERSION);
println!("Lemmy v{VERSION}");
// return error 503 while running db migrations and startup tasks
let mut startup_server_handle = None;