From 2ab63b15d994ec88c5635b1d2829abbbcf4fd42a Mon Sep 17 00:00:00 2001 From: Richard Jansen Date: Thu, 4 Jan 2024 13:52:30 +0100 Subject: [PATCH 1/5] Github actions & coveralls - github actions change to also include coveralls - updated README for test results badge - updated repo links in Cargo.toml --- .github/workflows/test.yml | 29 +++++++++++++++++++++++++---- Cargo.toml | 4 ++-- README.md | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 777fe89f9..483b4ffb5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,8 @@ name: Cargo tests on: push: branches: - - master + - main + - develop pull_request: jobs: clippy: @@ -11,7 +12,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: stable components: clippy override: true - name: Install dependencies @@ -50,7 +51,10 @@ jobs: runs-on: ${{ matrix.os }} env: - RUSTFLAGS: "-Dwarnings" + RUSTFLAGS: "-Dwarnings -Cinstrument-coverage -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" + CARGO_INCREMENTAL: "0" + RUSTDOCFLAGS: "-Cpanic=abort" + RUSTC_BOOTSTRAP: "1" steps: - uses: actions/checkout@v2 @@ -58,6 +62,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: toolchain: ${{matrix.rust}} + components: llvm-tools-preview - uses: actions/cache@v2 with: @@ -65,5 +70,21 @@ jobs: target key: ${{ runner.os }}-cargo-${{ matrix.rust }} + - name: Build + run: cargo build + + - name: Install grcov + run: cargo install grcov + - name: Run tests - run: cargo test + run: LLVM_PROFILE_FILE="fcm-rust-%p-%m.profraw" cargo test + + - name: Collect results + run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o . + + - name: Coveralls GitHub Action + uses: coverallsapp/github-action@v2.2.3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: ./lcov + diff --git a/Cargo.toml b/Cargo.toml index 54fa0d18a..6e465a1fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ authors = [ ] description = "An API to talk to FCM (Firebase Cloud Messaging) in Rust" license = "MIT" -homepage = "https://github.com/panicbit/fcm-rust" -repository = "https://github.com/panicbit/fcm-rust" +homepage = "https://github.com/rj76/fcm-rust" +repository = "https://github.com/rj76/fcm-rust" documentation = "https://docs.rs/fcm/" keywords = ["fcm", "firebase", "notification"] edition = "2018" diff --git a/README.md b/README.md index ff7e8150b..14866b84a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # fcm -[![Cargo tests](https://github.com/rj76/fcm-rust/actions/workflows/test.yml/badge.svg)](https://github.com/panicbit/fcm-rust/actions/workflows/test.yml) +[![Cargo tests](https://github.com/rj76/fcm-rust/actions/workflows/test.yml/badge.svg)](https://github.com/rj76/fcm-rust/actions/workflows/test.yml) [![Coveralls](https://img.shields.io/coveralls/panicbit/fcm-rust.svg?style=flat-square)][coveralls] [![Crates.io Version](https://img.shields.io/crates/v/fcm.svg?style=flat-square)][crates.io] [![Crates.io Downloads](https://img.shields.io/crates/dv/fcm.svg?style=flat-square)][crates.io] From 09aa86ec7801a51311377411855372247d535672 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 4 Jan 2024 12:55:34 +0000 Subject: [PATCH 2/5] Format Rust code using rustfmt --- src/android/mod.rs | 10 +++++----- src/apns/mod.rs | 2 +- src/client/mod.rs | 12 ++++-------- src/client/response.rs | 1 - src/lib.rs | 4 ++-- src/message/mod.rs | 30 ++++++++++++------------------ src/message/tests.rs | 6 ++---- src/notification/mod.rs | 2 +- src/web/mod.rs | 2 +- 9 files changed, 28 insertions(+), 41 deletions(-) diff --git a/src/android/mod.rs b/src/android/mod.rs index 0d409c5f0..a0f1778a0 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -36,7 +36,7 @@ pub struct AndroidConfig { // If set to true, messages will be allowed to be delivered to the app while the device is in direct boot mode. #[serde(skip_serializing_if = "Option::is_none")] - direct_boot_ok: Option + direct_boot_ok: Option, } #[derive(Serialize, Debug)] @@ -52,7 +52,7 @@ pub struct Color { blue: f32, // The fraction of this color that should be applied to the pixel. - alpha: f32 + alpha: f32, } #[derive(Serialize, Debug)] @@ -184,7 +184,7 @@ pub struct AndroidNotification { //https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#androidconfig pub struct AndroidFcmOptions { // Label associated with the message's analytics data. - analytics_label: String + analytics_label: String, } #[allow(dead_code)] @@ -206,7 +206,7 @@ pub enum NotificationPriority { PriorityLow, PriorityDefault, PriorityHigh, - PriorityMax + PriorityMax, } #[allow(dead_code)] @@ -217,5 +217,5 @@ pub enum Visibility { VisibilityUnspecified, Private, Public, - Secret + Secret, } diff --git a/src/apns/mod.rs b/src/apns/mod.rs index 612ff2ea8..bfd5a2f71 100644 --- a/src/apns/mod.rs +++ b/src/apns/mod.rs @@ -24,5 +24,5 @@ pub struct ApnsFcmOptions { analytics_label: String, // Contains the URL of an image that is going to be displayed in a notification. - image: String + image: String, } diff --git a/src/client/mod.rs b/src/client/mod.rs index 7a3f9953d..77b4e5d74 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,11 +1,10 @@ pub(crate) mod response; -use gauth::serv_account::ServiceAccount; -use reqwest::{Body, StatusCode}; -use reqwest::header::RETRY_AFTER; use crate::client::response::{ErrorReason, FcmError, FcmResponse, RetryAfter}; use crate::Message; - +use gauth::serv_account::ServiceAccount; +use reqwest::header::RETRY_AFTER; +use reqwest::{Body, StatusCode}; /// An async client for sending the notification payload. pub struct Client { @@ -115,10 +114,7 @@ impl Client { }; // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send - let url = format!( - "https://fcm.googleapis.com/v1/projects/{}/messages:send", - project_id - ); + let url = format!("https://fcm.googleapis.com/v1/projects/{}/messages:send", project_id); let request = self .http_client diff --git a/src/client/response.rs b/src/client/response.rs index 80617bcd0..f7e5bf6a7 100644 --- a/src/client/response.rs +++ b/src/client/response.rs @@ -148,7 +148,6 @@ pub enum FcmError { ProjectIdError(String), AuthToken(String), - } impl Error for FcmError {} diff --git a/src/lib.rs b/src/lib.rs index 21ab94604..c44d0a4ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,10 +64,10 @@ mod message; pub use crate::message::*; mod notification; pub use crate::notification::*; -mod client; mod android; -mod web; mod apns; +mod client; +mod web; pub use crate::client::*; diff --git a/src/message/mod.rs b/src/message/mod.rs index 6897cd762..4536921f5 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -1,9 +1,9 @@ -use serde::{Serialize, Serializer}; -use serde_json::Value; use crate::android::AndroidConfig; use crate::apns::ApnsConfig; -use crate::Notification; use crate::web::WebpushConfig; +use crate::Notification; +use serde::{Serialize, Serializer}; +use serde_json::Value; #[cfg(test)] mod tests; @@ -13,23 +13,17 @@ mod tests; pub enum Target { Token(String), Topic(String), - Condition(String) + Condition(String), } fn output_target(target: &Target, s: S) -> Result - where - S: Serializer +where + S: Serializer, { match target { - Target::Token(token) => { - s.serialize_newtype_struct("token", token.as_str()) - }, - Target::Topic(topic) => { - s.serialize_newtype_struct("topic", topic.as_str()) - }, - Target::Condition(condition) => { - s.serialize_newtype_struct("condition", condition.as_str()) - }, + Target::Token(token) => s.serialize_newtype_struct("token", token.as_str()), + Target::Topic(topic) => s.serialize_newtype_struct("topic", topic.as_str()), + Target::Condition(condition) => s.serialize_newtype_struct("condition", condition.as_str()), } } @@ -62,7 +56,7 @@ pub struct Message { // Target to send a message to. #[serde(serialize_with = "output_target")] - target: Target + target: Target, } #[derive(Serialize, Debug)] @@ -88,7 +82,7 @@ pub struct FcmOptions { pub struct MessageBuilder { data: Option, notification: Option, - target: Target + target: Target, } impl MessageBuilder { @@ -150,7 +144,7 @@ impl MessageBuilder { webpush: None, apns: None, fcm_options: None, - target: self.target + target: self.target, } } } diff --git a/src/message/tests.rs b/src/message/tests.rs index 731a78a75..b5315f8e7 100644 --- a/src/message/tests.rs +++ b/src/message/tests.rs @@ -12,8 +12,7 @@ struct CustomData { #[test] fn should_create_new_message() { let target = Target::Token("token".to_string()); - let msg = MessageBuilder::new(target.clone()) - .finalize(); + let msg = MessageBuilder::new(target.clone()).finalize(); assert_eq!(msg.target, target); } @@ -61,8 +60,7 @@ fn should_be_able_to_render_a_full_message_to_json() { let target = Target::Token("token".to_string()); let mut builder = MessageBuilder::new(target); - builder - .notification(NotificationBuilder::new().finalize()); + builder.notification(NotificationBuilder::new().finalize()); let payload = serde_json::to_string(&builder.finalize()).unwrap(); diff --git a/src/notification/mod.rs b/src/notification/mod.rs index 5a5a6c0f5..0ca5606a0 100644 --- a/src/notification/mod.rs +++ b/src/notification/mod.rs @@ -70,7 +70,7 @@ impl NotificationBuilder { Notification { title: self.title, body: self.body, - image: self.image + image: self.image, } } } diff --git a/src/web/mod.rs b/src/web/mod.rs index 494651417..60d42990d 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -29,5 +29,5 @@ pub struct WebpushFcmOptions { link: String, // Label associated with the message's analytics data. - analytics_label: String + analytics_label: String, } From 6561079b521489ca04f30d0c9c95270f3bce6630 Mon Sep 17 00:00:00 2001 From: Richard Jansen Date: Thu, 4 Jan 2024 14:04:01 +0100 Subject: [PATCH 3/5] lcov filename rename in github action --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 483b4ffb5..d4afa7690 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,11 +80,11 @@ jobs: run: LLVM_PROFILE_FILE="fcm-rust-%p-%m.profraw" cargo test - name: Collect results - run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o . + run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./tests.lcov - name: Coveralls GitHub Action uses: coverallsapp/github-action@v2.2.3 with: github-token: ${{ secrets.GITHUB_TOKEN }} - file: ./lcov + file: ./tests.lcov From b2f580a18a77973de7afcf7022595efd3bfca73d Mon Sep 17 00:00:00 2001 From: Richard Jansen Date: Thu, 4 Jan 2024 14:14:46 +0100 Subject: [PATCH 4/5] Remove windows from testing --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d4afa7690..0ec636b6a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,7 +46,6 @@ jobs: os: - ubuntu-latest - macos-latest - - windows-latest runs-on: ${{ matrix.os }} From dc8bd0fbf8fca8d09db4d51cbb8b48694b5713ea Mon Sep 17 00:00:00 2001 From: Richard Jansen Date: Thu, 4 Jan 2024 14:26:33 +0100 Subject: [PATCH 5/5] updated README --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 14866b84a..b74bfbd09 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ -# fcm +# fcm-rust [![Cargo tests](https://github.com/rj76/fcm-rust/actions/workflows/test.yml/badge.svg)](https://github.com/rj76/fcm-rust/actions/workflows/test.yml) -[![Coveralls](https://img.shields.io/coveralls/panicbit/fcm-rust.svg?style=flat-square)][coveralls] -[![Crates.io Version](https://img.shields.io/crates/v/fcm.svg?style=flat-square)][crates.io] -[![Crates.io Downloads](https://img.shields.io/crates/dv/fcm.svg?style=flat-square)][crates.io] -[![Crates.io License](https://img.shields.io/crates/l/fcm.svg?style=flat-square)][crates.io] +[![Coverage Status](https://coveralls.io/repos/github/rj76/fcm-rust/badge.svg)](https://coveralls.io/github/rj76/fcm-rust) + +[//]: # ([![Crates.io Version](https://img.shields.io/crates/v/fcm.svg?style=flat-square)) +[//]: # ([![Crates.io Downloads](https://img.shields.io/crates/dv/fcm.svg?style=flat-square)) +[//]: # ([![Crates.io License](https://img.shields.io/crates/l/fcm.svg?style=flat-square)) -[travis]: https://travis-ci.org/panicbit/fcm-rust -[coveralls]: https://coveralls.io/github/panicbit/fcm-rust ## v1 API