From 1c920fb87eed7bdfe71d00abddecd604fb9702a7 Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 11:10:52 -0800 Subject: [PATCH 01/11] adding build CI for user udpater Signed-off-by: danbugs --- .github/workflows/build.yml | 42 +++++++++++++++++++++ Cargo.lock | 73 ++++++++++++++++++++++--------------- Dockerfile-UserUpdater | 3 ++ Makefile | 8 +++- README.md | 10 +++++ frontend/src/main.rs | 16 ++++---- lib/src/player.rs | 12 ++++-- startgg_api/src/lib.rs | 4 +- 8 files changed, 123 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile-UserUpdater diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2a293b5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,42 @@ +name: Build + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: macos-latest + target: x86_64-apple-darwin + - os: windows-latest + target: x86_64-pc-windows-msvc + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + target: ${{ matrix.target }} + + - name: Build + run: cargo build --release --target ${{ matrix.target }} + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: my-binary-${{ matrix.target }} + path: target/${{ matrix.target }}/release/my-binary diff --git a/Cargo.lock b/Cargo.lock index 4fc63de..df55fc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,6 +158,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "block-buffer" version = "0.10.3" @@ -237,7 +243,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", "indexmap", @@ -402,7 +408,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841ef46f4787d9097405cac4e70fb8644fc037b526e8c14054247c0263c400d0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "proc-macro2", "proc-macro2-diagnostics", "quote", @@ -426,7 +432,7 @@ version = "1.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b28135ecf6b7d446b43e27e225622a038cc4e2930a1022f51cdb97ada19b8e4d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "byteorder", "diesel_derives", "pq-sys", @@ -774,9 +780,9 @@ dependencies = [ [[package]] name = "gql_client" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ad0b978ded703acd23762f99e0f701450c9d0066912c0d7f9bf65bf017d87d" +checksum = "e57f4862d3e5cd4ffe8df03fa2137e620e33578bbc1895e6f8f569630e17b1db" dependencies = [ "log", "reqwest", @@ -1078,7 +1084,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1103,9 +1109,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", @@ -1126,7 +1132,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" dependencies = [ "autocfg", - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", ] @@ -1164,11 +1170,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" dependencies = [ - "bitflags", + "bitflags 2.4.1", "cfg-if", "foreign-types", "libc", @@ -1196,11 +1202,10 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" dependencies = [ - "autocfg", "cc", "libc", "pkg-config", @@ -1233,7 +1238,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1299,9 +1304,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "polyval" @@ -1421,7 +1426,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1627,12 +1632,11 @@ checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "lazy_static", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1655,11 +1659,11 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.7.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +checksum = "7c4437699b6d34972de58652c68b98cb5b53a4199ab126db8e20ec8ded29a721" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -1668,9 +1672,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys", "libc", @@ -2046,9 +2050,9 @@ dependencies = [ [[package]] name = "tokio-native-tls" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ "native-tls", "tokio", @@ -2461,6 +2465,15 @@ dependencies = [ "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/Dockerfile-UserUpdater b/Dockerfile-UserUpdater new file mode 100644 index 0000000..181d3dc --- /dev/null +++ b/Dockerfile-UserUpdater @@ -0,0 +1,3 @@ +FROM debian:buster-slim +COPY target/x86_64-unknown-linux-gnu/release/pidgtm /usr/local/bin/pidgtm +ENTRYPOINT ["pidgtm"] diff --git a/Makefile b/Makefile index 4176077..e63bd69 100644 --- a/Makefile +++ b/Makefile @@ -19,14 +19,18 @@ build: # INSTALL .PHONY: install install: - install target/release/smithe $(INSTALL_DIR)/bin - install target/release/pidgtm $(INSTALL_DIR)/bin + cargo install --path . # PIDGTM .PHONY: pidgtm pidgtm-map: $(PIDGTM) map +.PHONY: pidgtm-user-updater +pidgtm-user-updater: + cargo build --release --bin pidgtm --target x86_64-unknown-linux-gnu + docker build -t pidgtm-user-updater -f Dockerfile-UserUpdater . + # BACKEND .PHONY: build-backend build-backend: diff --git a/README.md b/README.md index 0a738bd..92df61b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,16 @@ Smithereens is not yet available as a website, only as a command-line tool. With Currently, the only way to get Smithereens on your computer is to build it from source. To do so, you need to have the Rust toolchain installed on your machine. To install it, follow instructions [here](https://www.rust-lang.org/tools/install). +> Note: +>> Aside from the Rust toolchain, you will also need: +>> - Postgres, +>> - Diesel, and +>> - Trunk. +> +>> Plus, you need the following Rust targets: +>> - wasm32-unknown-unknown, and +>> - x86_64-unknown-linux-gnu + After that, inside of Smithereens' repository root, run: `cargo build --release`. With that, you'll have Smithereens' binary (i.e., `smithe`) built under `target/release`. You can run it, like: `./target/release/smithe`. After that, feel free to move the binary to a more convenient place on your machine (i.e., perhaps to a place included in your `PATH`, so you can run it simply with `smithe`). > Note: In the future, there will be releases for `smithe`, so this process will be better streamlined. \ No newline at end of file diff --git a/frontend/src/main.rs b/frontend/src/main.rs index ebda366..1c94cc6 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -58,7 +58,7 @@ impl Component for App { let link = ctx.link().clone(); wasm_bindgen_futures::spawn_local(async move { - let endpoint = format!("{}/players/{}", env!("SERVER_ADDRESS"), value); + let endpoint = format!("{}/players/{}", std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), value); let fetched_players: Vec = Request::get(&endpoint) .send() .await @@ -94,7 +94,7 @@ impl Component for App { let link = ctx.link().clone(); wasm_bindgen_futures::spawn_local(async move { - let fetched_tournaments: Vec = Request::get(&format!("{}/tournaments/{}", env!("SERVER_ADDRESS"), pid)) + let fetched_tournaments: Vec = Request::get(&format!("{}/tournaments/{}", std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), pid)) .send() .await .unwrap() @@ -102,7 +102,7 @@ impl Component for App { .await .unwrap(); - let fetched_sets: Vec = Request::get(&format!("{}/sets/{}", env!("SERVER_ADDRESS"), pid)) + let fetched_sets: Vec = Request::get(&format!("{}/sets/{}", std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), pid)) .send() .await .unwrap() @@ -127,7 +127,7 @@ impl Component for App { let link = ctx.link().clone(); wasm_bindgen_futures::spawn_local(async move { let fetch_winrate: String = - Request::get(&format!("{}/sets/{}/winrate", env!("SERVER_ADDRESS"), pid)) + Request::get(&format!("{}/sets/{}/winrate", std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), pid)) .send() .await .unwrap() @@ -137,7 +137,7 @@ impl Component for App { let fetch_competitor_type: String = Request::get(&format!( "{}/sets/{}/competitor_type", - env!("SERVER_ADDRESS"), + std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), pid )) .send() @@ -149,7 +149,7 @@ impl Component for App { let fetch_wins_without_dqs: String = Request::get(&format!( "{}/sets/{}/wins_without_dqs", - env!("SERVER_ADDRESS"), + std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), pid )) .send() @@ -161,7 +161,7 @@ impl Component for App { let fetch_losses_without_dqs: String = Request::get(&format!( "{}/sets/{}/losses_without_dqs", - env!("SERVER_ADDRESS"), + std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), pid )) .send() @@ -173,7 +173,7 @@ impl Component for App { let fetch_top_two_characters: String = Request::get(&format!( "{}/player/{}/top_two_characters", - env!("SERVER_ADDRESS"), + std::env::var("SERVER_ADDRESS").expect("could not find SERVER_ADDRESS env var"), pid )) .send() diff --git a/lib/src/player.rs b/lib/src/player.rs index cee2d73..ffb56ee 100644 --- a/lib/src/player.rs +++ b/lib/src/player.rs @@ -54,9 +54,15 @@ pub fn get_last_cached_player_id() -> Result { if let Some(val) = max_checked_player_id { Ok(val) } else { - Ok(1) - // ^^^ don't start at 0 because it is uniquely populated - // w/ all null values but non null player + // return max player id from players table + let max_player_id = players + .select(max(smithe_database::schema::players::player_id)) + .first::>(&db_connection)?; + if let Some(val) = max_player_id { + Ok(val) + } else { + Ok(1000) // nothing in db, start at 1000 + } } } diff --git a/startgg_api/src/lib.rs b/startgg_api/src/lib.rs index aa1bcfd..1b97bc8 100644 --- a/startgg_api/src/lib.rs +++ b/startgg_api/src/lib.rs @@ -3,7 +3,7 @@ pub mod queries; -use std::{collections::HashMap, env}; +use std::collections::HashMap; use as_any::AsAny; use serde::Deserialize; @@ -199,7 +199,7 @@ pub struct StartGG { impl StartGG { pub fn connect() -> Self { let mut headers = HashMap::new(); - let bearer_token = format!("Bearer {}", env!("STARTGG_TOKEN")); + let bearer_token = format!("Bearer {}", std::env::var("STARTGG_TOKEN").expect("could not find STARTGG_TOKEN env var")); headers.insert("authorization", bearer_token.as_str()); Self { gql_client: gql_client::Client::new_with_headers(STARTGG_ENDPOINT, headers), From dc0d4b5183b283c246c02009f84bec3c1bdee451 Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 11:21:47 -0800 Subject: [PATCH 02/11] clippy Signed-off-by: danbugs --- Makefile | 5 + backend/src/main.rs | 4 +- frontend/src/components/player_list.rs | 2 +- .../player_profile/player_profile_header.rs | 2 +- .../player_profile_tournament_list.rs | 2 +- frontend/src/main.rs | 112 +++++++++++------- lib/src/common.rs | 1 + lib/src/game.rs | 6 +- src/pidgtm/update.rs | 2 +- 9 files changed, 81 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index e63bd69..1aa3ceb 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,11 @@ improve: cargo clippy --all --all-targets --all-features -- -D warnings cargo fmt --all +.PHONY: clippy-fmt +clippy-fmt: # Runs clippy and fmt on all packages, except frontend because clippy gets confused by in-code HTML + cargo clippy -p smithe_backend -p smithe_database -p smithe_lib -p startgg + cargo fmt --all + .PHONY: test test: cargo test --workspace -- --show-output 2>&1 | tee test.out diff --git a/backend/src/main.rs b/backend/src/main.rs index e7b4c15..4927191 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -31,9 +31,7 @@ pub enum Error { impl<'r, 'o: 'r> Responder<'r, 'o> for Error { fn respond_to(self, req: &Request<'_>) -> response::Result<'o> { // todo: use open telemetry at this point - match self { - _ => Status::InternalServerError.respond_to(req), - } + Status::InternalServerError.respond_to(req) } } diff --git a/frontend/src/components/player_list.rs b/frontend/src/components/player_list.rs index 602ee0b..fbb094f 100644 --- a/frontend/src/components/player_list.rs +++ b/frontend/src/components/player_list.rs @@ -40,7 +40,7 @@ pub fn player_list(props: &Props) -> Html {

{ if p.prefix.is_none() || p.prefix.as_ref().unwrap().is_empty() { - format!("{}", &p.gamer_tag) + (&p.gamer_tag).to_string() } else { format!("{} | {}", p.prefix.as_ref().unwrap(), &p.gamer_tag) } diff --git a/frontend/src/components/player_profile/player_profile_header.rs b/frontend/src/components/player_profile/player_profile_header.rs index 7c578ae..8d98e24 100644 --- a/frontend/src/components/player_profile/player_profile_header.rs +++ b/frontend/src/components/player_profile/player_profile_header.rs @@ -33,7 +33,7 @@ pub fn player_profile_header(props: &Props) -> Html {

{ if props.selected_player.prefix.is_none() || props.selected_player.prefix.as_ref().unwrap().is_empty() { - format!("{}", &props.selected_player.gamer_tag) + (&props.selected_player.gamer_tag).to_string() } else { format!("{} | {}", props.selected_player.prefix.as_ref().unwrap(), &props.selected_player.gamer_tag) } diff --git a/frontend/src/components/player_profile/player_profile_tournament_list.rs b/frontend/src/components/player_profile/player_profile_tournament_list.rs index 653433f..4d8b579 100644 --- a/frontend/src/components/player_profile/player_profile_tournament_list.rs +++ b/frontend/src/components/player_profile/player_profile_tournament_list.rs @@ -26,7 +26,7 @@ pub fn player_profile_tournament_list(props: &Props) -> Html {

@@ -86,9 +86,9 @@ pub fn player_profile_tournament_list(props: &Props) -> Html {
{ - if s.requester_score > s.opponent_score - && s.requester_seed > s.opponent_seed - && s.result_type > 1 + if s.requester_score > s.opponent_score + && s.requester_seed > s.opponent_seed + && s.result_type > 1 && calculate_spr_or_uf(s.requester_seed, s.opponent_seed) > 0 { format!("upset factor: {}", calculate_spr_or_uf(s.requester_seed, s.opponent_seed)) } else { @@ -121,4 +121,4 @@ pub fn player_profile_tournament_list(props: &Props) -> Html { } } -} \ No newline at end of file +} diff --git a/frontend/src/models.rs b/frontend/src/models.rs index 22a1d7a..7733fcf 100644 --- a/frontend/src/models.rs +++ b/frontend/src/models.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct Player { @@ -48,4 +48,4 @@ pub struct Set { pub event_id: i32, pub tournament_id: i32, pub is_event_online: bool, -} \ No newline at end of file +} diff --git a/frontend/src/utils.rs b/frontend/src/utils.rs index c79e834..9d62c8b 100644 --- a/frontend/src/utils.rs +++ b/frontend/src/utils.rs @@ -2,13 +2,13 @@ pub fn calculate_spr_or_uf(a: i32, b: i32) -> i32 { let s = if a == 1 { 0. } else { - (a as f32 - 1.).log2().floor() + (2./3. * a as f32).log2().ceil() + (a as f32 - 1.).log2().floor() + (2. / 3. * a as f32).log2().ceil() }; - + let p = if b == 1 { 0. } else { - (b as f32 - 1.).log2().floor() + (2./3. * b as f32).log2().ceil() + (b as f32 - 1.).log2().floor() + (2. / 3. * b as f32).log2().ceil() }; (s - p) as i32 @@ -17,11 +17,11 @@ pub fn calculate_spr_or_uf(a: i32, b: i32) -> i32 { pub fn parse_text_vector(text: &str) -> Vec { // remove the first and last characters let text = &text[1..text.len() - 1]; - + if text.is_empty() { return Vec::new(); } - + let mut result = Vec::new(); let mut current = String::new(); let mut in_quotes = false; @@ -37,4 +37,4 @@ pub fn parse_text_vector(text: &str) -> Vec { } result.push(current); result -} \ No newline at end of file +} diff --git a/lib/src/player.rs b/lib/src/player.rs index ffb56ee..140b299 100644 --- a/lib/src/player.rs +++ b/lib/src/player.rs @@ -7,7 +7,12 @@ use smithe_database::{ }, }; -use diesel::{dsl::{max, count}, insert_into, prelude::*, update}; +use diesel::{ + dsl::{count, max}, + insert_into, + prelude::*, + update, +}; use smithe_database::{ db_models::{empty_player_ids::EmptyPlayerId, last_checked_player_id::LastCheckedPlayerId}, schema::last_checked_player_id, @@ -172,10 +177,13 @@ where } else { tracing::info!("✅ got some results..."); for s in ss { - tracing::info!("🍥 processing set from tourney \"{}\"", s.event.tournament.clone().unwrap().name); + tracing::info!( + "🍥 processing set from tourney \"{}\"", + s.event.tournament.clone().unwrap().name + ); // we only want to compile results for: double elimination single ssbu brackets - if is_ssbu_singles_double_elimination_tournament(&s) && s.completedAt.is_some(){ + if is_ssbu_singles_double_elimination_tournament(&s) && s.completedAt.is_some() { let requester_entrant_id = if is_tournament_finished(&s) { get_requester_id_from_standings(&s, player.id) } else { @@ -192,7 +200,8 @@ where let rslot = get_requester_set_slot(requester_entrant_id, &s); let oslot = get_opponent_set_slot(requester_entrant_id, &s); - if let (Some(r), Some(o)) = (rslot, oslot) { // tournaments could be finished, but not have actually finished + if let (Some(r), Some(o)) = (rslot, oslot) { + // tournaments could be finished, but not have actually finished // some sets only have a reported winner, ignore them // e.g., https://www.start.gg/tournament/mainstage-2021/event/ultimate-singles/brackets/952392/1513154 if r.standing @@ -302,4 +311,4 @@ pub fn get_top_two_characters(pid: i32) -> Result>> { .get_results::>(&db_connection)?; Ok(top_two_characters) -} \ No newline at end of file +} diff --git a/src/smithe/player.rs b/src/smithe/player.rs index 8968ec5..e2756ad 100644 --- a/src/smithe/player.rs +++ b/src/smithe/player.rs @@ -2,21 +2,17 @@ use std::sync::{Arc, Mutex}; use anyhow::Result; -use smithe_database::{ - db_models::{player::Player} -}; +use smithe_database::db_models::player::Player; use smithe_lib::{ common::start_read_all_by_increment_execute_finish_maybe_cancel, + player::{execute, get_all_like}, set::{ - get_all_from_player_id, get_competitor_type, get_last_completed_at, - get_set_losses_by_dq, - get_set_wins_without_dqs, get_winrate, get_set_losses_without_dqs, get_set_wins_by_dq, - }, player::{get_all_like, execute}, -}; -use startgg::{ - queries::set_getter::{make_set_getter_query, SetGetterVars} + get_all_from_player_id, get_competitor_type, get_last_completed_at, get_set_losses_by_dq, + get_set_losses_without_dqs, get_set_wins_by_dq, get_set_wins_without_dqs, get_winrate, + }, }; +use startgg::queries::set_getter::{make_set_getter_query, SetGetterVars}; use dialoguer::{theme::ColorfulTheme, Select}; diff --git a/startgg_api/src/lib.rs b/startgg_api/src/lib.rs index 1b97bc8..cff1a35 100644 --- a/startgg_api/src/lib.rs +++ b/startgg_api/src/lib.rs @@ -199,7 +199,10 @@ pub struct StartGG { impl StartGG { pub fn connect() -> Self { let mut headers = HashMap::new(); - let bearer_token = format!("Bearer {}", std::env::var("STARTGG_TOKEN").expect("could not find STARTGG_TOKEN env var")); + let bearer_token = format!( + "Bearer {}", + std::env::var("STARTGG_TOKEN").expect("could not find STARTGG_TOKEN env var") + ); headers.insert("authorization", bearer_token.as_str()); Self { gql_client: gql_client::Client::new_with_headers(STARTGG_ENDPOINT, headers), From 991939589e1f4913872fcebf58cf6e3d37a30ee7 Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 11:30:43 -0800 Subject: [PATCH 04/11] update CI Signed-off-by: danbugs --- .github/workflows/build.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2a293b5..41b2fe2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build +name: CI on: push: @@ -7,7 +7,27 @@ on: pull_request: jobs: + lint-and-format: + name: Lint with clippy and check formatting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy, rustfmt + override: true + + - name: Check formatting + run: cargo fmt -- --check + + - name: Clippy check + run: cargo clippy -p smithe_backend -p smithe_database -p smithe_lib -p startgg -- -D warnings build: + needs: lint-and-format strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] @@ -23,7 +43,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: From 3d1c8c2a490ddefdecb54b31bb1787bafdb2c6be Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 12:13:40 -0800 Subject: [PATCH 05/11] fixing build on windows, and adding caching Signed-off-by: danbugs --- .github/workflows/build.yml | 9 +++++++++ Makefile | 7 +------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 41b2fe2..c3d144a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,10 @@ jobs: steps: - uses: actions/checkout@v2 + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: @@ -51,6 +55,11 @@ jobs: override: true target: ${{ matrix.target }} + # Additional step for Windows only + - if: matrix.os == 'windows-latest' + name: Install PostgreSQL + run: choco install postgresql --params '/Password:postgres' --no-progress + - name: Build run: cargo build --release --target ${{ matrix.target }} diff --git a/Makefile b/Makefile index 1aa3ceb..4a6c75f 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,7 @@ SMITHE ?= target/release/smithe # CARGO .PHONY: improve improve: - cargo clippy --all --all-targets --all-features -- -D warnings - cargo fmt --all - -.PHONY: clippy-fmt -clippy-fmt: # Runs clippy and fmt on all packages, except frontend because clippy gets confused by in-code HTML - cargo clippy -p smithe_backend -p smithe_database -p smithe_lib -p startgg + cargo clippy --fix -p smithe_backend -p smithe_database -p smithe_lib -p startgg cargo fmt --all .PHONY: test From 00b510dc5cad6d744da59225ee721e260fa362f5 Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 12:52:56 -0800 Subject: [PATCH 06/11] added docker deploy action on PR merge onto main Signed-off-by: danbugs --- .github/workflows/docker-deploy.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/docker-deploy.yml diff --git a/.github/workflows/docker-deploy.yml b/.github/workflows/docker-deploy.yml new file mode 100644 index 0000000..58cd958 --- /dev/null +++ b/.github/workflows/docker-deploy.yml @@ -0,0 +1,23 @@ +name: Docker Deployment + +on: + push: + branches: + - main + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: my-binary-x86_64-unknown-linux-gnu + + - name: Build Docker image + run: | + docker build -t pidgtm-user-updater:latest -f Dockerfile-UserUpdater . + echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + docker push pidgtm-user-updater:latest From 056bab88dbca5136d882e0fe821c698d8952fdcc Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 13:07:30 -0800 Subject: [PATCH 07/11] added caching to postgres Signed-off-by: danbugs --- .github/workflows/build.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3d144a..981c464 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,8 +45,17 @@ jobs: - uses: actions/checkout@v2 - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 - + uses: Swatinem/rust-cache@v2 + + - if: matrix.os == 'windows-latest' + name: Cache Chocolatey packages + uses: actions/cache@v2 + with: + path: C:\ProgramData\chocolatey\lib + key: windows-choco-${{ hashFiles('**/choco-packages.config') }} + restore-keys: | + windows-choco- + - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: @@ -55,7 +64,6 @@ jobs: override: true target: ${{ matrix.target }} - # Additional step for Windows only - if: matrix.os == 'windows-latest' name: Install PostgreSQL run: choco install postgresql --params '/Password:postgres' --no-progress From 16a67fcdcef2d94eb8a0e88429d2a5f3ef1a7db2 Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 13:28:03 -0800 Subject: [PATCH 08/11] meaningless change to test caching Signed-off-by: danbugs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92df61b..913ccff 100644 --- a/README.md +++ b/README.md @@ -48,4 +48,4 @@ Currently, the only way to get Smithereens on your computer is to build it from After that, inside of Smithereens' repository root, run: `cargo build --release`. With that, you'll have Smithereens' binary (i.e., `smithe`) built under `target/release`. You can run it, like: `./target/release/smithe`. After that, feel free to move the binary to a more convenient place on your machine (i.e., perhaps to a place included in your `PATH`, so you can run it simply with `smithe`). -> Note: In the future, there will be releases for `smithe`, so this process will be better streamlined. \ No newline at end of file +> Note: In the future, there will be releases for `smithe`, so this process will be better streamlined. From 6686ffff7b8c1e13cf7c56b6b18dbcc771d6d572 Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 13:37:44 -0800 Subject: [PATCH 09/11] adding action for postgres and removing its caching 'cause it breaks build Signed-off-by: danbugs --- .github/workflows/build.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 981c464..4ad3579 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,15 +46,7 @@ jobs: - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - - - if: matrix.os == 'windows-latest' - name: Cache Chocolatey packages - uses: actions/cache@v2 - with: - path: C:\ProgramData\chocolatey\lib - key: windows-choco-${{ hashFiles('**/choco-packages.config') }} - restore-keys: | - windows-choco- + - name: Install Rust toolchain uses: actions-rs/toolchain@v1 @@ -66,7 +58,7 @@ jobs: - if: matrix.os == 'windows-latest' name: Install PostgreSQL - run: choco install postgresql --params '/Password:postgres' --no-progress + uses: ikalnytskyi/action-setup-postgres@v4 - name: Build run: cargo build --release --target ${{ matrix.target }} From c51ec8aefb30488cf06887a6e100c3aae52e3feb Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 14:15:37 -0800 Subject: [PATCH 10/11] fixing CI Signed-off-by: danbugs --- .github/workflows/build.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ad3579..ac68128 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,7 +58,14 @@ jobs: - if: matrix.os == 'windows-latest' name: Install PostgreSQL - uses: ikalnytskyi/action-setup-postgres@v4 + uses: ikalnytskyi/action-setup-postgres@v4 + with: + postgres-version: '13' + + - if: matrix.os == 'windows-latest' + name: Configure PostgreSQL library path + run: | + echo "LIB=${{ env.PG_HOME }}\lib;%LIB%" >> $GITHUB_ENV - name: Build run: cargo build --release --target ${{ matrix.target }} From 139ecc30b7f6bc63189bbbf09870df9b60241af6 Mon Sep 17 00:00:00 2001 From: danbugs Date: Sun, 24 Dec 2023 15:01:46 -0800 Subject: [PATCH 11/11] fixing CI Signed-off-by: danbugs --- .cargo/config.toml | 2 +- .github/workflows/build.yml | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 52cb51a..508ad07 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [target.x86_64-pc-windows-msvc.pq] -rustc-link-search = ["C:\\Program Files\\PostgreSQL\\16\\lib"] +rustc-link-search = ["C:\\Program Files\\PostgreSQL\\14\\lib"] rustc-link-lib = ["libpq"] \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac68128..e19a751 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,13 +59,6 @@ jobs: - if: matrix.os == 'windows-latest' name: Install PostgreSQL uses: ikalnytskyi/action-setup-postgres@v4 - with: - postgres-version: '13' - - - if: matrix.os == 'windows-latest' - name: Configure PostgreSQL library path - run: | - echo "LIB=${{ env.PG_HOME }}\lib;%LIB%" >> $GITHUB_ENV - name: Build run: cargo build --release --target ${{ matrix.target }}