From 975e41e8b2b6cb5dc7635cbd326b82d8ebb8b2ac Mon Sep 17 00:00:00 2001 From: Tyrese Luo Date: Sun, 24 Nov 2024 15:37:38 +0800 Subject: [PATCH 1/3] Add basic robrix rust CI config --- .cargo/config.toml | 5 ++- .github/workflows/main.yml | 83 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 29 +++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/main.yml diff --git a/.cargo/config.toml b/.cargo/config.toml index 1e4c8000..254f327f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,8 @@ ## Add these flags onto all target builds cumulatively. ## [target.'cfg(all())'] -rustflags = ["--cfg", "ruma_identifiers_storage=\"Arc\""] +rustflags = [ + "--cfg", "ruma_identifiers_storage=\"Arc\"", + "-A", "clippy::all", +] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..a171a494 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,83 @@ +# Trigger CI on PR updates and main branch pushes +# Uses caching and selective path triggers to optimize performance + +name: Robrix Rust CI + +# Only `main` branch +on: + push: + branches: + - main + paths: + - packaging/** + - resources/** + - src/** + - .github/** + - Cargo.toml + - rust-toolchain.toml + + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + branches: + - main + paths: + - packaging/** + - resources/** + - src/** + - .github/** + - Cargo.toml + - rust-toolchain.toml + +# Prevent concurrent CI runs and cancel in-progress runs on new pushes +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +# Global environment configuration +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: "0" # Disable incremental compilation in CI + RUST_BACKTRACE: 1 + # Enable warnings as errors for strict checks + RUSTFLAGS: "-A warnings" + # For special compile + rust_nightly: nightly-2024-10-20 + +jobs: + # Basic compilation check to ensure code builds + check: + if: github.event.pull_request.draft == false + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Install required system dependencies + - run: sudo apt-get update + - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev + - uses: dtolnay/rust-toolchain@stable + # Cache dependencies to speed up builds + - uses: Swatinem/rust-cache@v2 + with: + cache-all-crates: "true" + cache-on-failure: "true" + # Check if the code compiles with all features + - run: cargo check --workspace --all-features --all-targets + + clippy: + if: github.event.pull_request.draft == false + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: sudo apt-get update + - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + - uses: Swatinem/rust-cache@v2 + with: + cache-all-crates: "true" + cache-on-failure: "true" + # Run clippy with custom configuration for makepad DSL + # Allow pedantic / needless_lifetimes / too_many_arguments + - run: cargo clippy --workspace --examples --tests --all-features --all-targets \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 0787ea83..58797302 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -197,3 +197,32 @@ appdata_paths = [ "$APPDATA/$PUBLISHER/$PRODUCTNAME", "$LOCALAPPDATA/$PRODUCTNAME", ] + +[lints.rust] +keyword_idents_2024 = "forbid" +non_ascii_idents = "forbid" +non_local_definitions = "forbid" +unsafe_op_in_unsafe_fn = "forbid" + +unexpected_cfgs = "warn" +unnameable_types = "warn" +unused_import_braces = "warn" + +[lints.clippy] +correctness = "warn" +suspicious = "warn" +complexity = "warn" +perf = "warn" +needless_lifetimes = "warn" +too_many_arguments = "warn" + +cast_possible_truncation = "warn" +collection_is_never_read = "warn" +dbg_macro = "warn" +infinite_loop = "warn" +large_include_file = "warn" +large_stack_arrays = "warn" +match_same_arms = "warn" +mismatching_type_param_order = "warn" +partial_pub_fields = "warn" +return_self_not_must_use = "warn" \ No newline at end of file From 8ae5b6c5a56256171c90a72455de3da8af95f75b Mon Sep 17 00:00:00 2001 From: Tyrese Luo Date: Thu, 28 Nov 2024 09:55:10 +0800 Subject: [PATCH 2/3] update ci config --- .cargo/config.toml | 5 +---- .github/workflows/main.yml | 5 ----- Cargo.toml | 19 ++----------------- src/home/room_screen.rs | 8 ++++---- src/shared/html_or_plaintext.rs | 2 +- src/sliding_sync.rs | 3 +-- 6 files changed, 9 insertions(+), 33 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 254f327f..1e4c8000 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,8 +1,5 @@ ## Add these flags onto all target builds cumulatively. ## [target.'cfg(all())'] -rustflags = [ - "--cfg", "ruma_identifiers_storage=\"Arc\"", - "-A", "clippy::all", -] +rustflags = ["--cfg", "ruma_identifiers_storage=\"Arc\""] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a171a494..70f5a5b0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,9 +51,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - # Install required system dependencies - - run: sudo apt-get update - - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev - uses: dtolnay/rust-toolchain@stable # Cache dependencies to speed up builds - uses: Swatinem/rust-cache@v2 @@ -69,8 +66,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: sudo apt-get update - - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev - uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy diff --git a/Cargo.toml b/Cargo.toml index 2f19ea2d..de46ba31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,26 +208,11 @@ unexpected_cfgs = "warn" unnameable_types = "warn" unused_import_braces = "warn" +## Configuration for clippy lints. [lints.clippy] collapsible_if = "allow" collapsible_else_if = "allow" too_many_arguments = "allow" blocks_in_conditions = "allow" used_underscore_binding = "allow" -module_name_repetitions = "allow" -correctness = "warn" -suspicious = "warn" -complexity = "warn" -perf = "warn" -needless_lifetimes = "warn" - -cast_possible_truncation = "warn" -collection_is_never_read = "warn" -dbg_macro = "warn" -infinite_loop = "warn" -large_include_file = "warn" -large_stack_arrays = "warn" -match_same_arms = "warn" -mismatching_type_param_order = "warn" -partial_pub_fields = "warn" -return_self_not_must_use = "warn" +module_name_repetitions = "allow" \ No newline at end of file diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index b6cc679e..e3a8436e 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -2957,7 +2957,7 @@ fn populate_image_message_content( // then show a message about it being unsupported. if let Some(mime) = mimetype.as_ref() { if ImageFormat::from_mimetype(mime).is_none() { - text_or_image_ref.show_text(&format!( + text_or_image_ref.show_text(format!( "{body}\n\nImages/Stickers of type {mime:?} are not yet supported.", )); return true; @@ -2983,13 +2983,13 @@ fn populate_image_message_content( true } MediaCacheEntry::Requested => { - text_or_image_ref.show_text(&format!("{body}\n\nFetching image from {:?}", mxc_uri)); + text_or_image_ref.show_text(format!("{body}\n\nFetching image from {:?}", mxc_uri)); // Do not consider this image as being fully drawn, as we're still fetching it. false } MediaCacheEntry::Failed => { text_or_image_ref - .show_text(&format!("{body}\n\nFailed to fetch image from {:?}", mxc_uri)); + .show_text(format!("{body}\n\nFailed to fetch image from {:?}", mxc_uri)); // For now, we consider this as being "complete". In the future, we could support // retrying to fetch the image on a user click/tap. true @@ -2997,7 +2997,7 @@ fn populate_image_message_content( } } Some(MediaSource::Encrypted(encrypted)) => { - text_or_image_ref.show_text(&format!( + text_or_image_ref.show_text(format!( "{body}\n\n[TODO] fetch encrypted image at {:?}", encrypted.url )); diff --git a/src/shared/html_or_plaintext.rs b/src/shared/html_or_plaintext.rs index 03c81d32..d4a3475e 100644 --- a/src/shared/html_or_plaintext.rs +++ b/src/shared/html_or_plaintext.rs @@ -144,7 +144,7 @@ impl LiveHook for MatrixHtmlSpan { if let Some(doc) = scope.props.get::() { let mut walker = doc.new_walker_with_index(scope.index + 1); while let Some((lc, attr)) = walker.while_attr_lc(){ - let attr = attr.trim_matches(&['"', '\'']); + let attr = attr.trim_matches(['"', '\'']); match lc { live_id!(color) | live_id!(data-mx-color) => self.fg_color = Vec4::from_hex_str(attr).ok(), diff --git a/src/sliding_sync.rs b/src/sliding_sync.rs index 031862a9..55782c4b 100644 --- a/src/sliding_sync.rs +++ b/src/sliding_sync.rs @@ -1973,14 +1973,13 @@ async fn spawn_sso_server( .identity_provider_id(&identity_provider_id) .initial_device_display_name(&format!("robrix-sso-{brand}")) .await - .map(|response| { + .inspect(|_| { if let Some(client) = get_client() { if client.logged_in() { is_logged_in = true; log!("Already logged in, ignore login with sso"); } } - response }) { Ok(identity_provider_res) => { if !is_logged_in { From ca8043b0659166c2c0514e9209474844ce056c07 Mon Sep 17 00:00:00 2001 From: Tyrese Luo Date: Thu, 28 Nov 2024 14:03:43 +0800 Subject: [PATCH 3/3] Update ci config --- .github/workflows/main.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70f5a5b0..a6a89719 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,9 +39,7 @@ env: CARGO_INCREMENTAL: "0" # Disable incremental compilation in CI RUST_BACKTRACE: 1 # Enable warnings as errors for strict checks - RUSTFLAGS: "-A warnings" - # For special compile - rust_nightly: nightly-2024-10-20 + RUSTFLAGS: "-D warnings" jobs: # Basic compilation check to ensure code builds @@ -75,4 +73,13 @@ jobs: cache-on-failure: "true" # Run clippy with custom configuration for makepad DSL # Allow pedantic / needless_lifetimes / too_many_arguments - - run: cargo clippy --workspace --examples --tests --all-features --all-targets \ No newline at end of file + - run: cargo clippy --workspace --examples --tests --all-features --all-targets + + typos: + if: github.event.pull_request.draft == false + name: Check for typos + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check for typos + uses: crate-ci/typos@master \ No newline at end of file