Fix failing seed bin build and add bin builds to ci pipeline

This commit is contained in:
Keith Simmons 2022-05-26 15:40:46 -07:00
parent f4d13ef596
commit 125d83b3ec
4 changed files with 84 additions and 78 deletions

View file

@ -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

View file

@ -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::<Vec<GitHubUser>>()
.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::<UserId>::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"),
);

69
crates/collab/src/lib.rs Normal file
View file

@ -0,0 +1,69 @@
use axum::{http::StatusCode, response::IntoResponse};
pub type Result<T, E = Error> = std::result::Result<T, E>;
pub enum Error {
Http(StatusCode, String),
Internal(anyhow::Error),
}
impl From<anyhow::Error> for Error {
fn from(error: anyhow::Error) -> Self {
Self::Internal(error)
}
}
impl From<sqlx::Error> for Error {
fn from(error: sqlx::Error) -> Self {
Self::Internal(error.into())
}
}
impl From<axum::Error> for Error {
fn from(error: axum::Error) -> Self {
Self::Internal(error.into())
}
}
impl From<hyper::Error> for Error {
fn from(error: hyper::Error) -> Self {
Self::Internal(error.into())
}
}
impl From<serde_json::Error> 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 {}

View file

@ -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<T, E = Error> = std::result::Result<T, E>;
pub enum Error {
Http(StatusCode, String),
Internal(anyhow::Error),
}
impl From<anyhow::Error> for Error {
fn from(error: anyhow::Error) -> Self {
Self::Internal(error)
}
}
impl From<sqlx::Error> for Error {
fn from(error: sqlx::Error) -> Self {
Self::Internal(error.into())
}
}
impl From<axum::Error> for Error {
fn from(error: axum::Error) -> Self {
Self::Internal(error.into())
}
}
impl From<hyper::Error> for Error {
fn from(error: hyper::Error) -> Self {
Self::Internal(error.into())
}
}
impl From<serde_json::Error> 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;