Skip to content

Commit

Permalink
feat: tailcall-version workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 committed May 23, 2024
1 parent a0214a3 commit 71acc1d
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 59 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ opentelemetry-otlp = { version = "0.15.0", features = [
], optional = true }
opentelemetry-system-metrics = { version = "0.1.8", optional = true }
tailcall-http-cache = {path = "tailcall-http-cache", optional = true }
tailcall-version = { path = "./tailcall-version", optional = true }


# dependencies safe for wasm:
Expand Down Expand Up @@ -197,6 +198,7 @@ cli = [
"dep:opentelemetry-system-metrics",
"dep:tailcall-tracker",
"dep:tailcall-http-cache",
"dep:tailcall-version"
]

# Feature flag to enable all default features.
Expand All @@ -219,6 +221,7 @@ members = [
"tailcall-tracker",
"tailcall-hasher",
"tailcall-http-cache",
"tailcall-version",
]

# Boost execution_spec snapshot diffing performance
Expand Down
7 changes: 2 additions & 5 deletions src/cli/command.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use clap::{Parser, Subcommand};
use strum_macros::Display;
use tailcall_version::VERSION;

use crate::core::{config, generator};

pub const VERSION: &str = match option_env!("APP_VERSION") {
Some(version) => version,
_ => "0.1.0-dev",
};
const ABOUT: &str = r"
__ _ __ ____
/ /_____ _(_) /________ _/ / /
Expand All @@ -15,7 +12,7 @@ const ABOUT: &str = r"
\__/\__,_/_/_/\___/\__,_/_/_/";

#[derive(Parser)]
#[command(name = "tailcall", author, version = VERSION, about, long_about = Some(ABOUT))]
#[command(name = "tailcall", author, version = VERSION.as_str(), about, long_about = Some(ABOUT))]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
Expand Down
1 change: 0 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod metrics;
pub mod server;
mod tc;
pub mod telemetry;
mod version;

pub mod runtime;
pub(crate) mod update_checker;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/server/playground.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::version::VERSION;
use tailcall_version::VERSION;

const UTM_MEDIUM: &str = "server";
const DEBUG_UTM_SOURCE: &str = "tailcall-debug";
Expand Down
9 changes: 4 additions & 5 deletions src/cli/update_checker.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use colored::Colorize;
use tailcall_version::VERSION;
use update_informer::{registry, Check};
use which::which;

use crate::cli::command::VERSION;

enum InstallationMethod {
Npm,
Npx,
Expand Down Expand Up @@ -37,14 +36,14 @@ fn get_installation_method() -> InstallationMethod {

pub async fn check_for_update() {
tokio::task::spawn_blocking(|| {
if VERSION.eq("0.1.0-dev") {
if VERSION.is_dev() {

Check warning on line 39 in src/cli/update_checker.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/update_checker.rs#L39

Added line #L39 was not covered by tests
// skip validation if it's not a release
return;
}

let name: &str = "tailcallhq/tailcall";

let informer = update_informer::new(registry::GitHub, name, VERSION);
let informer = update_informer::new(registry::GitHub, name, VERSION.as_str());

Check warning on line 46 in src/cli/update_checker.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/update_checker.rs#L46

Added line #L46 was not covered by tests

if let Some(latest_version) = informer.check_version().ok().flatten() {
let github_release_url =
Expand All @@ -54,7 +53,7 @@ pub async fn check_for_update() {
"{}",
format!(
"A new release of tailcall is available: {} {} {}",
VERSION.cyan(),
VERSION.as_str().cyan(),

Check warning on line 56 in src/cli/update_checker.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/update_checker.rs#L56

Added line #L56 was not covered by tests
"➜".white(),
latest_version.to_string().cyan()
)
Expand Down
42 changes: 0 additions & 42 deletions src/cli/version.rs

This file was deleted.

1 change: 1 addition & 0 deletions tailcall-tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ machineid-rs = "1.2.4"
tokio = { workspace = true }
tracing = { workspace = true }
sysinfo = "0.30.12"
tailcall-version = { path = "../tailcall-version" }
8 changes: 3 additions & 5 deletions tailcall-tracker/src/check_tracking.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::env;

use tailcall_version::VERSION;

const LONG_ENV_FILTER_VAR_NAME: &str = "TAILCALL_TRACKER";
const SHORT_ENV_FILTER_VAR_NAME: &str = "TC_TRACKER";
const VERSION: &str = match option_env!("APP_VERSION") {
Some(version) => version,
_ => "0.1.0-dev",
};

/// Checks if tracking is enabled
pub fn check_tracking() -> bool {
let is_prod = !VERSION.contains("dev");
let is_prod = !VERSION.is_dev();

Check warning on line 10 in tailcall-tracker/src/check_tracking.rs

View check run for this annotation

Codecov / codecov/patch

tailcall-tracker/src/check_tracking.rs#L10

Added line #L10 was not covered by tests
let usage_enabled = env::var(LONG_ENV_FILTER_VAR_NAME)
.or(env::var(SHORT_ENV_FILTER_VAR_NAME))
.map(|v| !v.eq_ignore_ascii_case("false"))
Expand Down
6 changes: 6 additions & 0 deletions tailcall-version/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "tailcall-version"
version = "0.1.0"
edition = "2021"

[dependencies]
42 changes: 42 additions & 0 deletions tailcall-version/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const DEFAULT_VERSION: &str = "0.1.0-dev";

pub struct Version {
version: &'static str,
}

impl Version {
pub const fn new(version: &'static str) -> Self {
Version { version }
}

Check warning on line 10 in tailcall-version/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

tailcall-version/src/lib.rs#L8-L10

Added lines #L8 - L10 were not covered by tests

pub const fn as_str(&self) -> &'static str {
self.version
}

pub fn is_dev(&self) -> bool {
self.version.contains("dev")
}
}

pub const VERSION: Version = match option_env!("APP_VERSION") {
Some(version) => Version::new(version),
None => Version::new(DEFAULT_VERSION),
};

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_default_version() {
assert_eq!(VERSION.as_str(), DEFAULT_VERSION);
assert!(VERSION.is_dev());
}

#[test]
fn test_custom_version() {
const CUSTOM_VERSION: Version = Version::new("1.0.0-release");
assert_eq!(CUSTOM_VERSION.as_str(), "1.0.0-release");
assert!(!CUSTOM_VERSION.is_dev());
}
}

0 comments on commit 71acc1d

Please sign in to comment.