Skip to content

Commit

Permalink
Merge pull request #275 from tyreseluo/robrix_ci
Browse files Browse the repository at this point in the history
Add CI passes for clippy and cargo check
  • Loading branch information
kevinaboos authored Nov 28, 2024
2 parents f495dec + 656924c commit 6b84169
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 9 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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: "-D warnings"

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
- 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
- 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

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
13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,21 @@ appdata_paths = [
"$LOCALAPPDATA/$PRODUCTNAME",
]

[lints.rust]
keyword_idents_2024 = "forbid"
non_ascii_idents = "forbid"
non_local_definitions = "forbid"
unsafe_op_in_unsafe_fn = "forbid"

## Configuration for clippy
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"
module_name_repetitions = "allow"
8 changes: 4 additions & 4 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -2983,21 +2983,21 @@ 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
}
}
}
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
));
Expand Down
2 changes: 1 addition & 1 deletion src/shared/html_or_plaintext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl LiveHook for MatrixHtmlSpan {
if let Some(doc) = scope.props.get::<HtmlDoc>() {
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(),
Expand Down
3 changes: 1 addition & 2 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6b84169

Please sign in to comment.