From 579c13b39b68d60933d25f8c94dc463adb06a789 Mon Sep 17 00:00:00 2001 From: Marco Kirchner Date: Tue, 2 Apr 2024 17:35:55 +0200 Subject: [PATCH] publish on crates.io --- .github/workflows/rust-build-release.yml | 33 +++++++++- Cargo.lock | 16 ++--- Cargo.toml | 9 ++- autokuma/Cargo.toml | 7 ++- example/Cargo.toml | 11 ---- kuma-cli/Cargo.toml | 7 ++- kuma-client/Cargo.toml | 7 ++- kuma-client/src/client.rs | 80 +++++++++++++++++++++++- kuma.db | 0 release.toml | 2 + 10 files changed, 143 insertions(+), 29 deletions(-) delete mode 100644 example/Cargo.toml delete mode 100644 kuma.db create mode 100644 release.toml diff --git a/.github/workflows/rust-build-release.yml b/.github/workflows/rust-build-release.yml index 4e6f76d..c8da739 100644 --- a/.github/workflows/rust-build-release.yml +++ b/.github/workflows/rust-build-release.yml @@ -72,7 +72,7 @@ jobs: name: autokuma-${{ matrix.os }} path: dist/* - release: + github-release: needs: [build] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') @@ -83,6 +83,11 @@ jobs: with: fetch-depth: 0 + - name: Install cargo-release + uses: taiki-e/install-action@v2 + with: + tool: cargo-release + - name: Parse Changelog id: changelog uses: coditory/changelog-parser@v1 @@ -94,11 +99,35 @@ jobs: pattern: autokuma-* merge-multiple: true + - name: Publish to crates.io + shell: bash + run: cargo release --workspace --execute --no-confirm + - name: Create Release id: create_release uses: softprops/action-gh-release@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - name: Release ${{ github.ref }} + name: Release ${{ github.ref_name }} body: ${{ steps.changelog.outputs.description }} files: dist/* + + crates-io: + needs: [build] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install cargo-release + uses: taiki-e/install-action@v2 + with: + tool: cargo-release + + - name: Publish to crates.io + shell: bash + run: cargo release --workspace --execute --no-confirm "${GITHUB_REF_NAME#v}" diff --git a/Cargo.lock b/Cargo.lock index 43f35f6..ca7b270 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,14 +136,14 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "autokuma" -version = "0.0.0" +version = "0.0.3" dependencies = [ "bollard", "config", "derivative", "futures-util", "itertools", - "kuma_client", + "kuma-client", "log", "pretty_env_logger", "rust_socketio", @@ -1187,13 +1187,13 @@ dependencies = [ [[package]] name = "kuma-cli" -version = "0.0.0" +version = "0.0.3" dependencies = [ "clap", "config", "const-str", "dirs", - "kuma_client", + "kuma-client", "log", "pretty_env_logger", "serde", @@ -1204,8 +1204,8 @@ dependencies = [ ] [[package]] -name = "kuma_client" -version = "0.0.0" +name = "kuma-client" +version = "0.0.3" dependencies = [ "config", "derivative", @@ -2136,9 +2136,9 @@ dependencies = [ [[package]] name = "shadow-rs" -version = "0.27.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc90f58262c9783799e542c15a936977c32f59f5c9637b9a5ea09ec6a7adaa25" +checksum = "7960cbd6ba74691bb15e7ebf97f7136bd02d1115f5695a58c1f31d5645750128" dependencies = [ "const_format", "git2", diff --git a/Cargo.toml b/Cargo.toml index 7f63272..d3d9755 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,11 @@ members = ["autokuma", "kuma-cli", "kuma-client"] resolver = "2" [workspace.package] -version = "0.0.0" +version = "0.0.3" edition = "2021" +authors = ["Marco Kirchner "] +license = "MIT" +repository = "https://github.com/BigBoot/AutoKuma" [workspace.dependencies] bollard = { version = "0.16.0" } @@ -29,10 +32,10 @@ serde_repr = { version = "0.1.18" } serde_with = { version = "3.4.0", features = ["time_0_3"] } serde-inline-default = { version = "0.2.0" } serde_yaml = { version = "0.9.30" } -shadow-rs = { version = "*" } +shadow-rs = { version = "0.27.1" } strum = { version = "0.26.1", features = ["derive"] } thiserror = { version = "1.0.56" } time = { version = "0.3.31", features = ["serde"] } tokio = { version = "1.35.1", features = ["full"] } toml = { version = "0.8.8" } -url = { version = "*", features = ["serde"] } +url = { version = "2.5.0", features = ["serde"] } diff --git a/autokuma/Cargo.toml b/autokuma/Cargo.toml index f1a9acf..d031efc 100644 --- a/autokuma/Cargo.toml +++ b/autokuma/Cargo.toml @@ -1,10 +1,15 @@ [package] name = "autokuma" +description = "Automates the creation of Uptime Kuma monitors based on Docker container labels" version.workspace = true edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +readme = "../README.md" [dependencies] -kuma_client = { path = "../kuma-client" } +kuma-client = { path = "../kuma-client", version = "0.0.3" } bollard = { workspace = true } config = { workspace = true } diff --git a/example/Cargo.toml b/example/Cargo.toml deleted file mode 100644 index 396fc09..0000000 --- a/example/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "example" -version.workspace = true -edition.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -kuma_client = { path = "../kuma-client" } -tokio = { version = "1.35.1", features = ["full"] } -serde_json = { version = "1.0.111" } diff --git a/kuma-cli/Cargo.toml b/kuma-cli/Cargo.toml index abac5a1..1e5ab7f 100644 --- a/kuma-cli/Cargo.toml +++ b/kuma-cli/Cargo.toml @@ -1,14 +1,19 @@ [package] name = "kuma-cli" +description = "CLI tool for managing and interacting with Uptime Kuma" version.workspace = true edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +readme = "../README.md" [[bin]] name = "kuma" path = "src/main.rs" [dependencies] -kuma_client = { path = "../kuma-client" } +kuma-client = { path = "../kuma-client", version = "0.0.3" } clap = { workspace = true } config = { workspace = true } diff --git a/kuma-client/Cargo.toml b/kuma-client/Cargo.toml index e94be17..47c79ee 100644 --- a/kuma-client/Cargo.toml +++ b/kuma-client/Cargo.toml @@ -1,7 +1,12 @@ [package] -name = "kuma_client" +name = "kuma-client" +description = "Rust wrapper for the Uptime Kuma Socket.IO API" version.workspace = true edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +readme = "../README.md" [dependencies] config = { workspace = true } diff --git a/kuma-client/src/client.rs b/kuma-client/src/client.rs index d91cda7..2272007 100644 --- a/kuma-client/src/client.rs +++ b/kuma-client/src/client.rs @@ -1058,12 +1058,88 @@ impl Worker { } /// A client for interacting with Uptime Kuma. +/// +/// Example: +/// ``` +/// // Connect to the server +/// let client = Client::connect(Config { +/// url: Url::parse("http://localhost:3001").expect("Invalid URL"), +/// username: Some("Username".to_owned()), +/// password: Some("Password".to_owned()), +/// ..Default::default() +/// }) +/// .await +/// .expect("Failed to connect to server"); +/// +/// // Create a tag +/// let tag_definition = client +/// .add_tag(TagDefinition { +/// name: Some("example_tag".to_owned()), +/// color: Some("red".to_owned()), +/// ..Default::default() +/// }) +/// .await +/// .expect("Failed to add tag"); +/// +/// // Create a group +/// let group = client +/// .add_monitor(MonitorGroup { +/// name: Some("Example Group".to_owned()), +/// tags: vec![Tag { +/// tag_id: tag_definition.tag_id, +/// value: Some("example_group".to_owned()), +/// ..Default::default() +/// }], +/// ..Default::default() +/// }) +/// .await +/// .expect("Failed to add group"); +/// +/// // Createa a notification +/// let notification = client +/// .add_notification(Notification { +/// name: Some("Example Notification".to_owned()), +/// config: Some(serde_json::json!({ +/// "webhookURL": "https://webhook.site/304eeaf2-0248-49be-8985-2c86175520ca", +/// "webhookContentType": "json" +/// })), +/// ..Default::default() +/// }) +/// .await +/// .expect("Failed to add notification"); +/// +/// // Create a monitor +/// client +/// .add_monitor(MonitorHttp { +/// name: Some("Monitor Name".to_owned()), +/// url: Some("https://example.com".to_owned()), +/// parent: group.common().id().clone(), +/// tags: vec![Tag { +/// tag_id: tag_definition.tag_id, +/// value: Some("example_monitor".to_owned()), +/// ..Default::default() +/// }], +/// notification_id_list: Some( +/// vec![( +/// notification.id.expect("No notification ID").to_string(), +/// true, +/// )] +/// .into_iter() +/// .collect(), +/// ), +/// ..Default::default() +/// }) +/// .await +/// .expect("Failed to add monitor"); +/// +/// let monitors = client.get_monitors().await.expect("Failed to get monitors"); +/// println!("{:?}", monitors); +/// ``` +/// pub struct Client { worker: Arc, } - impl Client { - /// Establishes a connection to Uptime Kuma with the provided configuration. pub async fn connect(config: Config) -> Result { let worker = Worker::new(config); worker.connect().await?; diff --git a/kuma.db b/kuma.db deleted file mode 100644 index e69de29..0000000 diff --git a/release.toml b/release.toml new file mode 100644 index 0000000..17fcc6e --- /dev/null +++ b/release.toml @@ -0,0 +1,2 @@ +push = false +tag = false