-
Notifications
You must be signed in to change notification settings - Fork 259
263 lines (227 loc) · 6.93 KB
/
publish.yml
File metadata and controls
263 lines (227 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Publish to 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
dry_run:
description: "Dry run mode - generate artifacts without publishing"
required: false
type: boolean
default: false
permissions:
contents: write
id-token: write
jobs:
codegen:
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.TAG }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine version
id: version
run: |
set -euo pipefail
if [ "${{ github.ref_type }}" = "tag" ]; then
TAG="${{ github.ref_name }}"
elif [ -n "${{ inputs.version || '' }}" ]; then
TAG="${{ 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
VERSION="${TAG#v}"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "TAG=$TAG" >> "$GITHUB_OUTPUT"
echo "Resolved VERSION=$VERSION, TAG=$TAG"
- name: Setup Buf
uses: bufbuild/buf-setup-action@main
with:
github_token: ${{ github.token }}
- name: Generate protobuf code
run: buf generate
- name: Move generated files to lib root
run: |
set -euo pipefail
src_dir="packages/ts/lib/meshtastic"
dest_dir="packages/ts/lib"
if [ ! -d "$src_dir" ]; then
echo "Expected source directory '$src_dir' does not exist. 'buf generate' may have failed or changed its output paths." >&2
exit 1
fi
if ! compgen -G "$src_dir"/*_pb.ts > /dev/null; then
echo "No '*_pb.ts' files found in '$src_dir'. 'buf generate' may have produced no TypeScript files or changed their naming." >&2
exit 1
fi
mv "$src_dir"/*_pb.ts "$dest_dir"/
- name: Show generated files
run: |
echo "=== packages/ts contents ==="
ls -la packages/ts/
echo "=== packages/ts/lib contents ==="
ls -la packages/ts/lib/ || echo "lib folder not found"
- name: Set package versions
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.VERSION }}"
for f in packages/ts/deno.json packages/ts/package.json; do
test -f "$f" || { echo "Missing $f" >&2; exit 1; }
sed -i "s/__PACKAGE_VERSION__/${VERSION}/g" "$f"
done
- name: Copy license & README
run: cp LICENSE README.md packages/ts/
- name: Upload TypeScript code
uses: actions/upload-artifact@v4
with:
name: ts_code
path: packages/ts
build-typescript:
runs-on: ubuntu-24.04
needs: codegen
steps:
- name: Download TypeScript code
uses: actions/download-artifact@v4
with:
name: ts_code
- name: Show downloaded files
run: |
echo "=== Working directory ==="
pwd
echo "=== Contents ==="
ls -la
echo "=== lib/ contents ==="
ls -la lib/ || echo "lib folder not found"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Install dependencies
run: npm install
- name: Build with tsdown
run: npm run build
- name: Show build output
run: |
echo "=== Build output ==="
ls -la
ls -la dist/
- name: Upload built NPM package
uses: actions/upload-artifact@v4
with:
name: npm_package
path: |
dist/
package.json
LICENSE
README.md
- name: Upload JSR package
uses: actions/upload-artifact@v4
with:
name: jsr_package
path: |
lib/
mod.ts
deno.json
LICENSE
README.md
create-release-zips:
runs-on: ubuntu-24.04
needs: [codegen, build-typescript]
steps:
- name: Download NPM package
uses: actions/download-artifact@v4
with:
name: npm_package
path: npm_package
- name: Download JSR package
uses: actions/download-artifact@v4
with:
name: jsr_package
path: jsr_package
- name: Create zip archives
run: |
cd npm_package && zip -r ../meshtastic-protobufs-npm.zip . && cd ..
cd jsr_package && zip -r ../meshtastic-protobufs-jsr.zip . && cd ..
- name: Upload release zips
uses: actions/upload-artifact@v4
with:
name: release_zips
path: |
meshtastic-protobufs-npm.zip
meshtastic-protobufs-jsr.zip
upload-release-assets:
runs-on: ubuntu-24.04
needs: [codegen, create-release-zips]
if: ${{ !inputs.dry_run }}
steps:
- name: Download release zips
uses: actions/download-artifact@v4
with:
name: release_zips
- name: Upload assets to GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.codegen.outputs.tag }}
files: |
meshtastic-protobufs-npm.zip
meshtastic-protobufs-jsr.zip
push-buf-registry:
runs-on: ubuntu-24.04
needs: codegen
if: ${{ !inputs.dry_run }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Buf
uses: bufbuild/buf-setup-action@main
with:
github_token: ${{ github.token }}
- name: Push to schema registry
env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
run: buf push --tag ${{ needs.codegen.outputs.tag }}
publish-npm:
runs-on: ubuntu-24.04
needs: [codegen, build-typescript]
if: ${{ !inputs.dry_run }}
steps:
- name: Download NPM package
uses: actions/download-artifact@v4
with:
name: npm_package
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-jsr:
runs-on: ubuntu-24.04
needs: [codegen, build-typescript]
if: ${{ !inputs.dry_run }}
permissions:
contents: read
id-token: write
steps:
- name: Download JSR package
uses: actions/download-artifact@v4
with:
name: jsr_package
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Publish to JSR
run: npx jsr publish