Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 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 @@ -41,6 +41,9 @@ toml = "0.8"
# Error Handling
anyhow = "1.0"

# Regex
regex = "1.10"

# Progress & UI
indicatif = "0.17"

Expand Down
48 changes: 29 additions & 19 deletions src/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,40 @@ struct TempCredsResponse {
}

async fn get_temp_credentials(
org_slug: &str,
game_slug: &str,
branch_slug: &str,
org: &str,
game: &str,
environment: &str,
engine: &str,
engine_version: &str,
build_version: &str,
entrypoint: Option<&str>,
build_message: Option<&str>,
api_key: &str,
) -> Result<TempCredsResponse> {
let client = config::create_http_client()?;
let api_host = config::get("api_host")?;

let url = format!(
"{}/api/organizations/{}/games/{}/branches/{}/builds/create-temp-r2-creds",
api_host, org_slug, game_slug, branch_slug
"{}/api/organizations/{}/games/{}/environments/{}/builds/create-temp-r2-creds",
api_host, org, game, environment
);

let mut request_body = serde_json::json!({
"engine": engine,
"engineVersion": engine_version
"engineVersion": engine_version,
"version": build_version
});

// Add entrypoint if provided
if let Some(ep) = entrypoint {
request_body["entrypoint"] = serde_json::json!(ep);
}

// Add build message if provided
if let Some(msg) = build_message {
request_body["buildMessage"] = serde_json::json!(msg);
}

let response = client
.post(&url)
.header("Authorization", format!("Bearer {}", api_key))
Expand Down Expand Up @@ -101,18 +109,18 @@ async fn get_temp_credentials(
}

async fn notify_upload_complete(
org_slug: &str,
game_slug: &str,
branch_slug: &str,
org: &str,
game: &str,
environment: &str,
build_id: &str,
api_key: &str,
) -> Result<()> {
let client = config::create_http_client()?;
let api_host = config::get("api_host")?;

let url = format!(
"{}/api/organizations/{}/games/{}/branches/{}/builds/{}/upload-completed",
api_host, org_slug, game_slug, branch_slug, build_id
"{}/api/organizations/{}/games/{}/environments/{}/builds/{}/upload-completed",
api_host, org, game, environment, build_id
);

let response = client
Expand Down Expand Up @@ -140,7 +148,7 @@ async fn notify_upload_complete(
Ok(())
}

pub async fn handle_build_push(config_path: PathBuf, verbose: bool) -> Result<()> {
pub async fn handle_build_push(config_path: PathBuf, message: Option<String>, verbose: bool) -> Result<()> {
// Load wavedash.toml config
let wavedash_config = WavedashConfig::load(&config_path)?;

Expand All @@ -167,12 +175,14 @@ pub async fn handle_build_push(config_path: PathBuf, verbose: bool) -> Result<()
// Get temporary R2 credentials
let engine_kind = wavedash_config.engine_type()?;
let creds = get_temp_credentials(
&wavedash_config.org_slug,
&wavedash_config.game_slug,
&wavedash_config.branch_slug,
&wavedash_config.org,
&wavedash_config.game,
wavedash_config.environment.as_str(),
engine_kind.as_config_key(),
wavedash_config.version()?,
wavedash_config.engine_version()?,
wavedash_config.get_build_version(),
wavedash_config.entrypoint(),
message.as_deref(),
&api_key,
)
.await?;
Expand All @@ -199,9 +209,9 @@ pub async fn handle_build_push(config_path: PathBuf, verbose: bool) -> Result<()

// Notify the server that upload is complete
notify_upload_complete(
&wavedash_config.org_slug,
&wavedash_config.game_slug,
&wavedash_config.branch_slug,
&wavedash_config.org,
&wavedash_config.game,
wavedash_config.environment.as_str(),
&creds.game_build_id,
&api_key,
)
Expand Down
61 changes: 57 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use directories::BaseDirs;
use regex::Regex;
use serde::Deserialize;
use std::path::PathBuf;

Expand Down Expand Up @@ -102,11 +103,48 @@ pub struct CustomSection {
pub entrypoint: String,
}

/// The cloud environment for the game build
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Environment {
Production,
Demo,
Sandbox,
}

impl Environment {
pub fn as_str(&self) -> &'static str {
match self {
Environment::Production => "production",
Environment::Demo => "demo",
Environment::Sandbox => "sandbox",
}
}
}

impl std::fmt::Display for Environment {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}

#[derive(Debug, Deserialize)]
pub struct WavedashConfig {
pub org_slug: String,
pub game_slug: String,
pub branch_slug: String,
/// Organization slug
pub org: String,

/// Game slug
pub game: String,

/// Environment: production, demo, or sandbox
pub environment: Environment,

/// Build version in semantic versioning format (major.minor.patch)
/// Example: "1.0.0", "2.1.3"
/// Required - must match a release version to be selectable
#[serde(rename = "version")]
pub build_version: String,

pub upload_dir: PathBuf,

#[serde(rename = "godot")]
Expand Down Expand Up @@ -157,6 +195,15 @@ impl WavedashConfig {
let config: WavedashConfig = toml::from_str(&config_content)
.map_err(|e| anyhow::anyhow!("Failed to parse config file: {}", e))?;

// Validate build_version format (required, must be semver)
let semver_regex = Regex::new(r"^\d+\.\d+\.\d+$").unwrap();
if !semver_regex.is_match(&config.build_version) {
anyhow::bail!(
"Invalid version '{}'. Must be in semantic version format: major.minor.patch (e.g., 1.0.0, 2.1.3)",
config.build_version
);
}

Ok(config)
}

Expand All @@ -175,7 +222,8 @@ impl WavedashConfig {
}
}

pub fn version(&self) -> Result<&str> {
/// Get the engine version (e.g., Godot version, Unity version)
pub fn engine_version(&self) -> Result<&str> {
if let Some(ref godot) = self.godot {
Ok(&godot.version)
} else if let Some(ref unity) = self.unity {
Expand All @@ -187,6 +235,11 @@ impl WavedashConfig {
}
}

/// Get the build version (semantic version: major.minor.patch)
pub fn get_build_version(&self) -> &str {
&self.build_version
}

pub fn entrypoint(&self) -> Option<&str> {
self.custom.as_ref().map(|c| c.entrypoint.as_str())
}
Expand Down
2 changes: 1 addition & 1 deletion src/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub async fn handle_dev(config_path: Option<PathBuf>, verbose: bool, no_open: bo
let sandbox_url = build_sandbox_url(
&wavedash_config,
engine_label,
wavedash_config.version()?,
wavedash_config.engine_version()?,
&local_origin,
entrypoint.as_deref(),
entrypoint_params.as_ref(),
Expand Down
10 changes: 5 additions & 5 deletions src/dev/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ pub fn build_sandbox_url(
let base = host.trim_end_matches('/');

// First, build the game URL (what will be the rdurl parameter)
let game_url_full = format!("{}/play/{}", base, wavedash_config.game_slug);
let game_url_full = format!("{}/play/{}", base, wavedash_config.game);
let mut game_url = Url::parse(&game_url_full)
.with_context(|| format!("Unable to parse website host {}", game_url_full))?;

{
let mut pairs = game_url.query_pairs_mut();
pairs.append_pair(UrlParams::GAME_SUBDOMAIN, &wavedash_config.game_slug);
pairs.append_pair(UrlParams::GAME_BRANCH_SLUG, &wavedash_config.branch_slug);
pairs.append_pair(UrlParams::GAME_CLOUD_ID, &wavedash_config.org_slug);
pairs.append_pair(UrlParams::GAME_SUBDOMAIN, &wavedash_config.game);
pairs.append_pair(UrlParams::GAME_ENVIRONMENT, wavedash_config.environment.as_str());
pairs.append_pair(UrlParams::GAME_CLOUD_ID, &wavedash_config.org);
pairs.append_pair(UrlParams::LOCAL_ORIGIN, local_origin);
pairs.append_pair(UrlParams::SANDBOX, "true");
pairs.append_pair(UrlParams::ENGINE, engine_label);
Expand All @@ -47,7 +47,7 @@ pub fn build_sandbox_url(
let host_url = Url::parse(&format!("https://{}", base.trim_start_matches("https://").trim_start_matches("http://")))?;
let main_host = host_url.host_str().ok_or_else(|| anyhow::anyhow!("Could not extract host"))?;

let subdomain = format!("{}.sandbox.{}", wavedash_config.game_slug, main_host);
let subdomain = format!("{}.sandbox.{}", wavedash_config.game, main_host);
let permission_grant_url = format!("https://{}/sandbox/permission-grant", subdomain);

let mut url = Url::parse(&permission_grant_url)?;
Expand Down
2 changes: 1 addition & 1 deletion src/dev/url_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub struct UrlParams;

impl UrlParams {
pub const GAME_SUBDOMAIN: &'static str = "gsdomain";
pub const GAME_BRANCH_SLUG: &'static str = "gbrslug";
pub const GAME_ENVIRONMENT: &'static str = "genv";
pub const GAME_CLOUD_ID: &'static str = "gcid";
pub const SANDBOX: &'static str = "sandbox";
pub const LOCAL_ORIGIN: &'static str = "localorigin";
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ enum BuildCommands {
default_value = "./wavedash.toml"
)]
config: PathBuf,
#[arg(short = 'm', long = "message", help = "Build message (like a commit message)")]
message: Option<String>,
},
}

Expand Down Expand Up @@ -144,8 +146,8 @@ async fn main() -> Result<()> {
}
}
Commands::Build { action } => match action {
BuildCommands::Push { config } => {
handle_build_push(config, cli.verbose).await?;
BuildCommands::Push { config, message } => {
handle_build_push(config, message, cli.verbose).await?;
}
},
Commands::Dev { config, no_open } => {
Expand Down