use short commit SHA as version and mark non-release builds as dev (#295)

V3_GIT_ORIGIN_REV_ID: 78475725003cd57790361caa8659c7a7146eacf2
This commit is contained in:
Krushan Bauva 2024-01-25 14:23:24 +05:30 committed by hasura-bot
parent 761c2a3b3a
commit 4bed94b01f
7 changed files with 92 additions and 17 deletions

View File

@ -1,2 +1 @@
.git
target
target

65
v3/Cargo.lock generated
View File

@ -390,6 +390,17 @@ dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "build-data"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aed3884e2cab7c973c8fd2d150314b6a932df7fdc830edcaf1e8e7c4ae9db3c0"
dependencies = [
"chrono",
"safe-lock",
"safe-regex",
]
[[package]]
name = "bumpalo"
version = "3.14.0"
@ -939,6 +950,7 @@ dependencies = [
"axum",
"base64 0.21.5",
"bincode",
"build-data",
"clap 4.4.10",
"criterion",
"derive_more",
@ -2658,6 +2670,59 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "safe-lock"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "077d73db7973cccf63eb4aff1e5a34dc2459baa867512088269ea5f2f4253c90"
[[package]]
name = "safe-proc-macro2"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fd85be67db87168aa3c13fd0da99f48f2ab005dccad5af5626138dc1df20eb6"
dependencies = [
"unicode-ident",
]
[[package]]
name = "safe-quote"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77e530f7831f3feafcd5f1aae406ac205dd998436b4007c8e80f03eca78a88f7"
dependencies = [
"safe-proc-macro2",
]
[[package]]
name = "safe-regex"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a15289bf322e0673d52756a18194167f2378ec1a15fe884af6e2d2cb934822b0"
dependencies = [
"safe-regex-macro",
]
[[package]]
name = "safe-regex-compiler"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba76fae590a2aa665279deb1f57b5098cbace01a0c5e60e262fcf55f7c51542"
dependencies = [
"safe-proc-macro2",
"safe-quote",
]
[[package]]
name = "safe-regex-macro"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96c2e96b5c03f158d1b16ba79af515137795f4ad4e8de3f790518aae91f1d127"
dependencies = [
"safe-proc-macro2",
"safe-regex-compiler",
]
[[package]]
name = "same-file"
version = "1.0.6"

View File

@ -17,6 +17,9 @@ RUN rustup component add rustfmt
# needed for coverage reporting
RUN rustup component add llvm-tools-preview
# Building with build.rs require git context to be available across directories
ENV GIT_DISCOVERY_ACROSS_FILESYSTEM=1
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
###

View File

@ -53,6 +53,10 @@ json_value_merge = "2.0"
async-recursion= "1.0.5"
nonempty = "0.8"
# Dependencies to build and run build.rs file
[build-dependencies]
build-data = "0.1.5" # To set short commit-sha at build time
[dev-dependencies]
goldenfile = "1.4.5"
tokio-test = "0.4.2"

View File

@ -10,7 +10,7 @@ use axum::{
use clap::Parser;
use ::engine::authentication::{AuthConfig, AuthConfig::V1 as V1AuthConfig, AuthModeConfig};
use engine::schema::GDS;
use engine::{schema::GDS, VERSION};
use hasura_authn_core::Session;
use hasura_authn_jwt::auth as jwt_auth;
use hasura_authn_jwt::jwt;
@ -42,11 +42,6 @@ struct EngineState {
auth_config: AuthConfig,
}
const GIT_HASH_VERSION: &str = env!(
"GIT_HASH",
"Unable to start engine: unable to fetch the current git hash to use as trace version"
);
#[tokio::main]
async fn main() {
let server = ServerOptions::parse();
@ -167,7 +162,7 @@ async fn graphql_request_tracing_middleware<B: Send>(
tracing_util::set_attribute_on_active_span(
AttributeVisibility::Internal,
"version",
GIT_HASH_VERSION,
VERSION,
);
Box::pin(async move {
let response = next.run(request).await;

View File

@ -1,10 +1,12 @@
use std::process::Command;
fn main() {
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
// Cargo sets the PROFILE environment variable
let profile = std::env::var("PROFILE").unwrap();
if profile == "release" {
// For release builds (cargo build --release ...), set the version to the git commit short
let commit_short = build_data::get_git_commit_short().unwrap();
println!("cargo:rustc-env=CARGO_V3_ENGINE_VERSION={}", commit_short);
} else {
// For non-release builds, set the version to 'dev'
println!("cargo:rustc-env=CARGO_V3_ENGINE_VERSION=dev");
}
}

View File

@ -4,3 +4,10 @@ pub mod execute;
pub mod metadata;
pub mod schema;
pub mod utils;
// This is set by the build.rs script.
/// The version of the v3-engine release.
pub static VERSION: &str = env!(
"CARGO_V3_ENGINE_VERSION",
"Unable to start engine: unable to fetch the current git hash to use as version in traces"
);