Skip to content

Commit cd5c83a

Browse files
authored
Merge pull request #790 from danditomaso/ci/jsr-publish-pipeline
ci: fix publish github action workflow for publishing to JSR, Cargo, …
2 parents ef173e3 + caecabe commit cd5c83a

File tree

12 files changed

+350
-27
lines changed

12 files changed

+350
-27
lines changed

.github/workflows/publish.yml

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,132 @@
1-
name: Push new version to schema registry
2-
3-
permissions:
4-
contents: read
1+
name: Publish to Cargo, JSR, & NPM
52

63
on:
74
push:
85
tags:
9-
- "**"
6+
- "v*"
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: "Version to publish (e.g. v1.2.3). Used when manually dispatching."
11+
required: false
12+
type: string
1013

11-
jobs:
12-
push_to_registry:
13-
runs-on: ubuntu-latest
14+
permissions: write-all
1415

16+
jobs:
17+
codegen:
18+
runs-on: ubuntu-24.04
1519
steps:
1620
- name: Checkout code
1721
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Show files exist
26+
run: |
27+
set -euxo pipefail
28+
ls -la packages/ts || true
29+
ls -la packages/rust || true
30+
cat packages/ts/deno.json
31+
cat packages/ts/package.json
32+
cat packages/rust/Cargo.toml
33+
34+
- name: Determine VERSION
35+
run: |
36+
set -euo pipefail
37+
if [ "${{ github.ref_type }}" = "tag" ]; then
38+
VERSION="${{ github.ref_name }}"
39+
elif [ -n "${{ inputs.version || '' }}" ]; then
40+
VERSION="${{ inputs.version }}"
41+
else
42+
echo "No tag ref and no 'version' input. Provide a tag (push a tag) or pass inputs.version." >&2
43+
exit 1
44+
fi
45+
# If you don't want the leading 'v' inside files, strip it:
46+
STRIPPED="${VERSION#v}"
47+
echo "VERSION=$STRIPPED" >> "$GITHUB_ENV"
48+
echo "Resolved VERSION=$STRIPPED"
49+
50+
- name: Set Package Versions to current tag
51+
run: |
52+
set -euxo pipefail
53+
for f in \
54+
packages/ts/deno.json \
55+
packages/ts/package.json \
56+
packages/rust/Cargo.toml
57+
do
58+
test -f "$f" || { echo "Missing $f" >&2; exit 1; }
59+
# replace __PACKAGE_VERSION__ with env VERSION
60+
sed -i "s/__PACKAGE_VERSION__/${VERSION//\//-}/g" "$f"
61+
done
1862
1963
- name: Setup Buf
20-
uses: bufbuild/buf-action@v1.2.0
64+
uses: bufbuild/buf-setup-action@main
2165
with:
2266
github_token: ${{ github.token }}
23-
token: ${{ secrets.BUF_TOKEN }}
24-
setup_only: true
67+
68+
- name: Generate code
69+
run: buf generate
70+
71+
- name: Copy license & README
72+
run: |
73+
cp LICENSE packages/ts
74+
cp LICENSE packages/rust
75+
cp README.md packages/ts
76+
cp README.md packages/rust
77+
78+
- name: Upload Rust code
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: rust_code
82+
path: packages/rust
83+
84+
- name: Upload TypeScript code
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: ts_code
88+
path: packages/ts
2589

2690
- name: Push to schema registry
2791
env:
2892
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
2993
run: |
3094
buf push --tag ${{ github.ref_name }}
95+
96+
publish-jsr:
97+
runs-on: ubuntu-24.04
98+
needs: codegen
99+
permissions:
100+
contents: read
101+
id-token: write
102+
steps:
103+
- name: Download TypeScript code
104+
uses: actions/download-artifact@v4
105+
with:
106+
name: ts_code
107+
- name: Remove package.json (JSR doesn’t need it)
108+
run: rm -f package.json
109+
- name: Set up Deno
110+
uses: denoland/setup-deno@main
111+
with:
112+
deno-version: rc
113+
- name: Publish to JSR
114+
run: deno publish --unstable-sloppy-imports
115+
116+
publish-cargo:
117+
runs-on: ubuntu-24.04
118+
needs: codegen
119+
steps:
120+
- name: Download Rust code
121+
uses: actions/download-artifact@v4
122+
with:
123+
name: rust_code
124+
- name: Set up Rust
125+
uses: actions-rust-lang/setup-rust-toolchain@v1
126+
- name: Check Library
127+
run: cargo check
128+
- name: Publish to crates.io
129+
uses: katyo/publish-crates@v2
130+
with:
131+
registry-token: ${{ secrets.CARGO_TOKEN }}
132+
ignore-unpublished-changes: true

buf.gen.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: v2
2+
plugins:
3+
- remote: buf.build/bufbuild/es:v2.1.0
4+
out: packages/ts/lib
5+
opt: target=ts
6+
- remote: buf.build/community/neoeinstein-prost:v0.4.0
7+
out: packages/rust/src/generated
8+
- remote: buf.build/community/neoeinstein-prost-crate:v0.4.1
9+
out: packages/rust/src/generated
10+
opt: no_features

buf.yaml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
version: v1
2-
name: buf.build/meshtastic/protobufs
3-
deps: []
4-
build:
5-
excludes: []
6-
breaking:
7-
use:
8-
- FILE
9-
ignore:
10-
- FILE_OPTION_CHANGED
11-
lint:
12-
ignore_only:
13-
PACKAGE_DEFINED:
14-
- nanopb.proto
15-
use:
16-
- MINIMAL
1+
version: v2
2+
modules:
3+
- path: meshtastic
4+
name: buf.build/meshtastic/protobufs
5+
excludes:
6+
- meshtastic/device_only/
7+
lint:
8+
use:
9+
- MINIMAL
10+
except:
11+
- PACKAGE_NO_IMPORT_CYCLE
12+
disallow_comment_ignores: true
13+
breaking:
14+
use:
15+
- FILE
16+
except:
17+
- EXTENSION_NO_DELETE
18+
- FIELD_SAME_DEFAULT
19+

packages/rust/Cargo.lock

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rust/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "meshtastic_protobufs"
3+
edition = "2021"
4+
version = "__PACKAGE_VERSION__"
5+
description = "Meshtastic Protobuf definitions"
6+
repository = "https://github.com/meshtastic/protobufs"
7+
license-file = "LICENSE"
8+
include = [
9+
"**/*.rs",
10+
"Cargo.toml",
11+
]
12+
13+
[dependencies]
14+
prost = "0.13.3"
15+
prost-types = "0.13.3"

packages/rust/src/generated/.gitkeep

Whitespace-only changes.

packages/rust/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate prost;
2+
extern crate core;
3+
extern crate prost_types;
4+
5+
include!("generated/mod.rs");

packages/ts/deno.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@meshtastic/protobufs",
3+
"version": "__PACKAGE_VERSION__",
4+
"exports": {
5+
".": "./mod.ts"
6+
},
7+
"imports": {
8+
"@bufbuild/protobuf": "npm:@bufbuild/protobuf@^2.2.3"
9+
},
10+
"publish": {
11+
"exclude": [
12+
"!lib"
13+
]
14+
}
15+
}

packages/ts/deno.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ts/lib/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)