From 125d83b3ec96bf6f87779373f759b3611deb38c3 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Thu, 26 May 2022 15:40:46 -0700 Subject: [PATCH] Fix failing seed bin build and add bin builds to ci pipeline --- .github/workflows/ci.yml | 3 ++ crates/collab/src/bin/seed.rs | 19 +++++----- crates/collab/src/lib.rs | 69 ++++++++++++++++++++++++++++++++++ crates/collab/src/main.rs | 71 +---------------------------------- 4 files changed, 84 insertions(+), 78 deletions(-) create mode 100644 crates/collab/src/lib.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e97c529faf..dc0b687170 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,9 @@ jobs: - name: Run tests run: cargo test --workspace --no-fail-fast + + - name: Build collab binaries + run: cargo build --bins --all-features bundle: name: Bundle app diff --git a/crates/collab/src/bin/seed.rs b/crates/collab/src/bin/seed.rs index ee202ee4a8..4a3dabfc71 100644 --- a/crates/collab/src/bin/seed.rs +++ b/crates/collab/src/bin/seed.rs @@ -1,4 +1,5 @@ use clap::Parser; +use collab::{Error, Result}; use db::{Db, PostgresDb, UserId}; use rand::prelude::*; use serde::Deserialize; @@ -32,12 +33,12 @@ async fn main() { .expect("failed to connect to postgres database"); let mut zed_users = vec![ - "nathansobo".to_string(), - "maxbrunsfeld".to_string(), - "as-cii".to_string(), - "iamnbutler".to_string(), - "gibusu".to_string(), - "Kethku".to_string(), + ("nathansobo".to_string(), Some("nathan@zed.dev")), + ("maxbrunsfeld".to_string(), Some("max@zed.dev")), + ("as-cii".to_string(), Some("antonio@zed.dev")), + ("iamnbutler".to_string(), Some("nate@zed.dev")), + ("gibusu".to_string(), Some("greg@zed.dev")), + ("Kethku".to_string(), Some("keith@zed.dev")), ]; if args.github_users { @@ -61,7 +62,7 @@ async fn main() { .json::>() .await .expect("failed to deserialize github user"); - zed_users.extend(users.iter().map(|user| user.login.clone())); + zed_users.extend(users.iter().map(|user| (user.login.clone(), None))); if let Some(last_user) = users.last() { last_user_id = Some(last_user.id); @@ -72,7 +73,7 @@ async fn main() { } let mut zed_user_ids = Vec::::new(); - for zed_user in zed_users { + for (zed_user, email) in zed_users { if let Some(user) = db .get_user_by_github_login(&zed_user) .await @@ -81,7 +82,7 @@ async fn main() { zed_user_ids.push(user.id); } else { zed_user_ids.push( - db.create_user(&zed_user, true) + db.create_user(&zed_user, email, true) .await .expect("failed to insert user"), ); diff --git a/crates/collab/src/lib.rs b/crates/collab/src/lib.rs new file mode 100644 index 0000000000..518530c539 --- /dev/null +++ b/crates/collab/src/lib.rs @@ -0,0 +1,69 @@ +use axum::{http::StatusCode, response::IntoResponse}; + +pub type Result = std::result::Result; + +pub enum Error { + Http(StatusCode, String), + Internal(anyhow::Error), +} + +impl From for Error { + fn from(error: anyhow::Error) -> Self { + Self::Internal(error) + } +} + +impl From for Error { + fn from(error: sqlx::Error) -> Self { + Self::Internal(error.into()) + } +} + +impl From for Error { + fn from(error: axum::Error) -> Self { + Self::Internal(error.into()) + } +} + +impl From for Error { + fn from(error: hyper::Error) -> Self { + Self::Internal(error.into()) + } +} + +impl From for Error { + fn from(error: serde_json::Error) -> Self { + Self::Internal(error.into()) + } +} + +impl IntoResponse for Error { + fn into_response(self) -> axum::response::Response { + match self { + Error::Http(code, message) => (code, message).into_response(), + Error::Internal(error) => { + (StatusCode::INTERNAL_SERVER_ERROR, format!("{}", &error)).into_response() + } + } + } +} + +impl std::fmt::Debug for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::Http(code, message) => (code, message).fmt(f), + Error::Internal(error) => error.fmt(f), + } + } +} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::Http(code, message) => write!(f, "{code}: {message}"), + Error::Internal(error) => error.fmt(f), + } + } +} + +impl std::error::Error for Error {} diff --git a/crates/collab/src/main.rs b/crates/collab/src/main.rs index 74401699ca..47f1e6173a 100644 --- a/crates/collab/src/main.rs +++ b/crates/collab/src/main.rs @@ -4,7 +4,8 @@ mod db; mod env; mod rpc; -use axum::{body::Body, http::StatusCode, response::IntoResponse, Router}; +use axum::{body::Body, Router}; +use collab::{Error, Result}; use db::{Db, PostgresDb}; use serde::Deserialize; use std::{ @@ -73,74 +74,6 @@ async fn main() -> Result<()> { Ok(()) } -pub type Result = std::result::Result; - -pub enum Error { - Http(StatusCode, String), - Internal(anyhow::Error), -} - -impl From for Error { - fn from(error: anyhow::Error) -> Self { - Self::Internal(error) - } -} - -impl From for Error { - fn from(error: sqlx::Error) -> Self { - Self::Internal(error.into()) - } -} - -impl From for Error { - fn from(error: axum::Error) -> Self { - Self::Internal(error.into()) - } -} - -impl From for Error { - fn from(error: hyper::Error) -> Self { - Self::Internal(error.into()) - } -} - -impl From for Error { - fn from(error: serde_json::Error) -> Self { - Self::Internal(error.into()) - } -} - -impl IntoResponse for Error { - fn into_response(self) -> axum::response::Response { - match self { - Error::Http(code, message) => (code, message).into_response(), - Error::Internal(error) => { - (StatusCode::INTERNAL_SERVER_ERROR, format!("{}", &error)).into_response() - } - } - } -} - -impl std::fmt::Debug for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Error::Http(code, message) => (code, message).fmt(f), - Error::Internal(error) => error.fmt(f), - } - } -} - -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Error::Http(code, message) => write!(f, "{code}: {message}"), - Error::Internal(error) => error.fmt(f), - } - } -} - -impl std::error::Error for Error {} - pub fn init_tracing(config: &Config) -> Option<()> { use opentelemetry::KeyValue; use opentelemetry_otlp::WithExportConfig;