Repository navigation
397 lines (383 loc) · 16.5 KB
/
Copy pathrelease.yml
File metadata and controls
397 lines (383 loc) · 16.5 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
name: Release
# On a version tag, build the distributable artifacts for every platform and
# attach them to a GitHub Release. Registry publishing (crates.io / npm / PyPI /
# NuGet / Maven) is OFF by default and gated behind opt-in repo variables — turn
# it on later without touching this file.
#
# git tag v0.1.0 && git push origin v0.1.0 # → builds + GitHub Release
#
# The tag version MUST match Cargo.toml (workspace), crates/powder-node/package.json,
# and crates/powder-python/pyproject.toml — `verify-version` fails on drift.
#
# Enable publishing later (Settings → Secrets and variables → Actions → Variables):
# ENABLE_PUBLISH = true → crates.io + npm + PyPI
# All three use OIDC Trusted Publishing — no secret. Configure the trusted
# publisher once on crates.io / npmjs.com / pypi.org (repo + release.yml).
# ENABLE_NUGET = true → NuGet (OIDC; set variable NUGET_USER = your nuget.org username)
# ENABLE_MAVEN = true → Maven Central Portal (secrets MAVEN_CENTRAL_* + MAVEN_SIGNING_* — not OIDC)
on:
push:
tags: ["v*"]
workflow_dispatch: {}
permissions:
contents: write # create the GitHub Release
jobs:
# ===========================================================================
# Guard
# ===========================================================================
verify-version:
name: Verify tag matches package versions
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- uses: actions/checkout@v4
- id: v
run: |
tag="${GITHUB_REF_NAME#v}"
echo "version=$tag" >> "$GITHUB_OUTPUT"
# workflow_dispatch has no tag — skip the equality check then.
if [ "${{ github.event_name }}" != "push" ]; then
echo "manual run: skipping version match"; exit 0
fi
cargo_v=$(grep -m1 '^version' Cargo.toml | sed -E 's/.*"(.*)".*/\1/')
node_v=$(node -p "require('./crates/powder-node/package.json').version")
py_v=$(grep -m1 '^version' crates/powder-python/pyproject.toml | sed -E 's/.*"(.*)".*/\1/')
echo "tag=$tag cargo=$cargo_v node=$node_v py=$py_v"
for got in "$cargo_v" "$node_v" "$py_v"; do
if [ "$got" != "$tag" ]; then
echo "::error::version mismatch: tag=$tag but found $got"
exit 1
fi
done
# ===========================================================================
# Build artifacts (always run) — attached to the GitHub Release
# ===========================================================================
# Native libraries: the runtime dependency for Go / C / C++ / C# (powder_ffi)
# and Java / Kotlin (powder_java). One tarball per platform.
native-libs:
name: native libs (${{ matrix.label }})
needs: verify-version
strategy:
fail-fast: false
matrix:
include:
- { host: macos-latest, target: aarch64-apple-darwin, label: macos-arm64 }
- { host: macos-15-intel, target: x86_64-apple-darwin, label: macos-x64 }
- { host: ubuntu-latest, target: x86_64-unknown-linux-gnu, label: linux-x64 }
- { host: ubuntu-24.04-arm, target: aarch64-unknown-linux-gnu, label: linux-arm64 }
- { host: ubuntu-latest, target: x86_64-unknown-linux-musl, label: linux-x64-musl }
- { host: ubuntu-24.04-arm, target: aarch64-unknown-linux-musl, label: linux-arm64-musl }
- { host: windows-latest, target: x86_64-pc-windows-msvc, label: windows-x64 }
- { host: windows-11-arm, target: aarch64-pc-windows-msvc, label: windows-arm64 }
runs-on: ${{ matrix.host }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install musl tools
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build powder-ffi + powder-java
run: cargo build -p powder-ffi -p powder-java --release --target ${{ matrix.target }}
- name: Package libraries
shell: bash
run: |
mkdir -p out
d="target/${{ matrix.target }}/release"
for f in libpowder_ffi.dylib libpowder_ffi.so powder_ffi.dll \
libpowder_java.dylib libpowder_java.so powder_java.dll; do
[ -f "$d/$f" ] && cp "$d/$f" out/
done
ls -la out
tar -czf "powder-native-${{ matrix.label }}.tar.gz" -C out .
- uses: actions/upload-artifact@v4
with:
name: native-${{ matrix.label }}
path: powder-native-${{ matrix.label }}.tar.gz
if-no-files-found: error
# npm prebuilt native addons (@powder/node), one .node per platform.
npm-prebuild:
name: npm prebuild (${{ matrix.target }})
needs: verify-version
strategy:
fail-fast: false
matrix:
include:
- { host: macos-latest, target: aarch64-apple-darwin }
- { host: macos-15-intel, target: x86_64-apple-darwin }
- { host: windows-latest, target: x86_64-pc-windows-msvc }
- { host: windows-11-arm, target: aarch64-pc-windows-msvc }
- { host: ubuntu-latest, target: x86_64-unknown-linux-gnu }
- { host: ubuntu-24.04-arm, target: aarch64-unknown-linux-gnu }
- { host: ubuntu-latest, target: x86_64-unknown-linux-musl }
- { host: ubuntu-24.04-arm, target: aarch64-unknown-linux-musl }
runs-on: ${{ matrix.host }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
workspaces: "crates/powder-node"
- name: Install musl tools
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install -y musl-tools
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Build native addon
working-directory: crates/powder-node
run: |
npm install
npx napi build --platform --release --target ${{ matrix.target }}
- uses: actions/upload-artifact@v4
with:
name: napi-${{ matrix.target }}
path: crates/powder-node/*.node
if-no-files-found: error
# Python wheels (abi3, one per platform) + sdist.
python-wheels:
name: python wheel (${{ matrix.target }})
needs: verify-version
strategy:
fail-fast: false
matrix:
include:
- { host: ubuntu-latest, target: x86_64, manylinux: auto }
- { host: ubuntu-24.04-arm, target: aarch64, manylinux: auto }
- { host: ubuntu-latest, target: x86_64, manylinux: musllinux_1_2 }
- { host: ubuntu-24.04-arm, target: aarch64, manylinux: musllinux_1_2 }
- { host: macos-latest, target: aarch64, manylinux: "" }
- { host: macos-15-intel, target: x86_64, manylinux: "" }
- { host: windows-latest, target: x64, manylinux: "" }
- { host: windows-11-arm, target: aarch64, manylinux: "" }
runs-on: ${{ matrix.host }}
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux }}
args: --release --out dist --manifest-path crates/powder-python/Cargo.toml
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.host }}-${{ matrix.target }}-${{ matrix.manylinux || 'native' }}
path: dist/*.whl
if-no-files-found: error
python-sdist:
name: python sdist
needs: verify-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path crates/powder-python/Cargo.toml
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
if-no-files-found: error
# ===========================================================================
# GitHub Release (always run) — gather every artifact and attach it
# ===========================================================================
github-release:
name: GitHub Release
needs: [verify-version, native-libs, npm-prebuild, python-wheels, python-sdist]
runs-on: ubuntu-latest
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Flatten into release assets
run: |
mkdir -p release-assets
find dist -type f \( -name '*.tar.gz' -o -name '*.whl' -o -name '*.node' \) \
-exec cp {} release-assets/ \;
ls -la release-assets
- uses: softprops/action-gh-release@v2
if: github.event_name == 'push'
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
files: release-assets/*
# ===========================================================================
# Registry publishing — OFF by default, opt-in via repo variables
# ===========================================================================
crates-io:
name: Publish to crates.io
needs: verify-version
if: github.event_name == 'push' && vars.ENABLE_PUBLISH == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write # OIDC trusted publishing — no CARGO_REGISTRY_TOKEN
contents: read
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Stage distribution README into each crate
run: |
cp README.dist.md crates/powder-core/README.md
cp README.dist.md crates/powder-cli/README.md
# OIDC (default). Skipped on the very first publish, when the crate does
# not exist yet and can't have a trusted publisher — set FIRST_PUBLISH=true
# + secret CARGO_REGISTRY_TOKEN for that one run, then remove the variable.
- name: Authenticate to crates.io via OIDC
if: vars.FIRST_PUBLISH != 'true'
uses: rust-lang/crates-io-auth-action@v1
id: auth
# Dependency order: cli depends on core (+ optional studio), studio on core.
# `cargo publish` blocks until the index sees each crate.
- name: Publish powder-core
run: cargo publish -p powder-orm --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ vars.FIRST_PUBLISH == 'true' && secrets.CARGO_REGISTRY_TOKEN || steps.auth.outputs.token }}
- name: Publish powder-studio
run: cargo publish -p powder-orm-studio --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ vars.FIRST_PUBLISH == 'true' && secrets.CARGO_REGISTRY_TOKEN || steps.auth.outputs.token }}
- name: Publish powder-cli
run: cargo publish -p powder-orm-cli --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ vars.FIRST_PUBLISH == 'true' && secrets.CARGO_REGISTRY_TOKEN || steps.auth.outputs.token }}
npm-publish:
name: Publish to npm
needs: [verify-version, npm-prebuild]
if: github.event_name == 'push' && vars.ENABLE_PUBLISH == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write # OIDC trusted publishing — no NPM_TOKEN
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- name: Use OIDC-capable npm
run: npm install -g npm@latest # trusted publishing needs npm >= 11.5.1
- name: Collect prebuilt addons
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: napi-*
- name: Assemble + publish
working-directory: crates/powder-node
# First publish creates the package (+ platform packages), so it can't
# use a not-yet-existing trusted publisher: set FIRST_PUBLISH=true +
# secret NPM_TOKEN for that run, then remove the variable for OIDC.
# When empty, npm ≥ 11.5.1 auto-uses OIDC (id-token: write above).
env:
NODE_AUTH_TOKEN: ${{ vars.FIRST_PUBLISH == 'true' && secrets.NPM_TOKEN || '' }}
run: |
npm install
cp ../../README.dist.md README.md # npm reads README.md from the package dir
npx tsc -p tsconfig.json
npx napi artifacts --dir ../../artifacts
npx napi prepublish -t npm --skip-gh-release
npm publish --access public
python-publish:
name: Publish to PyPI
needs: [verify-version, python-wheels, python-sdist]
if: github.event_name == 'push' && vars.ENABLE_PUBLISH == 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write # OIDC Trusted Publishing — no token needed
steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: "{wheel-*,sdist}"
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
# NuGet (C#). Opt-in: ENABLE_NUGET=true + repo variable NUGET_USER (your
# nuget.org username). OIDC trusted publishing — no NUGET_API_KEY.
nuget-publish:
name: Publish to NuGet
needs: [verify-version, native-libs]
if: github.event_name == 'push' && vars.ENABLE_NUGET == 'true'
runs-on: ubuntu-latest
environment: nuget
permissions:
id-token: write # OIDC trusted publishing
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Collect native tarballs
uses: actions/download-artifact@v4
with:
path: native
pattern: native-*
- name: Place natives into runtimes/
shell: bash
run: |
base=bindings/csharp/Powder/runtimes
declare -A RID=( [macos-arm64]=osx-arm64 [macos-x64]=osx-x64 [linux-x64]=linux-x64 [linux-arm64]=linux-arm64 [linux-x64-musl]=linux-musl-x64 [linux-arm64-musl]=linux-musl-arm64 [windows-x64]=win-x64 [windows-arm64]=win-arm64 )
for label in "${!RID[@]}"; do
tb="native/native-$label/powder-native-$label.tar.gz"
[ -f "$tb" ] || continue
tmp=$(mktemp -d); tar -xzf "$tb" -C "$tmp"
mkdir -p "$base/${RID[$label]}/native"
find "$tmp" -name 'libpowder_ffi.*' -o -name 'powder_ffi.dll' | while read -r f; do
cp "$f" "$base/${RID[$label]}/native/"
done
done
find "$base" -type f
- name: Pack
run: |
dotnet pack bindings/csharp/Powder/Powder.csproj -c Release \
-p:Version=${{ needs.verify-version.outputs.version }} -o out
- name: Authenticate to NuGet via OIDC
uses: NuGet/login@v1
id: nuget-login
with:
user: ${{ vars.NUGET_USER }}
- name: Push
run: |
dotnet nuget push "out/*.nupkg" \
--api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" \
--source https://api.nuget.org/v3/index.json --skip-duplicate
# Maven Central Portal (Java + Kotlin). Opt-in: ENABLE_MAVEN=true.
# Secrets: MAVEN_CENTRAL_USERNAME / _PASSWORD (Central Portal user token),
# MAVEN_SIGNING_KEY (armored GPG private key) / _PASSWORD.
maven-publish:
name: Publish to Maven Central
needs: verify-version
if: github.event_name == 'push' && vars.ENABLE_MAVEN == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- uses: gradle/actions/setup-gradle@v4
with:
# vanniktech maven-publish 0.37 needs a Gradle newer than 8.10
# (ProjectLayout.getSettingsDirectory(), added later) — always use
# the latest stable release instead of guessing a version floor.
gradle-version: "current"
- name: Publish + release to Central Portal
working-directory: jvm
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_SIGNING_PASSWORD }}
run: |
gradle publishAndReleaseToMavenCentral --no-configuration-cache \
-Pversion=${{ needs.verify-version.outputs.version }}