Skip to content
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: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
sudo mariadb -e "FLUSH PRIVILEGES";

- name: Setup Rust
uses: dtolnay/rust-toolchain@1.89.0
uses: dtolnay/rust-toolchain@1.92.0

- name: Configure cache
uses: Swatinem/rust-cache@v2
Expand All @@ -50,7 +50,8 @@ jobs:
env:
DATABASE_URL: mysql://api:${{ secrets.MARIADB_PW }}@localhost:3306/master_db
REDIS_URL: redis://localhost:6379
run: RUST_BACKTRACE=1 cargo test -F mysql -F test
GQL_API_CURSOR_SECRET_KEY: ${{ secrets.GQL_API_CURSOR_SECRET_KEY }}
run: RUST_BACKTRACE=1 cargo test -F mysql

lint:
name: Lint
Expand All @@ -61,13 +62,16 @@ jobs:
uses: actions/checkout@v4

- name: Setup Rust
uses: dtolnay/rust-toolchain@1.89.0
uses: dtolnay/rust-toolchain@1.92.0

- name: Setup Clippy
run: rustup component add clippy

- name: Run clippy
run: |
cargo clippy --no-default-features -- -D warnings
cargo clippy -- -D warnings
cargo clippy --no-default-features -F mysql -- -D warnings
cargo clippy -r --no-default-features -F mysql -- -D warnings
cargo clippy -F mysql -- -D warnings
cargo clippy -r -F mysql -- -D warnings
cargo clippy --all-features -- -D warnings
cargo clippy -r --all-features -- -D warnings
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@1.89.0
uses: dtolnay/rust-toolchain@1.92.0
- name: Configure cache
uses: Swatinem/rust-cache@v2
- name: Setup pages
Expand All @@ -26,7 +26,7 @@ jobs:
- name: Clean docs folder
run: cargo clean --doc
- name: Build docs
run: cargo +nightly doc --all-features --no-deps --workspace --exclude clear_redis_mappacks --exclude admin
run: cargo +nightly doc --all-features --no-deps --workspace --exclude admin
- name: Add redirect
run: echo '<meta http-equiv="refresh" content="0;url=records_lib/index.html">' > target/doc/index.html
- name: Remove lock file
Expand Down
43 changes: 22 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,41 @@ members = [
"crates/graphql-schema-generator",
"crates/player-map-ranking",
"crates/compute-player-map-ranking",
"crates/test-env",
]

[workspace.dependencies]
thiserror = "2.0.12"
tokio = "1.44.1"
async-graphql = "7.0.15"
sqlx = { version = "0.8.3", features = ["chrono", "mysql", "runtime-tokio"] }
chrono = { version = "0.4.40", features = ["serde"] }
deadpool = { version = "0.12.2", features = ["managed", "rt_tokio_1"] }
thiserror = "2.0.17"
tokio = "1.49.0"
async-graphql = "7.1.0"
sqlx = { version = "0.8.6", features = ["chrono", "mysql", "runtime-tokio"] }
chrono = { version = "0.4.42", features = ["serde"] }
deadpool = { version = "0.12.3", features = ["managed", "rt_tokio_1"] }
deadpool-redis = { version = "0.20.0", features = ["rt_tokio_1"] }
serde = "1.0.219"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
actix-web = "4.10.2"
serde = "1.0.228"
tracing = "0.1.44"
tracing-subscriber = "0.3.22"
actix-web = "4.12.1"
actix-cors = "0.7.1"
async-graphql-actix-web = "7.0.15"
tracing-actix-web = "0.7.16"
reqwest = { version = "0.12.14", features = ["json"] }
rand = "0.9.0"
futures = "0.3.27"
async-graphql-actix-web = "7.1.0"
tracing-actix-web = "0.7.20"
reqwest = { version = "0.12.28", features = ["json"] }
rand = "0.9.2"
futures = "0.3.31"
sha256 = "1.6.0"
actix-session = { version = "0.10.1", features = ["cookie-session"] }
anyhow = "1.0.97"
anyhow = "1.0.100"
dotenvy = "0.15.7"
itertools = "0.14.0"
once_cell = "1.21.1"
csv = "1.3.0"
mkenv = "0.1.6"
once_cell = "1.21.3"
csv = "1.4.0"
mkenv = "1.0.2"
nom = "8.0.0"
pin-project-lite = "0.2.16"
sea-orm = { version = "1.1.14", features = [
sea-orm = { version = "1.1.19", features = [
"runtime-tokio",
"macros",
"with-chrono",
] }
serde_json = "1.0.143"
serde_json = "1.0.149"
prettytable = { version = "0.10.0", default-features = false }
2 changes: 1 addition & 1 deletion crates/admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"

[dependencies]
anyhow = { workspace = true }
clap = { version = "4.5.16", features = ["derive"] }
clap = { version = "4.5.54", features = ["derive"] }
csv = { workspace = true }
deadpool-redis = { workspace = true }
dotenvy = { workspace = true }
Expand Down
19 changes: 14 additions & 5 deletions crates/admin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use mkenv::Env as _;
use mkenv::prelude::*;
use records_lib::{Database, DbEnv, LibEnv};

use self::{clear::ClearCommand, leaderboard::LbCommand, populate::PopulateCommand};
Expand All @@ -24,7 +24,12 @@ enum EventCommand {
Clear(ClearCommand),
}

mkenv::make_env!(Env includes [DbEnv as db_env, LibEnv as lib_env]:);
mkenv::make_config! {
struct Env {
db_env: { DbEnv },
lib_env: { LibEnv },
}
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand All @@ -33,11 +38,15 @@ async fn main() -> anyhow::Result<()> {
.compact()
.try_init()
.map_err(|e| anyhow::anyhow!("unable to init tracing_subscriber: {e}"))?;
let env = Env::try_get()?;
let env = Env::define();
env.init();
records_lib::init_env(env.lib_env);

let db =
Database::from_db_url(env.db_env.db_url.db_url, env.db_env.redis_url.redis_url).await?;
let db = Database::from_db_url(
env.db_env.db_url.db_url.get(),
env.db_env.redis_url.redis_url.get(),
)
.await?;

let cmd = Command::parse();

Expand Down
2 changes: 1 addition & 1 deletion crates/compute-player-map-ranking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"

[dependencies]
anyhow = { workspace = true }
clap = { version = "4.5.48", features = ["derive"] }
clap = { version = "4.5.54", features = ["derive"] }
dotenvy = { workspace = true }
mkenv = { workspace = true }
player-map-ranking = { path = "../player-map-ranking" }
Expand Down
17 changes: 11 additions & 6 deletions crates/compute-player-map-ranking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ use std::{
use anyhow::Context as _;
use chrono::{DateTime, Days, Months, Utc};
use clap::Parser as _;
use mkenv::Env as _;
use mkenv::prelude::*;
use records_lib::{DbUrlEnv, time::Time};
use sea_orm::Database;

mkenv::make_env! {AppEnv includes [DbUrlEnv as db_env]:}
mkenv::make_config! {
struct AppEnv {
db_env: { DbUrlEnv },
}
}

#[derive(Clone)]
struct SinceDuration {
Expand Down Expand Up @@ -96,10 +100,11 @@ async fn main() -> anyhow::Result<()> {
})
.context("couldn't write header to map ranking file")?;

let db_url = AppEnv::try_get()
.context("couldn't initialize environment")?
.db_env
.db_url;
let app_config = AppEnv::define();
app_config
.try_init()
.map_err(|e| anyhow::anyhow!("couldn't initialize environment: {e}"))?;
let db_url = app_config.db_env.db_url.get();
let db = Database::connect(db_url)
.await
.context("couldn't connect to database")?;
Expand Down
4 changes: 3 additions & 1 deletion crates/entity/src/entities/maps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use sea_orm::entity::prelude::*;

/// A ShootMania Obstacle map in the database.
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "maps")]
pub struct Model {
/// The map ID.
Expand Down Expand Up @@ -32,6 +32,8 @@ pub struct Model {
pub gold_time: Option<i32>,
/// The author time of the map.
pub author_time: Option<i32>,
/// The score of the player, calculated periodically.
pub score: f64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
4 changes: 3 additions & 1 deletion crates/entity/src/entities/players.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use sea_orm::entity::prelude::*;

/// A player in the database.
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "players")]
pub struct Model {
/// The player ID.
Expand All @@ -20,6 +20,8 @@ pub struct Model {
pub admins_note: Option<String>,
/// The player role.
pub role: u8,
/// The score of the player, calculated periodically.
pub score: f64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
10 changes: 5 additions & 5 deletions crates/game_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
actix-web = { workspace = true }
actix-cors = { workspace = true }
actix-http = "3.11.0"
actix-http = "3.11.2"
async-graphql-actix-web = { workspace = true }
tracing-actix-web = { workspace = true }
reqwest = { workspace = true, features = ["multipart"] }
Expand All @@ -44,12 +44,12 @@ graphql-api = { path = "../graphql-api" }
serde_json = { workspace = true }

[dev-dependencies]
records-lib = { path = "../records_lib" }
test-env = { path = "../test-env" }
records-lib = { path = "../records_lib", features = ["tracing", "mock"] }

[features]
default = ["request_filter"]
request_filter = ["dep:pin-project-lite", "dep:request_filter"]
auth = []
mysql = ["records-lib/mysql"]
postgres = ["records-lib/postgres"]
test = ["records-lib/test"]
mysql = ["records-lib/mysql", "test-env/mysql"]
postgres = ["records-lib/postgres", "test-env/postgres"]
2 changes: 0 additions & 2 deletions crates/game_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ fn main() {
#[cfg(all(feature = "auth", not(test)))]
println!("cargo:rustc-cfg=auth");
println!("cargo:rustc-check-cfg=cfg(auth)");

println!("cargo:rustc-check-cfg=cfg(test_force_db_deletion)");
}
3 changes: 2 additions & 1 deletion crates/game_api/src/auth/gen_token.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use deadpool_redis::redis::AsyncCommands as _;
use mkenv::Layer as _;
use records_lib::{
RedisConnection, gen_random_str,
redis_key::{mp_token_key, web_token_key},
Expand All @@ -23,7 +24,7 @@ pub async fn gen_token_for(
let mp_key = mp_token_key(login);
let web_key = web_token_key(login);

let ex = crate::env().auth_token_ttl as _;
let ex = crate::env().auth_token_ttl.get() as _;

let mp_token_hash = digest(&*mp_token);
let web_token_hash = digest(&*web_token);
Expand Down
3 changes: 2 additions & 1 deletion crates/game_api/src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use actix_web::{
web,
};
use dsc_webhook::{FormattedRequestHead, WebhookBody, WebhookBodyEmbed, WebhookBodyEmbedField};
use mkenv::prelude::*;
use records_lib::{Database, pool::clone_dbconn};
use tracing_actix_web::{DefaultRootSpanBuilder, RequestId};

Expand Down Expand Up @@ -163,7 +164,7 @@ pub(crate) fn send_internal_err_msg_detached<E>(

tokio::task::spawn(async move {
if let Err(e) = client
.post(&crate::env().wh_report_url)
.post(crate::env().wh_report_url.get())
.json(&wh_msg)
.send()
.await
Expand Down
Loading
Loading