From f40cb802b193e16cb8e2010485abc8632f887086 Mon Sep 17 00:00:00 2001 From: Ronan Date: Wed, 25 Sep 2024 08:09:54 +0200 Subject: [PATCH] refactor build.rs for creeating TESTUSER and deleting it after build --- .github/workflows/build.yaml | 2 +- .github/workflows/windows.yml | 3 ++- build.rs | 19 +++++++----------- db_v2.sqlite3 | Bin 352256 -> 348160 bytes libs/state/Cargo.toml | 4 ++++ libs/state/build.rs | 35 ++++++++++++++++++++++++++++++++++ libs/state/src/database.rs | 5 ++++- 7 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 libs/state/build.rs diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b094388..fd26b53 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -156,7 +156,7 @@ jobs: EOF - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.target }} path: target/${{ matrix.target }}/release/ diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index f258a72..ba72fcf 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -84,6 +84,7 @@ jobs: export TAG_NAME=${{ github.event.release.tag_name }} export TAG_NAME=${TAG_NAME:-"nightly"} echo $TAG_NAME - mv /tmp/windows_${{ matrix.job.arch }}_${{ github.event.release.tag_name }}.zip /tmp/windows_${{ matrix.job.arch }}_${TAG_NAME}.zip + ls -l /tmp + mv /tmp/windows_*.zip /tmp/windows_${{ matrix.job.arch }}_${TAG_NAME}.zip gh release create $TAG_NAME -t "$TAG_NAME" -n "$TAG_NAME" || true gh release upload $TAG_NAME /tmp/windows_${{ matrix.job.arch }}_${TAG_NAME}.zip --clobber \ No newline at end of file diff --git a/build.rs b/build.rs index 295c4bb..f60a98b 100644 --- a/build.rs +++ b/build.rs @@ -54,18 +54,7 @@ impl PackageJson { #[tokio::main] async fn main() { let db_path = env::var("DATABASE_URL").unwrap_or("sqlite://db_v2.sqlite3".to_string()); - let mut conn = SqliteConnection::connect(&format!("{}", db_path)) - .await - .expect("Failed to open database"); - conn.execute( - r#" - INSERT OR IGNORE INTO peer (guid, id, uuid, pk, created_at, "user", status, note, region, strategy, info, last_online) VALUES - (x'95CC7775BA37481DAD7214A4F6CE5A94', 'TESTUSER', randomblob(16), randomblob(16), '1901-01-01 12:00:00', randomblob(16), 0, '', NULL, randomblob(16), '{}', '1901-01-01 12:00:00'); - "# - ) - .await - .expect("Failed to insert test data"); - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=webconsole"); let data = fs::read_to_string("./webconsole/package.json").unwrap(); @@ -118,9 +107,15 @@ async fn main() { str::from_utf8(&output.stdout).unwrap_or(""), str::from_utf8(&output.stderr).unwrap_or("") ); + + // Delete test data if it exists + let mut conn = SqliteConnection::connect(&format!("{}", db_path)) + .await + .expect("Failed to open database"); conn.execute( r#" DELETE FROM peer WHERE guid = x'95CC7775BA37481DAD7214A4F6CE5A94'; + PRAGMA journal_mode=DELETE; "# ) .await diff --git a/db_v2.sqlite3 b/db_v2.sqlite3 index 076cd026578ce1537c7579bdd9da08e331ec3ea8..671d35090023e1b236950ef06f85fda7da696bb7 100644 GIT binary patch delta 518 zcmZoTAlk4%R3|vlC$l6~AuYcsH?c&)m_dMnk&(ecL4kpRffY2C(+?XI!fOc)dDh{^dP-{O?>#l#fK5sv0Rdj#F!&%ABk`#D~H-2}nv zS}dA2H82`T^Z#JrWRzs!>*n9i8^jmEt;HF`X3q4SQIh}1WJQ6$n$9b|& z+MepgYRAM9r@fIHCNT0YhuE&o4i0T33G%q@K5Gf<2%P!Hl5FbRc^DQfF{TG sa1T~_Hr6l)HgV(WjCYuXr_Xj~;M1& delta 2483 zcmb_ddrT8|9KYXPuh;h#q2XCQUaicceE<$76Pz&R{jw-*+DZ$Slos17-~)>~(X=e$ zy6l{&bGrFhmTZcy*;teq=N~h1x@e5iRpa)@GMAuRBtb{q@3_$wqGmeV`?jBJf8WpV z^L_oU=YXPTSfQz{F0;{As@dskGt-m-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L(~YT7n;z~|a)rAL!Ex2*8lD`fO)SOoZMg&ygJyaEt3-beoAX$|`b=v4PP7h7FoSim{tOHRP zl)yWs`lZ#(0Y69rf{DU2*Zd$RSic0H#h1WThzzhqHb+?v^Eiag1Zix0W(F@-;CgVP zeK)yA``ee}ni0y}+?W=Sp4>Wa?8-g+m-KSd*)pZ$V9R!wE?29|oVX~RK2NKK*YtUu LK7t#%pWyU2nsXSM diff --git a/libs/state/Cargo.toml b/libs/state/Cargo.toml index 1b8f100..9f1acd5 100644 --- a/libs/state/Cargo.toml +++ b/libs/state/Cargo.toml @@ -19,3 +19,7 @@ tracing-subscriber = "0.3" sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio-rustls", "macros", "chrono", "json"] } bcrypt = "0.15" uuid = { version = "1.0", features = ["v4"] } + +[build-dependencies] +tokio = { version = "1", features = ["full"] } +sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio-rustls", "macros", "chrono", "json"] } \ No newline at end of file diff --git a/libs/state/build.rs b/libs/state/build.rs new file mode 100644 index 0000000..0e6702c --- /dev/null +++ b/libs/state/build.rs @@ -0,0 +1,35 @@ +// Copyright (c) 2024 Ronan LE MEILLAT for SCTG Development +// +// This file is part of the SCTGDesk project. +// +// SCTGDesk is free software: you can redistribute it and/or modify +// it under the terms of the Affero General Public License version 3 as +// published by the Free Software Foundation. +// +// SCTGDesk is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// Affero General Public License for more details. +// +// You should have received a copy of the Affero General Public License +// along with SCTGDesk. If not, see . +use sqlx::{Connection, Executor, SqliteConnection}; +use std::env; + + +#[tokio::main] +async fn main() { + let db_path = env::var("DATABASE_URL").unwrap_or("sqlite://db_v2.sqlite3".to_string()); + let mut conn = SqliteConnection::connect(&format!("{}", db_path)) + .await + .expect("Failed to open database"); + conn.execute( + r#" + INSERT OR IGNORE INTO peer (guid, id, uuid, pk, created_at, "user", status, note, region, strategy, info, last_online) VALUES + (x'95CC7775BA37481DAD7214A4F6CE5A94', 'TESTUSER', randomblob(16), randomblob(16), '1901-01-01 12:00:00', randomblob(16), 0, '', NULL, randomblob(16), '{}', '1901-01-01 12:00:00'); + "# + ) + .await + .expect("Failed to insert test data"); + +} diff --git a/libs/state/src/database.rs b/libs/state/src/database.rs index 008e110..4743bd5 100644 --- a/libs/state/src/database.rs +++ b/libs/state/src/database.rs @@ -1560,9 +1560,12 @@ impl Database { pub async fn get_cpus_count(&self) -> Vec { let mut conn = self.pool.acquire().await.unwrap(); - // for avoiding compiltion error you can use the following query + // for avoiding compiltion error you can use the following query it is included in the build.rs // INSERT OR IGNORE INTO peer (guid, id, uuid, pk, created_at, "user", status, note, region, strategy, info, last_online) VALUES // (x'95CC7775BA37481DAD7214A4F6CE5A94', 'TESTUSER', randomblob(16), randomblob(16), '1901-01-01 12:00:00', randomblob(16), 0, '', NULL, randomblob(16), '{}', '1901-01-01 12:00:00'); + // Note: that the build.rs will not remove the peer from the database + // for removing the peer from the database you can use the following query + // DELETE FROM peer WHERE guid = x'95CC7775BA37481DAD7214A4F6CE5A94'; let res = sqlx::query!( r#" SELECT