From 5ff4ed02480cd1ca7b97274208af4f4de9b640ac Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Sun, 6 Oct 2024 22:11:45 +1000 Subject: [PATCH] Enable publishing to Cargo & JSR --- .github/workflows/ci.yml | 27 ----- .github/workflows/publish.yml | 74 +++++++++--- .github/workflows/pull_request.yml | 28 ----- .gitignore | 4 + buf.gen.yaml | 10 ++ buf.yaml | 32 +++--- meshtastic/admin.proto | 10 +- meshtastic/apponly.proto | 4 +- meshtastic/clientonly.proto | 4 +- .../{ => device_only}/deviceonly.options | 0 meshtastic/{ => device_only}/deviceonly.proto | 10 +- .../device_only/nanopb.proto | 0 meshtastic/localonly.proto | 4 +- meshtastic/mesh.proto | 34 +++--- meshtastic/mqtt.proto | 4 +- packages/rust/Cargo.lock | 105 ++++++++++++++++++ packages/rust/Cargo.toml | 15 +++ packages/rust/src/generated/.gitkeep | 0 packages/rust/src/lib.rs | 5 + packages/ts/deno.json | 15 +++ packages/ts/lib/.gitkeep | 0 packages/ts/mod.ts | 43 +++++++ 22 files changed, 308 insertions(+), 120 deletions(-) delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/pull_request.yml create mode 100644 .gitignore create mode 100644 buf.gen.yaml rename meshtastic/{ => device_only}/deviceonly.options (100%) rename meshtastic/{ => device_only}/deviceonly.proto (97%) rename nanopb.proto => meshtastic/device_only/nanopb.proto (100%) create mode 100644 packages/rust/Cargo.lock create mode 100644 packages/rust/Cargo.toml create mode 100644 packages/rust/src/generated/.gitkeep create mode 100644 packages/rust/src/lib.rs create mode 100644 packages/ts/deno.json create mode 100644 packages/ts/lib/.gitkeep create mode 100644 packages/ts/mod.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 1023c96..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Push commit to schema registry - -permissions: - contents: read - -on: - push: - branches: - - master - -jobs: - push_to_registry: - name: Push to schema registry - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Buf - uses: bufbuild/buf-setup-action@v1.30.0 - with: - github_token: ${{ github.token }} - - - name: Push to schema registry - uses: bufbuild/buf-push-action@v1.2.0 - with: - buf_token: ${{ secrets.BUF_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8ea8360..53252e7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,30 +1,72 @@ -name: Push new version to schema registry - -permissions: - contents: read +name: Publish to Cargo & JSR on: push: tags: - "**" -jobs: - push_to_registry: - runs-on: ubuntu-latest +permissions: write-all +jobs: + codegen: + runs-on: ubuntu-24.04 steps: - name: Checkout code uses: actions/checkout@v4 - + - name: Set Package Versions to current tag + run: sed -i "s/__PACKAGE_VERSION__/$(echo $GITHUB_REF | cut -d '/' -f 3)/g" packages/ts/deno.json \ + && sed -i "s/__PACKAGE_VERSION__/$(echo $GITHUB_REF | cut -d '/' -f 3)/g" packages/rust/Cargo.toml - name: Setup Buf - uses: bufbuild/buf-setup-action@v1.30.0 + uses: bufbuild/buf-setup-action@main with: github_token: ${{ github.token }} + - name: Generate code + run: buf generate dewars + - name: Copy license + run: cp LICENSE packages/ts && cp LICENSE packages/rust + - name: Upload Rust code + uses: actions/upload-artifact@v4 + with: + name: rust_code + path: packages/rust + - name: Upload TypeScript code + uses: actions/upload-artifact@v4 + with: + name: ts_code + path: packages/ts - - name: Push to schema registry - # uses: bufbuild/buf-push-action@v1 - # with: - # buf_token: ${{ secrets.BUF_TOKEN }} - run: | - export BUF_TOKEN=${{ secrets.BUF_TOKEN }} - buf push --tag ${{ github.ref_name }} + publish-jsr: + runs-on: ubuntu-24.04 + needs: codegen + permissions: + contents: read + id-token: write + steps: + - name: Download TypeScript code + uses: actions/download-artifact@v4 + with: + name: ts_code + - name: Set up Deno + uses: denoland/setup-deno@main + with: + deno-version: rc + - name: Publish to JSR + run: deno publish --unstable-sloppy-imports + + publish-cargo: + runs-on: ubuntu-24.04 + needs: codegen + steps: + - name: Download Rust code + uses: actions/download-artifact@v4 + with: + name: rust_code + - name: Set up Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Check Library + run: cargo check + - name: Publish to crates.io + uses: katyo/publish-crates@v2 + with: + registry-token: ${{ secrets.CARGO_TOKEN }} + ignore-unpublished-changes: true diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml deleted file mode 100644 index 179d09a..0000000 --- a/.github/workflows/pull_request.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: pull-request - -permissions: - contents: read - -on: pull_request -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Buf - uses: bufbuild/buf-setup-action@v1.30.0 - with: - github_token: ${{ github.token }} - - - name: Lint - uses: bufbuild/buf-lint-action@v1.1.1 - - - name: Push to schema registry - uses: bufbuild/buf-push-action@v1.2.0 - if: ${{ github.event_name != 'pull_request_target' && github.event_name != 'pull_request' }} - with: - buf_token: ${{ secrets.BUF_TOKEN }} - draft: ${{ github.ref_name != 'master'}} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f87222a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +packages/ts/lib/* +packages/rust/src/generated/* +packages/rust/target +!.gitkeep diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 0000000..1306002 --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,10 @@ +version: v2 +plugins: + - remote: buf.build/bufbuild/es:v2.1.0 + out: packages/ts/lib + opt: target=ts + - remote: buf.build/community/neoeinstein-prost:v0.4.0 + out: packages/rust/src/generated + - remote: buf.build/community/neoeinstein-prost-crate:v0.4.1 + out: packages/rust/src/generated + opt: no_features diff --git a/buf.yaml b/buf.yaml index 642e538..9d85f4e 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,14 +1,18 @@ -version: v1 -name: buf.build/meshtastic/protobufs -deps: [] -build: - excludes: [] -breaking: - use: - - FILE -lint: - ignore_only: - PACKAGE_DEFINED: - - nanopb.proto - use: - - MINIMAL +version: v2 +modules: + - path: meshtastic + name: buf.build/meshtastic/protobufs + excludes: + - meshtastic/device_only/ + lint: + use: + - MINIMAL + except: + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true + breaking: + use: + - FILE + except: + - EXTENSION_NO_DELETE + - FIELD_SAME_DEFAULT diff --git a/meshtastic/admin.proto b/meshtastic/admin.proto index 48d3392..4849175 100644 --- a/meshtastic/admin.proto +++ b/meshtastic/admin.proto @@ -2,11 +2,11 @@ syntax = "proto3"; package meshtastic; -import "meshtastic/channel.proto"; -import "meshtastic/config.proto"; -import "meshtastic/connection_status.proto"; -import "meshtastic/mesh.proto"; -import "meshtastic/module_config.proto"; +import "channel.proto"; +import "config.proto"; +import "connection_status.proto"; +import "mesh.proto"; +import "module_config.proto"; option csharp_namespace = "Meshtastic.Protobufs"; option go_package = "github.com/meshtastic/go/generated"; diff --git a/meshtastic/apponly.proto b/meshtastic/apponly.proto index 100833f..50eb196 100644 --- a/meshtastic/apponly.proto +++ b/meshtastic/apponly.proto @@ -2,8 +2,8 @@ syntax = "proto3"; package meshtastic; -import "meshtastic/channel.proto"; -import "meshtastic/config.proto"; +import "channel.proto"; +import "config.proto"; option csharp_namespace = "Meshtastic.Protobufs"; option go_package = "github.com/meshtastic/go/generated"; diff --git a/meshtastic/clientonly.proto b/meshtastic/clientonly.proto index 2b919ef..e76be6c 100644 --- a/meshtastic/clientonly.proto +++ b/meshtastic/clientonly.proto @@ -2,8 +2,8 @@ syntax = "proto3"; package meshtastic; -import "meshtastic/localonly.proto"; -import "meshtastic/mesh.proto"; +import "localonly.proto"; +import "mesh.proto"; option csharp_namespace = "Meshtastic.Protobufs"; option go_package = "github.com/meshtastic/go/generated"; diff --git a/meshtastic/deviceonly.options b/meshtastic/device_only/deviceonly.options similarity index 100% rename from meshtastic/deviceonly.options rename to meshtastic/device_only/deviceonly.options diff --git a/meshtastic/deviceonly.proto b/meshtastic/device_only/deviceonly.proto similarity index 97% rename from meshtastic/deviceonly.proto rename to meshtastic/device_only/deviceonly.proto index 91367bf..ce777df 100644 --- a/meshtastic/deviceonly.proto +++ b/meshtastic/device_only/deviceonly.proto @@ -2,11 +2,11 @@ syntax = "proto3"; package meshtastic; -import "meshtastic/channel.proto"; -import "meshtastic/localonly.proto"; -import "meshtastic/mesh.proto"; -import "meshtastic/telemetry.proto"; -import "meshtastic/config.proto"; +import "channel.proto"; +import "localonly.proto"; +import "mesh.proto"; +import "telemetry.proto"; +import "config.proto"; import "nanopb.proto"; option csharp_namespace = "Meshtastic.Protobufs"; diff --git a/nanopb.proto b/meshtastic/device_only/nanopb.proto similarity index 100% rename from nanopb.proto rename to meshtastic/device_only/nanopb.proto diff --git a/meshtastic/localonly.proto b/meshtastic/localonly.proto index bcb2796..ab11c7c 100644 --- a/meshtastic/localonly.proto +++ b/meshtastic/localonly.proto @@ -2,8 +2,8 @@ syntax = "proto3"; package meshtastic; -import "meshtastic/config.proto"; -import "meshtastic/module_config.proto"; +import "config.proto"; +import "module_config.proto"; option csharp_namespace = "Meshtastic.Protobufs"; option go_package = "github.com/meshtastic/go/generated"; diff --git a/meshtastic/mesh.proto b/meshtastic/mesh.proto index 6b9be53..9f35056 100644 --- a/meshtastic/mesh.proto +++ b/meshtastic/mesh.proto @@ -2,12 +2,12 @@ syntax = "proto3"; package meshtastic; -import "meshtastic/channel.proto"; -import "meshtastic/config.proto"; -import "meshtastic/module_config.proto"; -import "meshtastic/portnums.proto"; -import "meshtastic/telemetry.proto"; -import "meshtastic/xmodem.proto"; +import "channel.proto"; +import "config.proto"; +import "module_config.proto"; +import "portnums.proto"; +import "telemetry.proto"; +import "xmodem.proto"; option csharp_namespace = "Meshtastic.Protobufs"; option go_package = "github.com/meshtastic/go/generated"; @@ -338,7 +338,7 @@ enum HardwareModel { * Heltec HRU-3601: https://heltec.org/project/hru-3601/ */ HELTEC_HRU_3601 = 23; - + /* * Heltec Wireless Bridge */ @@ -541,7 +541,7 @@ enum HardwareModel { CDEBYTE_EORA_S3 = 61; /* - * TWC_MESH_V4 + * TWC_MESH_V4 * Adafruit NRF52840 feather express with SX1262, SSD1306 OLED and NEO6M GPS */ TWC_MESH_V4 = 62; @@ -557,27 +557,27 @@ enum HardwareModel { * ESP32-D0WDQ6 With SX1276/SKY66122, SSD1306 OLED and No GPS */ RADIOMASTER_900_BANDIT_NANO = 64; - + /* * Heltec Capsule Sensor V3 with ESP32-S3 CPU, Portable LoRa device that can replace GNSS modules or sensors */ HELTEC_CAPSULE_SENSOR_V3 = 65; - + /* * Heltec Vision Master T190 with ESP32-S3 CPU, and a 1.90 inch TFT display */ HELTEC_VISION_MASTER_T190 = 66; - + /* * Heltec Vision Master E213 with ESP32-S3 CPU, and a 2.13 inch E-Ink display */ HELTEC_VISION_MASTER_E213 = 67; - + /* * Heltec Vision Master E290 with ESP32-S3 CPU, and a 2.9 inch E-Ink display */ HELTEC_VISION_MASTER_E290 = 68; - + /* * Heltec Mesh Node T114 board with nRF52840 CPU, and a 1.14 inch TFT display, Ultimate low-power design, * specifically adapted for the Meshtatic project @@ -593,7 +593,7 @@ enum HardwareModel { * Seeed studio T1000-E tracker card. NRF52840 w/ LR1110 radio, GPS, button, buzzer, and sensors. */ TRACKER_T1000_E = 71; - + /* * RAK3172 STM32WLE5 Module (https://store.rakwireless.com/products/wisduo-lpwan-module-rak3172) */ @@ -625,7 +625,7 @@ enum HardwareModel { * */ RP2040_FEATHER_RFM95 = 76; - + /* M5 esp32 based MCU modules with enclosure, TFT and LORA Shields. All Variants (Basic, Core, Fire, Core2, CoreS3, Paper) https://m5stack.com/ */ M5STACK_COREBASIC = 77; M5STACK_CORE2 = 78; @@ -635,7 +635,7 @@ enum HardwareModel { /* M5 esp32 based MCU modules with enclosure, TFT and LORA Shields. All Variants (Basic, Core, Fire, Core2, CoreS3, Paper) https://m5stack.com/ */ M5STACK_CORES3 = 80; - + /* Seeed XIAO S3 DK*/ SEEED_XIAO_S3 = 81; @@ -1069,7 +1069,7 @@ message MeshPacket { /* * Higher priority for specific message types (portnums) to distinguish between other reliable packets. - */ + */ HIGH = 100; /* diff --git a/meshtastic/mqtt.proto b/meshtastic/mqtt.proto index 2dbc820..487b848 100644 --- a/meshtastic/mqtt.proto +++ b/meshtastic/mqtt.proto @@ -2,8 +2,8 @@ syntax = "proto3"; package meshtastic; -import "meshtastic/config.proto"; -import "meshtastic/mesh.proto"; +import "config.proto"; +import "mesh.proto"; option csharp_namespace = "Meshtastic.Protobufs"; option go_package = "github.com/meshtastic/go/generated"; diff --git a/packages/rust/Cargo.lock b/packages/rust/Cargo.lock new file mode 100644 index 0000000..6b365f0 --- /dev/null +++ b/packages/rust/Cargo.lock @@ -0,0 +1,105 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "meshtastic_protobufs" +version = "2.5.5" +dependencies = [ + "prost", + "prost-types", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670" +dependencies = [ + "prost", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" diff --git a/packages/rust/Cargo.toml b/packages/rust/Cargo.toml new file mode 100644 index 0000000..ce52443 --- /dev/null +++ b/packages/rust/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "meshtastic_protobufs" +edition = "2021" +version = "__PACKAGE_VERSION__" +description = "Meshtastic Protobuf definitions" +repository = "https://github.com/meshtastic/protobufs" +license-file = "LICENSE" +include = [ + "**/*.rs", + "Cargo.toml", +] + +[dependencies] +prost = "0.13.3" +prost-types = "0.13.3" diff --git a/packages/rust/src/generated/.gitkeep b/packages/rust/src/generated/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/rust/src/lib.rs b/packages/rust/src/lib.rs new file mode 100644 index 0000000..a5bf95a --- /dev/null +++ b/packages/rust/src/lib.rs @@ -0,0 +1,5 @@ +extern crate prost; +extern crate core; +extern crate prost_types; + +include!("generated/mod.rs"); diff --git a/packages/ts/deno.json b/packages/ts/deno.json new file mode 100644 index 0000000..88caa96 --- /dev/null +++ b/packages/ts/deno.json @@ -0,0 +1,15 @@ +{ + "name": "@meshtastic/protobufs", + "version": "__PACKAGE_VERSION__", + "exports": { + ".": "./mod.ts" + }, + "imports": { + "@bufbuild/protobuf": "npm:@bufbuild/protobuf@^2.1.0" + }, + "publish": { + "exclude": [ + "!lib" + ] + } +} diff --git a/packages/ts/lib/.gitkeep b/packages/ts/lib/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/ts/mod.ts b/packages/ts/mod.ts new file mode 100644 index 0000000..fc519fe --- /dev/null +++ b/packages/ts/mod.ts @@ -0,0 +1,43 @@ +import * as Admin from "./lib/admin_pb.ts"; +import * as AppOnly from "./lib/apponly_pb.ts"; +import * as ATAK from "./lib/atak_pb.ts"; +import * as CannedMessages from "./lib/cannedmessages_pb.ts"; +import * as Channel from "./lib/channel_pb.ts"; +import * as ClientOnly from "./lib/clientonly_pb.ts"; +import * as Config from "./lib/config_pb.ts"; +import * as ConnectionStatus from "./lib/connection_status_pb.ts"; +import * as LocalOnly from "./lib/localonly_pb.ts"; +import * as Mesh from "./lib/mesh_pb.ts"; +import * as ModuleConfig from "./lib/module_config_pb.ts"; +import * as Mqtt from "./lib/mqtt_pb.ts"; +import * as PaxCount from "./lib/paxcount_pb.ts"; +import * as Portnums from "./lib/portnums_pb.ts"; +import * as PowerMon from "./lib/powermon_pb.ts"; +import * as RemoteHardware from "./lib/remote_hardware_pb.ts"; +import * as Rtttl from "./lib/rtttl_pb.ts"; +import * as StoreForward from "./lib/storeforward_pb.ts"; +import * as Telemetry from "./lib/telemetry_pb.ts"; +import * as Xmodem from "./lib/xmodem_pb.ts"; + +export const Protobuf = { + Admin, + AppOnly, + ATAK, + CannedMessages, + Channel, + ClientOnly, + Config, + ConnectionStatus, + LocalOnly, + Mesh, + ModuleConfig, + Mqtt, + PaxCount, + Portnums, + PowerMon, + RemoteHardware, + Rtttl, + StoreForward, + Telemetry, + Xmodem, +};