Skip to content

Commit

Permalink
chore: updates (#17)
Browse files Browse the repository at this point in the history
* chore: updates

* build: use just

* fixes

* doc

* fix: GH workflow
  • Loading branch information
hseeberger authored Oct 11, 2023
1 parent 39b7937 commit 840c38d
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 94 deletions.
53 changes: 27 additions & 26 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 25 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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!
Expand All @@ -8,21 +13,27 @@ edition = "2021"
description = "Google Cloud Pub/Sub client library"
authors = [ "Heiko Seeberger <[email protected]>" ]
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" }
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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").

18 changes: 18 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
27 changes: 14 additions & 13 deletions pub-sub-client-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
41 changes: 21 additions & 20 deletions pub-sub-client-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" ] }
3 changes: 2 additions & 1 deletion pub-sub-client-tests/examples/transform.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::anyhow;
use base64::{engine::general_purpose::STANDARD, Engine};
use pub_sub_client::{
Error, PubSubClient, PublishedMessage, PulledMessage, RawPublishedMessage,
RawPulledMessageEnvelope,
Expand Down Expand Up @@ -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())]))
Expand Down
9 changes: 4 additions & 5 deletions pub-sub-client-tests/tests/test.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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)))
Expand Down
23 changes: 12 additions & 11 deletions pub-sub-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" ]
Expand Down
3 changes: 2 additions & 1 deletion pub-sub-client/src/publisher/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
})
Expand Down
12 changes: 9 additions & 3 deletions pub-sub-client/src/subscriber/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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::<Value>(&bytes)
.map_err(|source| Error::Deserialize { source })
Expand Down Expand Up @@ -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};
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 840c38d

Please sign in to comment.