Skip to content

Commit

Permalink
fix: added utm source & medium on playground url (#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 authored May 25, 2024
1 parent df60a01 commit 24c85d2
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 17 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
7 changes: 5 additions & 2 deletions src/cli/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
pub mod http_1;
pub mod http_2;
pub mod http_server;
pub mod playground;
pub mod server_config;

pub use http_server::Server;

use self::server_config::ServerConfig;

const GRAPHQL_SLUG: &str = "/graphql";

fn log_launch(sc: &ServerConfig) {
let addr = sc.addr().to_string();
tracing::info!(
Expand All @@ -15,7 +18,7 @@ fn log_launch(sc: &ServerConfig) {
sc.http_version()
);

let url = sc.graphiql_url();
let url = format!("https://tailcall.run/playground/?u={}/graphql", url);
let graphiql_url = sc.graphiql_url() + GRAPHQL_SLUG;
let url = playground::build_url(&graphiql_url);
tracing::info!("🌍 Playground: {}", url);
}
19 changes: 19 additions & 0 deletions src/cli/server/playground.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use tailcall_version::VERSION;

const UTM_MEDIUM: &str = "server";
const DEBUG_UTM_SOURCE: &str = "tailcall-debug";
const RELEASE_UTM_SOURCE: &str = "tailcall-release";
const BASE_PLAYGROUND_URL: &str = "https://tailcall.run/playground/";

pub fn build_url(graphiql_url: &str) -> String {
let utm_source = if VERSION.is_dev() {
DEBUG_UTM_SOURCE
} else {
RELEASE_UTM_SOURCE
};

format!(
"{}?u={}&utm_source={}&utm_medium={}",
BASE_PLAYGROUND_URL, graphiql_url, utm_source, UTM_MEDIUM
)
}
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() {
// 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());

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(),
"➜".white(),
latest_version.to_string().cyan()
)
Expand Down
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();
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 }
}

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 24c85d2

Please sign in to comment.