Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
NewbMiao committed Jun 8, 2023
1 parent 42ac807 commit f365593
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 13 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build-rust:
strategy:
Expand All @@ -24,10 +28,23 @@ jobs:
uses: taiki-e/install-action@cargo-llvm-cov
- name: install nextest
uses: taiki-e/install-action@nextest
- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features native-tls,postgres
- uses: Swatinem/rust-cache@v1
- name: Check code format
run: cargo fmt -- --check
- name: Start dependent services
run: sh ./dependent-services-up.sh
- name: Check the package for errors
run: cargo check --all
- name: Lint rust sources
run: cargo clippy --all-targets --all-features --tests --benches -- -D warnings
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo
target
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rust-
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ oauth2 = "4.4.0"
reqwest = "0.11.18"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
sqlx = { version = "0.6.3", features = ["postgres","runtime-tokio-rustls","chrono"] }
sqlx = { version = "0.6.3", features = ["postgres","runtime-tokio-rustls","chrono", "offline"] }
tokio = { version = "1.0", features = ["full"] }
tower = { version = "0.4", features = ["util", "filter"] }
tower-http = { version = "0.4.0", features = ["cors", "trace"] }
Expand Down
3 changes: 3 additions & 0 deletions dependent-services-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
docker-compose up -d
sqlx migrate run --database-url "postgresql://axum-koans:axum-koans-sec@localhost:15432/axum-koans"
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
volumes:
- "postgresql_keycloak_data:/bitnami/postgresql"
environment:
ALLOW_EMPTY_PASSWORD: yes
ALLOW_EMPTY_PASSWORD: "yes"
POSTGRESQL_USERNAME: keycloak
POSTGRESQL_DATABASE: keycloak
POSTGRESQL_PASSWORD: keycloak-sec
Expand Down Expand Up @@ -46,7 +46,7 @@ services:
KC_DB_URL: jdbc:postgresql://keycloak_database:5432/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: keycloak-sec
KEYCLOAK_CREATE_ADMIN_USER: true
KEYCLOAK_CREATE_ADMIN_USER: "true"
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin-sec
ports:
Expand Down
82 changes: 82 additions & 0 deletions sqlx-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"db": "PostgreSQL",
"80a1e4b0af4d1342bd886c5b6a7c2ef0665e61e54c2ba1d8a7d04c95e0fc0730": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int4"
}
],
"nullable": [
false
],
"parameters": {
"Left": [
"Varchar",
"Varchar",
"Varchar",
"Varchar"
]
}
},
"query": "INSERT INTO profiles (account_id, username, email, refresh_token) VALUES ($1, $2, $3, $4) RETURNING id"
},
"d9db2b6c9db243005b52295e4037ce305bb1f0c0bd8afb9704ac33bee8dceede": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int4"
},
{
"name": "account_id",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "username",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "email",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "refresh_token",
"ordinal": 4,
"type_info": "Varchar"
},
{
"name": "created_date",
"ordinal": 5,
"type_info": "Timestamptz"
},
{
"name": "updated_date",
"ordinal": 6,
"type_info": "Timestamptz"
}
],
"nullable": [
false,
false,
false,
false,
false,
false,
true
],
"parameters": {
"Left": [
"Int4"
]
}
},
"query": "SELECT * FROM profiles WHERE id = $1"
}
}
9 changes: 9 additions & 0 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod profile;
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};

pub async fn get_db_pool(database_url: String) -> Result<Pool<Postgres>, sqlx::Error> {
PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
}
1 change: 0 additions & 1 deletion src/tables/profile.rs → src/database/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct Profile {
created_date: DateTime<Utc>,
updated_date: Option<DateTime<Utc>>,
}

impl Profile {
pub fn new(account_id: String, username: String, email: String, refresh_token: String) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::Deserialize;
use serde_json::json;
use sqlx::{Pool, Postgres};

use crate::{extensions::google_auth::GoogleAuth, tables::profile::Profile};
use crate::{database::profile::Profile, extensions::google_auth::GoogleAuth};

pub async fn auth_handler(Extension(google_auth): Extension<Arc<GoogleAuth>>) -> impl IntoResponse {
let auth_url = google_auth.auth_url().await;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod database;
pub mod extensions;
pub mod handlers;
pub mod middlewares;
pub mod tables;
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axum::{middleware, routing::get, Extension, Router};
use axum_koans::{
database::get_db_pool,
extensions::{google_auth::GoogleAuth, keycloak_auth::KeycloakAuth},
handlers::{
auth::{auth_callback_handler, auth_handler},
Expand All @@ -8,7 +9,6 @@ use axum_koans::{
middlewares::log,
};
use dotenvy::{self, dotenv};
use sqlx::postgres::PgPoolOptions;
use std::{env, net::SocketAddr, sync::Arc};
use tower::ServiceBuilder;
use tower_http::trace::{self, TraceLayer};
Expand Down Expand Up @@ -36,11 +36,7 @@ async fn main() {
env::var("DATABASE_URL").expect("Missing the DATABASE_URL environment variable.");

// db pool
let db_pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
.unwrap();
let db_pool = get_db_pool(database_url).await.unwrap();
// Start configuring a `fmt` subscriber
let subscriber = tracing_subscriber::fmt()
.compact()
Expand Down
1 change: 0 additions & 1 deletion src/tables/mod.rs

This file was deleted.

0 comments on commit f365593

Please sign in to comment.