From 840c38d385c2822ac0c67092b494dbbc8d3f1f40 Mon Sep 17 00:00:00 2001 From: Heiko Seeberger Date: Wed, 11 Oct 2023 20:28:10 +0200 Subject: [PATCH] chore: updates (#17) * chore: updates * build: use just * fixes * doc * fix: GH workflow --- .github/workflows/ci.yaml | 53 +++++++++++----------- Cargo.toml | 39 ++++++++++------ README.md | 1 + justfile | 18 ++++++++ pub-sub-client-derive/Cargo.toml | 27 +++++------ pub-sub-client-tests/Cargo.toml | 41 +++++++++-------- pub-sub-client-tests/examples/transform.rs | 3 +- pub-sub-client-tests/tests/test.rs | 9 ++-- pub-sub-client/Cargo.toml | 23 +++++----- pub-sub-client/src/publisher/mod.rs | 3 +- pub-sub-client/src/subscriber/mod.rs | 12 +++-- 11 files changed, 135 insertions(+), 94 deletions(-) create mode 100644 justfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 28173df..096fc85 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,47 +1,48 @@ -name: CI +name: ci on: push: - branches: [main] + branches: + - main + tags-ignore: + - v* + pull_request: - branches: [main] + branches: + - main jobs: - test: + ci: runs-on: ubuntu-latest steps: - name: Check out uses: actions/checkout@v3 + # Nightly needed for `cargo +nightly fmt` below - name: Install Rust toolchain run: | rustup update - rustup toolchain install nightly + rustup toolchain install nightly --profile minimal rustup component add rustfmt --toolchain nightly - rustup component add clippy --toolchain nightly + # rustup component add clippy --toolchain nightly - - name: Set up cargo cache - uses: actions/cache@v3 - continue-on-error: false + - name: Install just + uses: taiki-e/install-action@v2 with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo- - - - name: Check code format (cargo fmt) - run: cargo +nightly fmt --check - - - name: Lint (cargo clippy) - run: cargo clippy --no-deps -- -D warnings - - - name: Test (cargo test) + tool: just + + - name: Set up Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Check code format + run: just fmt_check + + - name: Run linter + run: just lint + + - name: Run tests env: GCP_SERVICE_ACCOUNT: ${{ secrets.GCP_SERVICE_ACCOUNT }} run: | printenv GCP_SERVICE_ACCOUNT > pub-sub-client-tests/secrets/active-road-365118-2eca6b7b8fd9.json - cargo test + just test diff --git a/Cargo.toml b/Cargo.toml index b39a2b1..995e1a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,10 @@ [workspace] -members = [ "pub-sub-client", "pub-sub-client-derive", "pub-sub-client-tests" ] +members = [ + "pub-sub-client", + "pub-sub-client-derive", + "pub-sub-client-tests", +] +resolver = "2" [workspace.package] # No use to define version here, because cargo release ignores it! @@ -8,21 +13,27 @@ edition = "2021" description = "Google Cloud Pub/Sub client library" authors = [ "Heiko Seeberger " ] license = "Apache-2.0" +readme = "README.md" homepage = "https://github.com/hseeberger/pub-sub-client" repository = "https://github.com/hseeberger/pub-sub-client" documentation = "https://github.com/hseeberger/pub-sub-client" +publish = true [workspace.dependencies] -anyhow = "1.0" -base64 = "0.13" -goauth = "0.13" -reqwest = { version = "0.11" } -serde = { version = "1.0" } -serde_json = "1.0" -smpl_jwt = "0.7" -thiserror = "1.0" -time = { version = "0.3" } -tracing = "0.1" -testcontainers = "0.14" -tokio = "1.21" -tracing-subscriber = "0.3" +anyhow = { version = "1.0" } +base64 = { version = "0.21" } +goauth = { version = "0.13" } +proc-macro2 = { version = "1.0" } +quote = { version = "1.0" } +reqwest = { version = "0.11" } +serde = { version = "1.0" } +serde_json = { version = "1.0" } +smpl_jwt = { version = "0.7" } +syn = { version = "2.0" } +testcontainers = { version = "0.15" } +testcontainers-modules = { version = "0.1", features = [ "google_cloud_sdk_emulators" ] } +thiserror = { version = "1.0" } +time = { version = "0.3" } +tokio = { version = "1" } +tracing = { version = "0.1" } +tracing-subscriber = { version = "0.3" } diff --git a/README.md b/README.md index 9a3227a..fd39014 100644 --- a/README.md +++ b/README.md @@ -97,3 +97,4 @@ authority to do so. This code is open source software licensed under the [Apache 2.0 License]("http://www.apache.org/licenses/LICENSE-2.0.html"). + diff --git a/justfile b/justfile new file mode 100644 index 0000000..b99ca07 --- /dev/null +++ b/justfile @@ -0,0 +1,18 @@ +set shell := ["bash", "-uc"] + +check: + cargo check --tests + +fmt: + cargo +nightly fmt + +fmt_check: + cargo +nightly fmt --check + +lint: + cargo clippy --no-deps -- -D warnings + +test: + cargo test + +all: fmt check lint test diff --git a/pub-sub-client-derive/Cargo.toml b/pub-sub-client-derive/Cargo.toml index 5222390..56f8f4c 100644 --- a/pub-sub-client-derive/Cargo.toml +++ b/pub-sub-client-derive/Cargo.toml @@ -1,19 +1,20 @@ [package] -name = "pub-sub-client-derive" -version= "0.11.1-alpha.0" -edition.workspace = true -description.workspace = true -authors.workspace = true -license.workspace = true -readme.workspace = true -homepage.workspace = true -repository.workspace = true -documentation.workspace = true +name = "pub-sub-client-derive" +version = "0.11.1-alpha.0" +description = { workspace = true } +edition = { workspace = true } +authors = { workspace = true } +license = { workspace = true } +readme = { workspace = true } +homepage = { workspace = true } +repository = { workspace = true } +documentation = { workspace = true } +publish = { workspace = true } [lib] proc-macro = true [dependencies] -proc-macro2 = "1.0" -quote = "1.0" -syn = "1.0" +proc-macro2 = { workspace = true } +quote = { workspace = true } +syn = { workspace = true } diff --git a/pub-sub-client-tests/Cargo.toml b/pub-sub-client-tests/Cargo.toml index 40ee9d9..9d9fdc4 100644 --- a/pub-sub-client-tests/Cargo.toml +++ b/pub-sub-client-tests/Cargo.toml @@ -1,23 +1,24 @@ [package] -name = "pub-sub-client-tests" -version= "0.11.1-alpha.0" -edition.workspace = true -description.workspace = true -authors.workspace = true -license.workspace = true -readme.workspace = true -homepage.workspace = true -repository.workspace = true -documentation.workspace = true -publish = false +name = "pub-sub-client-tests" +version = "0.11.1-alpha.0" +description = { workspace = true } +edition = { workspace = true } +authors = { workspace = true } +license = { workspace = true } +readme = { workspace = true } +homepage = { workspace = true } +repository = { workspace = true } +documentation = { workspace = true } +publish = false [dev-dependencies] -pub-sub-client = { version = "=0.11.1-alpha.0", path = "../pub-sub-client", features = [ "derive" ] } -anyhow = { workspace = true } -base64 = { workspace = true } -reqwest = { workspace = true, features = [ "json" ] } -serde = { workspace = true, features = [ "derive" ] } -serde_json = { workspace = true } -testcontainers = { workspace = true } -tokio = { workspace = true, features = [ "full" ] } -tracing-subscriber = { workspace = true, features = [ "env-filter", "fmt", "json", "tracing-log" ] } +pub-sub-client = { version = "=0.11.1-alpha.0", path = "../pub-sub-client", features = [ "derive" ] } +anyhow = { workspace = true } +base64 = { workspace = true } +reqwest = { workspace = true, features = [ "json" ] } +serde = { workspace = true, features = [ "derive" ] } +serde_json = { workspace = true } +testcontainers = { workspace = true } +testcontainers-modules = { workspace = true } +tokio = { workspace = true, features = [ "full" ] } +tracing-subscriber = { workspace = true, features = [ "env-filter", "fmt", "json", "tracing-log" ] } diff --git a/pub-sub-client-tests/examples/transform.rs b/pub-sub-client-tests/examples/transform.rs index 10ca454..d2de8ea 100644 --- a/pub-sub-client-tests/examples/transform.rs +++ b/pub-sub-client-tests/examples/transform.rs @@ -1,4 +1,5 @@ use anyhow::anyhow; +use base64::{engine::general_purpose::STANDARD, Engine}; use pub_sub_client::{ Error, PubSubClient, PublishedMessage, PulledMessage, RawPublishedMessage, RawPulledMessageEnvelope, @@ -40,7 +41,7 @@ async fn run() -> Result<(), Error> { let messages = vec!["Hello", "from pub-sub-client"] .iter() - .map(|s| base64::encode(json!({ "text": s }).to_string())) + .map(|s| STANDARD.encode(json!({ "text": s }).to_string())) .map(|data| { RawPublishedMessage::new(data) .with_attributes(HashMap::from([("type".to_string(), "Foo".to_string())])) diff --git a/pub-sub-client-tests/tests/test.rs b/pub-sub-client-tests/tests/test.rs index b10e3de..3c4242f 100644 --- a/pub-sub-client-tests/tests/test.rs +++ b/pub-sub-client-tests/tests/test.rs @@ -1,12 +1,11 @@ +use base64::{engine::general_purpose::STANDARD, Engine}; use pub_sub_client::{PubSubClient, PublishedMessage, RawPublishedMessage}; use reqwest::{Client, StatusCode}; use serde::{Deserialize, Serialize}; use serde_json::json; use std::{collections::HashMap, env, time::Duration, vec}; -use testcontainers::{ - clients::Cli, - images::google_cloud_sdk_emulators::{CloudSdk, PUBSUB_PORT}, -}; +use testcontainers::clients::Cli; +use testcontainers_modules::google_cloud_sdk_emulators::{CloudSdk, PUBSUB_PORT}; const PROJECT_ID: &str = "active-road-365118"; const TOPIC_ID: &str = "test"; @@ -64,7 +63,7 @@ async fn test() { let pub_sub_client = pub_sub_client.unwrap(); // Publish raw - let foo = base64::encode(json!({ "Foo": { "text": TEXT } }).to_string()); + let foo = STANDARD.encode(json!({ "Foo": { "text": TEXT } }).to_string()); let messages = vec![RawPublishedMessage::new(foo)]; let result = pub_sub_client .publish_raw(TOPIC_ID, messages, Some(Duration::from_secs(10))) diff --git a/pub-sub-client/Cargo.toml b/pub-sub-client/Cargo.toml index 8cebbe8..515da08 100644 --- a/pub-sub-client/Cargo.toml +++ b/pub-sub-client/Cargo.toml @@ -1,15 +1,16 @@ [package] -name = "pub-sub-client" -version= "0.11.1-alpha.0" -edition.workspace = true -description.workspace = true -authors.workspace = true -license.workspace = true -readme.workspace = true -homepage.workspace = true -repository.workspace = true -documentation.workspace = true -exclude = [ "tests" ] +name = "pub-sub-client" +version = "0.11.1-alpha.0" +description = { workspace = true } +edition = { workspace = true } +authors = { workspace = true } +license = { workspace = true } +readme = { workspace = true } +homepage = { workspace = true } +repository = { workspace = true } +documentation = { workspace = true } +publish = { workspace = true } +exclude = [ "tests" ] [features] derive = [ "pub-sub-client-derive" ] diff --git a/pub-sub-client/src/publisher/mod.rs b/pub-sub-client/src/publisher/mod.rs index dc81671..c988bf6 100644 --- a/pub-sub-client/src/publisher/mod.rs +++ b/pub-sub-client/src/publisher/mod.rs @@ -1,4 +1,5 @@ use crate::{error::Error, PubSubClient}; +use base64::{engine::general_purpose::STANDARD, Engine}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, fmt::Debug, time::Duration}; use tracing::debug; @@ -101,7 +102,7 @@ impl PubSubClient { .map_err(|source| Error::Serialize { source })? .into_iter() .map(|(bytes, attributes)| RawPublishedMessage { - data: Some(base64::encode(bytes)), + data: Some(STANDARD.encode(bytes)), attributes, ordering_key, }) diff --git a/pub-sub-client/src/subscriber/mod.rs b/pub-sub-client/src/subscriber/mod.rs index a5ee506..bb5f144 100644 --- a/pub-sub-client/src/subscriber/mod.rs +++ b/pub-sub-client/src/subscriber/mod.rs @@ -1,4 +1,5 @@ use crate::{error::Error, PubSubClient}; +use base64::{engine::general_purpose::STANDARD, Engine}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_json::Value; use std::{collections::HashMap, error::Error as StdError, fmt::Debug, time::Duration}; @@ -164,7 +165,11 @@ where .data .as_ref() .ok_or(Error::NoData) - .and_then(|data| base64::decode(data).map_err(|source| Error::NoBase64 { source })) + .and_then(|data| { + STANDARD + .decode(data) + .map_err(|source| Error::NoBase64 { source }) + }) .and_then(|bytes| { serde_json::from_slice::(&bytes) .map_err(|source| Error::Deserialize { source }) @@ -204,6 +209,7 @@ where mod tests { use super::{deserialize, RawPulledMessage, RawPulledMessageEnvelope}; use anyhow::anyhow; + use base64::{engine::general_purpose::STANDARD, Engine}; use serde::Deserialize; use serde_json::{json, Value}; use std::{collections::HashMap, error::Error as StdError}; @@ -223,7 +229,7 @@ mod tests { RawPulledMessageEnvelope { ack_id: "ack_id".to_string(), message: RawPulledMessage { - data: Some(base64::encode(json!({"text": "test"}).to_string())), + data: Some(STANDARD.encode(json!({"text": "test"}).to_string())), attributes: Some(HashMap::from([("type".to_string(), "Foo".to_string())])), id: "id".to_string(), publish_time: OffsetDateTime::parse(TIME, &Rfc3339).unwrap(), @@ -234,7 +240,7 @@ mod tests { RawPulledMessageEnvelope { ack_id: "ack_id".to_string(), message: RawPulledMessage { - data: Some(base64::encode(json!({"Bar": {"text": "test"}}).to_string())), + data: Some(STANDARD.encode(json!({"Bar": {"text": "test"}}).to_string())), attributes: Some(HashMap::from([("version".to_string(), "v2".to_string())])), id: "id".to_string(), publish_time: OffsetDateTime::parse(TIME, &Rfc3339).unwrap(),