Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(friendshipper): allow manually typing in a commit #383

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
14 changes: 14 additions & 0 deletions core/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ impl ArtifactStorage {
}
}

pub async fn get_artifact_for_commit(
&self,
artifact_config: ArtifactConfig,
commit: &str,
) -> Result<ArtifactEntry, CoreError> {
let artifact_list = self.artifact_list(artifact_config).await;
let artifact_entry = artifact_list
.entries
.iter()
.find(|entry| entry.commit == Some(commit.to_string()))
.ok_or(anyhow!("Artifact not found for commit {}", commit))?;
Ok(artifact_entry.clone())
}

fn resolve_path(&self, artifact_config: &ArtifactConfig) -> String {
match &self.schema_version {
StorageSchemaVersion::V1 => Self::resolve_path_v1(artifact_config),
Expand Down
51 changes: 50 additions & 1 deletion friendshipper/src-tauri/src/builds/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::routing::{get, post};
use axum::{Json, Router};
use chrono::{DateTime, Local, Utc};
use ethos_core::storage::{
ArtifactBuildConfig, ArtifactConfig, ArtifactKind, ArtifactList, Platform,
ArtifactBuildConfig, ArtifactConfig, ArtifactEntry, ArtifactKind, ArtifactList, Platform,
};
use ethos_core::utils::junit::JunitOutput;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time;
Expand Down Expand Up @@ -36,6 +36,7 @@ where
{
Router::new()
.route("/", get(get_builds))
.route("/commit", get(get_build))
.route("/client/sync", post(sync_client))
.route("/client/wipe", post(wipe_client_data))
.route("/longtail/reset", post(reset_longtail))
Expand All @@ -46,6 +47,54 @@ where
.route("/workflows/stop", post(stop_workflow))
}

#[derive(Default, Deserialize)]
struct GetBuildParams {
commit: String,
project: Option<String>,
}

async fn get_build<T>(
State(state): State<AppState<T>>,
params: Query<GetBuildParams>,
) -> Result<Json<ArtifactEntry>, CoreError>
where
T: EngineProvider,
{
let aws_client = ensure_aws_client(state.aws_client.read().await.clone())?;
aws_client.check_expiration().await?;

let project_param = params.project.clone();

let project = if let Some(project) = project_param {
project
} else {
state
.app_config
.read()
.clone()
.selected_artifact_project
.context("Project not configured. Repo may still be initializing.")?
};

let storage = state
.storage
.read()
.clone()
.context("Storage not configured. AWS may still be initializing.")?;

let artifact_config = ArtifactConfig::new(
project.as_str().into(),
ArtifactKind::Client,
ArtifactBuildConfig::Development,
Platform::Win64,
);

let artifact_entry = storage
.get_artifact_for_commit(artifact_config, &params.commit)
.await?;
Ok(Json(artifact_entry))
}

#[derive(Default, Deserialize)]
struct GetBuildsParams {
#[serde(default = "get_default_limit")]
Expand Down
38 changes: 37 additions & 1 deletion friendshipper/src-tauri/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ethos_core::utils::junit::JunitOutput;
use tracing::error;

use ethos_core::storage::ArtifactList;
use ethos_core::storage::{ArtifactEntry, ArtifactList};
use ethos_core::tauri::command::{check_error, restart};
use ethos_core::tauri::error::TauriError;
use ethos_core::tauri::State;
Expand Down Expand Up @@ -92,6 +92,42 @@ pub async fn get_project_config(
}

// Commits
#[tauri::command]
pub async fn get_build(
state: tauri::State<'_, State>,
commit: String,
project: Option<String>,
) -> Result<ArtifactEntry, TauriError> {
let mut req = state.client.get(format!(
"{}/builds/commit?commit={}",
state.server_url, commit
));

if let Some(project) = project {
req = req.query(&[("project", project)]);
}

match req.send().await {
Ok(res) => {
if is_error_status(res.status()) {
Err(create_tauri_error(res).await)
} else {
match res.json::<ArtifactEntry>().await {
Ok(res) => Ok(res),
Err(err) => Err(TauriError {
message: err.to_string(),
status_code: 0,
}),
}
}
}
Err(err) => Err(TauriError {
message: err.to_string(),
status_code: 0,
}),
}
}

#[tauri::command]
pub async fn get_builds(
state: tauri::State<'_, State>,
Expand Down
1 change: 1 addition & 0 deletions friendshipper/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fn main() -> Result<(), CoreError> {
delete_snapshot,
download_server_logs,
fix_rebase,
get_build,
get_builds,
get_commits,
get_dynamic_config,
Expand Down
6 changes: 5 additions & 1 deletion friendshipper/src/lib/builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import type {
GetWorkflowsResponse,
ArtifactListResponse,
SyncClientRequest,
JunitOutput
JunitOutput,
ArtifactEntry
} from '$lib/types';

export const getBuild = async (commit: string, project?: string): Promise<ArtifactEntry> =>
invoke('get_build', { commit, project });

export const getBuilds = async (limit?: number, project?: string): Promise<ArtifactListResponse> =>
invoke('get_builds', { limit, project });

Expand Down
13 changes: 11 additions & 2 deletions friendshipper/src/lib/components/home/ContributorLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
repoStatus
} from '$lib/stores';
import { getPlaytestGroupForUser, getPlaytests } from '$lib/playtests';
import { getBuilds, syncClient } from '$lib/builds';
import { getBuild, getBuilds, syncClient } from '$lib/builds';
import { getServers } from '$lib/gameServers';
import UnrealEngineLogoNoCircle from '$lib/icons/UnrealEngineLogoNoCircle.svelte';
import { handleError } from '$lib/utils';
Expand Down Expand Up @@ -193,10 +193,19 @@
const playtestAssignment = getPlaytestGroupForUser(playtest, $appConfig.userDisplayName);
if (playtestAssignment && playtestAssignment.serverRef) {
const project = playtest.metadata.annotations['believer.dev/project'];
const entry = await getBuilds(250, project).then((a) =>
let entry = await getBuilds(250, project).then((a) =>
a.entries.find((b) => b.commit === playtest.spec.version)
);

if (!entry) {
entry = await getBuild(playtest.spec.version, project);

if (!entry) {
await emit('error', 'No build found for playtest');
return;
}
}

const updatedServers = await getServers(playtest.spec.version);
const playtestServer = updatedServers.find(
(s) => s.name === playtestAssignment.serverRef?.name
Expand Down
13 changes: 11 additions & 2 deletions friendshipper/src/lib/components/home/PlaytestLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
TauriError
} from '$lib/types';
import { getServers, launchServer, openLogsFolder } from '$lib/gameServers';
import { syncClient, getBuilds } from '$lib/builds';
import { syncClient, getBuilds, getBuild } from '$lib/builds';
import ServerModal from '$lib/components/servers/ServerModal.svelte';
import { getPlaytestGroupForUser } from '$lib/playtests';
import ServerTable from '$lib/components/servers/ServerTable.svelte';
Expand Down Expand Up @@ -191,12 +191,21 @@
const playtestAssignment = getPlaytestGroupForUser(nextPlaytest, $appConfig.userDisplayName);
if (playtestAssignment && playtestAssignment.serverRef) {
const project = nextPlaytest.metadata.annotations?.['believer.dev/project'];
const entry = project
let entry = project
? await getBuilds(250, project).then((a) =>
a.entries.find((b) => b.commit === nextPlaytest.spec.version)
)
: null;

if (!entry) {
entry = await getBuild(nextPlaytest.spec.version, project);

if (!entry) {
await emit('error', 'No build found for playtest');
return;
}
}

if (entry !== selected) {
const updatedServers = await getServers(nextPlaytest?.spec.version);
const playtestServer = updatedServers.find(
Expand Down
13 changes: 11 additions & 2 deletions friendshipper/src/lib/components/playtests/PlaytestCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
playtests
} from '$lib/stores';
import { openUrl, handleError } from '$lib/utils';
import { getBuilds, syncClient } from '$lib/builds';
import { getBuild, getBuilds, syncClient } from '$lib/builds';
import { getServers } from '$lib/gameServers';

export let playtest: Playtest;
Expand Down Expand Up @@ -143,10 +143,19 @@
try {
if (playtest.metadata.annotations) {
const project = playtest.metadata.annotations['believer.dev/project'];
const entry = await getBuilds(250, project).then((a) =>
let entry = await getBuilds(250, project).then((a) =>
a.entries.find((b) => b.commit === playtest.spec.version)
);

if (!entry) {
entry = await getBuild(playtest.spec.version, project);

if (!entry) {
await emit('error', 'No build found for playtest');
return;
}
}

const playtestAssignment = getPlaytestGroupForUser(playtest, $appConfig.userDisplayName);
if (playtestAssignment && playtestAssignment.serverRef) {
const updatedServers = await getServers(playtest.spec.version);
Expand Down
Loading
Loading