From e925e2b201855e223e8a859ceabceac52d05c874 Mon Sep 17 00:00:00 2001 From: Dan Ditomaso Date: Wed, 8 Oct 2025 17:39:16 -0400 Subject: [PATCH] ci: fix publish github action workflow for publishing to JSR, Cargo, and NPM --- .github/workflows/publish.yml | 124 ++++++++++++++++++++++++--- buf.gen.yaml | 10 +++ buf.yaml | 32 ++++--- 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/deno.lock | 16 ++++ packages/ts/lib/.gitkeep | 0 packages/ts/mod.ts | 20 +++++ packages/ts/package.json | 32 +++++++ 12 files changed, 349 insertions(+), 25 deletions(-) create mode 100644 buf.gen.yaml 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/deno.lock create mode 100644 packages/ts/lib/.gitkeep create mode 100644 packages/ts/mod.ts create mode 100755 packages/ts/package.json diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 70c229e..d375521 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,30 +1,132 @@ -name: Push new version to schema registry - -permissions: - contents: read +name: Publish to Cargo, JSR, & NPM on: push: tags: - - "**" + - "v*" + workflow_dispatch: + inputs: + version: + description: "Version to publish (e.g. v1.2.3). Used when manually dispatching." + required: false + type: string + +permissions: write-all jobs: - push_to_registry: - runs-on: ubuntu-latest - + codegen: + runs-on: ubuntu-24.04 steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Show files exist + run: | + set -euxo pipefail + ls -la packages/ts || true + ls -la packages/rust || true + cat packages/ts/deno.json + cat packages/ts/package.json + cat packages/rust/Cargo.toml + + - name: Determine VERSION + run: | + set -euo pipefail + if [ "${{ github.ref_type }}" = "tag" ]; then + VERSION="${{ github.ref_name }}" + elif [ -n "${{ inputs.version || '' }}" ]; then + VERSION="${{ inputs.version }}" + else + echo "No tag ref and no 'version' input. Provide a tag (push a tag) or pass inputs.version." >&2 + exit 1 + fi + # If you don't want the leading 'v' inside files, strip it: + STRIPPED="${VERSION#v}" + echo "VERSION=$STRIPPED" >> "$GITHUB_ENV" + echo "Resolved VERSION=$STRIPPED" + + - name: Set Package Versions to current tag + run: | + set -euxo pipefail + for f in \ + packages/ts/deno.json \ + packages/ts/package.json \ + packages/rust/Cargo.toml + do + test -f "$f" || { echo "Missing $f" >&2; exit 1; } + # replace __PACKAGE_VERSION__ with env VERSION + sed -i "s/__PACKAGE_VERSION__/${VERSION//\//-}/g" "$f" + done - name: Setup Buf - uses: bufbuild/buf-action@v1.2.0 + uses: bufbuild/buf-setup-action@main with: github_token: ${{ github.token }} - token: ${{ secrets.BUF_TOKEN }} - setup_only: true + + - name: Generate code + run: buf generate + + - name: Copy license & README + run: | + cp LICENSE packages/ts + cp LICENSE packages/rust + cp README.md packages/ts + cp README.md 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 env: BUF_TOKEN: ${{ secrets.BUF_TOKEN }} run: | 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: Remove package.json (JSR doesn’t need it) + run: rm -f package.json + - 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 \ No newline at end of file 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/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..99b801a --- /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.2.3" + }, + "publish": { + "exclude": [ + "!lib" + ] + } +} diff --git a/packages/ts/deno.lock b/packages/ts/deno.lock new file mode 100644 index 0000000..d39f28e --- /dev/null +++ b/packages/ts/deno.lock @@ -0,0 +1,16 @@ +{ + "version": "4", + "specifiers": { + "npm:@bufbuild/protobuf@^2.2.3": "2.2.3" + }, + "npm": { + "@bufbuild/protobuf@2.2.3": { + "integrity": "sha512-tFQoXHJdkEOSwj5tRIZSPNUuXK3RaR7T1nUrPgbYX1pUbvqqaaZAsfo+NXBPsz5rZMSKVFrgK1WL8Q/MSLvprg==" + } + }, + "workspace": { + "dependencies": [ + "npm:@bufbuild/protobuf@^2.2.3" + ] + } +} 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..b043e49 --- /dev/null +++ b/packages/ts/mod.ts @@ -0,0 +1,20 @@ +export * as Admin from "./lib/admin_pb.ts"; +export * as AppOnly from "./lib/apponly_pb.ts"; +export * as ATAK from "./lib/atak_pb.ts"; +export * as CannedMessages from "./lib/cannedmessages_pb.ts"; +export * as Channel from "./lib/channel_pb.ts"; +export * as ClientOnly from "./lib/clientonly_pb.ts"; +export * as Config from "./lib/config_pb.ts"; +export * as ConnectionStatus from "./lib/connection_status_pb.ts"; +export * as LocalOnly from "./lib/localonly_pb.ts"; +export * as Mesh from "./lib/mesh_pb.ts"; +export * as ModuleConfig from "./lib/module_config_pb.ts"; +export * as Mqtt from "./lib/mqtt_pb.ts"; +export * as PaxCount from "./lib/paxcount_pb.ts"; +export * as Portnums from "./lib/portnums_pb.ts"; +export * as PowerMon from "./lib/powermon_pb.ts"; +export * as RemoteHardware from "./lib/remote_hardware_pb.ts"; +export * as Rtttl from "./lib/rtttl_pb.ts"; +export * as StoreForward from "./lib/storeforward_pb.ts"; +export * as Telemetry from "./lib/telemetry_pb.ts"; +export * as Xmodem from "./lib/xmodem_pb.ts"; diff --git a/packages/ts/package.json b/packages/ts/package.json new file mode 100755 index 0000000..04f1162 --- /dev/null +++ b/packages/ts/package.json @@ -0,0 +1,32 @@ +{ + "name": "@meshtastic/protobufs", + "description": "Protobuf definitions for the Meshtastic project", + "version": "__PACKAGE_VERSION__", + "homepage": "https://github.com/meshtastic/protobufs", + "license": "GPLV3", + "publishConfig": { + "access": "public" + }, + "type": "module", + "main": "./dist/mod.js", + "module": "./dist/mod.js", + "types": "./dist/mod.d.ts", + "dependencies": { + "@bufbuild/protobuf": "^2.2.3" + }, + "devDependencies": { + "tsdown": "^0.13.4", + "typescript": "^5.8.3" + }, + "scripts": { + "build": "tsdown" + }, + "tsdown": { + "entry": "mod.ts", + "dts": true, + "format": [ + "esm" + ], + "splitting": false + } +}