Skip to content

armgit / BUI

Public Imported from GitHub
0

Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI

ci: release workflow (crates.io, npm trusted publishing, GitHub Release); fix test flakiness

Preetham Pemmasani53263f8f24d0
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 45e6d24..acb3d2a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,6 +12,7 @@ on:
branches: [main]
pull_request:
workflow_dispatch:
+ workflow_call: # release.yml runs the whole suite before publishing
concurrency:
group: ci-${{ github.ref }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..70efaba
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,160 @@
+# Publish a release: crates.io, npm and a GitHub Release. (PyPI is published by
+# wheels.yml, which also runs on the same tag.)
+#
+# git tag v0.2.0 && git push --tags
+#
+# Every step is safe to re-run: a version that is already on a registry is skipped, so a
+# failed run (a network timeout, say) can be repeated with "Re-run failed jobs".
+#
+# tag v* : check versions, run the whole CI suite, then publish
+# manual run : same, but nothing is published unless "publish" is ticked
+# (the default is a dry run: cargo publish --dry-run, npm publish --dry-run)
+#
+# One-time setup (repository Settings > Secrets and variables > Actions):
+# CARGO_REGISTRY_TOKEN a crates.io API token (scopes: publish-new, publish-update)
+# npm and PyPI need no secret: both use trusted publishing (OIDC). On npmjs.com, each of
+# @blender-ui/native and @blender-ui/react lists this repository and the workflow file
+# release.yml as its trusted publisher. See docs/publishing.md.
+
+name: release
+
+on:
+ push:
+ tags: ["v*"]
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: "Release tag to check against (e.g. v0.2.0)"
+ required: true
+ publish:
+ description: "Really publish (otherwise a dry run)"
+ type: boolean
+ default: false
+ skip_ci:
+ description: "Skip the CI suite (only if you know it is red for a reason that does not affect the release)"
+ type: boolean
+ default: false
+
+permissions:
+ contents: read
+
+env:
+ TAG: ${{ github.event.inputs.tag || github.ref_name }}
+ PUBLISH: ${{ github.event_name == 'push' || github.event.inputs.publish == 'true' }}
+
+jobs:
+ versions:
+ name: versions match the tag
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+ - run: python tools/check_versions.py "$TAG"
+
+ ci:
+ name: build and test everywhere
+ needs: versions
+ if: github.event.inputs.skip_ci != 'true'
+ uses: ./.github/workflows/ci.yml
+
+ crates:
+ name: crates.io
+ needs: [versions, ci]
+ # runs when the versions match and CI passed (or was skipped on purpose)
+ if: ${{ !cancelled() && needs.versions.result == 'success' && (needs.ci.result == 'success' || needs.ci.result == 'skipped') }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 90
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+ - uses: dtolnay/rust-toolchain@stable
+ - run: sudo apt-get update && sudo apt-get install -y libx11-dev
+ - name: Vendor the C sources (blenderui-sys carries them)
+ run: python bindings/rust/scripts/vendor_c.py
+ - name: Publish in dependency order
+ working-directory: bindings/rust
+ env:
+ CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
+ run: |
+ version="${TAG#v}"
+ for crate in blenderui-tailwind blenderui-macros blenderui-sys blenderui blenderui-imgui; do
+ if [ "$(curl -s -o /dev/null -w '%{http_code}' "https://crates.io/api/v1/crates/$crate/$version")" = 200 ]; then
+ echo "::notice::$crate $version is already on crates.io; skipping"
+ continue
+ fi
+ flags="--allow-dirty -j 2"
+ [ "$PUBLISH" = true ] || flags="$flags --dry-run"
+ # uploads of the big blenderui-sys crate sometimes time out (HTTP 408): retry
+ for attempt in 1 2 3; do
+ cargo publish -p "$crate" $flags && break
+ [ "$attempt" = 3 ] && exit 1
+ echo "::warning::$crate: attempt $attempt failed; retrying"
+ sleep $((attempt * 30))
+ done
+ # the next crate needs this one in the index
+ [ "$PUBLISH" = true ] && sleep 20
+ done
+
+ npm:
+ name: npm
+ needs: [versions, ci]
+ # runs when the versions match and CI passed (or was skipped on purpose)
+ if: ${{ !cancelled() && needs.versions.result == 'success' && (needs.ci.result == 'success' || needs.ci.result == 'skipped') }}
+ # the native addon ships prebuilt for Windows x64 (other systems build it from source)
+ runs-on: windows-latest
+ timeout-minutes: 60
+ permissions:
+ contents: read
+ id-token: write # npm trusted publishing (OIDC) and provenance
+ defaults:
+ run:
+ shell: bash
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: "22"
+ registry-url: https://registry.npmjs.org
+ - name: Upgrade npm to 11.5.1+ for trusted publishing (Node 22 ships an older one)
+ run: npm install -g npm@^11.5.1
+ - uses: oven-sh/setup-bun@v2 # the runtime tests build a Bun executable too
+ - uses: dtolnay/rust-toolchain@stable
+ - name: Install workspace dependencies
+ working-directory: bindings
+ run: npm ci
+ - name: Publish @blender-ui/native then @blender-ui/react, with no token (OIDC)
+ run: |
+ # native first: react depends on it
+ for pkg in node react; do
+ cd "bindings/$pkg"
+ name=$(node -p "require('./package.json').name")
+ version=$(node -p "require('./package.json').version")
+ if npm view "$name@$version" version >/dev/null 2>&1; then
+ echo "::notice::$name@$version is already on npm; skipping"
+ else
+ flags="--access public --provenance"
+ [ "$PUBLISH" = true ] || flags="$flags --dry-run"
+ npm publish $flags
+ fi
+ cd ../..
+ done
+
+ github-release:
+ name: GitHub Release
+ needs: [crates, npm]
+ if: github.event_name == 'push' || github.event.inputs.publish == 'true'
+ runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/checkout@v4
+ - name: Create the release (notes from the commits since the last tag)
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ gh release view "$TAG" >/dev/null 2>&1 && { echo "release exists"; exit 0; }
+ gh release create "$TAG" --title "BUI ${TAG#v}" --generate-notes --verify-tag
diff --git a/bindings/node/test/fixtures/react-app.jsx b/bindings/node/test/fixtures/react-app.jsx
index d8713c2..64e8c7b 100644
--- a/bindings/node/test/fixtures/react-app.jsx
+++ b/bindings/node/test/fixtures/react-app.jsx
@@ -26,6 +26,7 @@ const { app, window } = render(<Counter />, { width: 200, height: 120, headless:
window.body.style = 'margin: 0; background: #000'
const tick = (ms = 40) => new Promise(r => setTimeout(r, ms))
const find = (id) => [...window._nodes.values()].find(n => n.getAttribute?.('id') === id)
+// sampled inside the button but right of the "count N" label, so text never covers it
const pixel = (s, x, y) => { const i = (y * s.width + x) * 4; return [s.data[i], s.data[i + 1], s.data[i + 2]] }
;(async () => {
@@ -40,8 +41,8 @@ const pixel = (s, x, y) => { const i = (y * s.width + x) * 4; return [s.data[i],
const after = await window.screenshot()
console.log(JSON.stringify({
runtime: globalThis.__BUI_NATIVE__ ? 'quickjs' : (typeof Bun !== 'undefined' ? 'bun' : 'node'),
- before: pixel(before, 40, 15),
- after: pixel(after, 40, 15),
+ before: pixel(before, 70, 25),
+ after: pixel(after, 70, 25),
once,
rendersAfterOne,
many: Boolean(find('many')),
diff --git a/bindings/package-lock.json b/bindings/package-lock.json
index e02c4d3..271260e 100644
--- a/bindings/package-lock.json
+++ b/bindings/package-lock.json
@@ -70,7 +70,7 @@
},
"react": {
"name": "@blender-ui/react",
- "version": "0.2.0",
+ "version": "0.2.1",
"license": "GPL-2.0-or-later",
"dependencies": {
"@blender-ui/native": "^0.2.1",
diff --git a/bindings/python/tests/test_tk_compat.py b/bindings/python/tests/test_tk_compat.py
index 618cea5..4db100f 100644
--- a/bindings/python/tests/test_tk_compat.py
+++ b/bindings/python/tests/test_tk_compat.py
@@ -63,6 +63,9 @@ def prog_calculator(tk, ttk):
buttons["C"].invoke()
entry.insert(0, "6*7")
buttons["="].invoke()
+ # a textvariable write reaches the Entry at idle time in Tk on macOS: flush it
+ # before reading the widget (without this, stdlib Tk there still shows "6*7")
+ root.update_idletasks()
out.append(entry.get())
info = buttons["5"].grid_info()
result = {"results": out, "grid": (info["row"], info["column"]), "size": root.grid_size(),
diff --git a/bindings/react/package.json b/bindings/react/package.json
index b69171b..3254646 100644
--- a/bindings/react/package.json
+++ b/bindings/react/package.json
@@ -1,6 +1,6 @@
{
"name": "@blender-ui/react",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "React renderer for BUI: Blender's UI in native windows from JSX, with React's hooks backed by signals. Node.js and Bun.",
"main": "index.js",
"types": "index.d.ts",
diff --git a/docs/publishing.md b/docs/publishing.md
index 52baef6..08ac920 100644
--- a/docs/publishing.md
+++ b/docs/publishing.md
@@ -76,13 +76,47 @@ Remove the source tree from `sys.path` and keep `examples/` on it for
No API tokens are stored anywhere.
+## Releasing everything at once
+
+One tag publishes all of it:
+
+```sh
+git tag v0.2.0 && git push --tags
+```
+
+| Workflow | Publishes |
+|---|---|
+| `wheels.yml` | the Python wheels and sdist to PyPI (trusted publishing, no secret) |
+| `release.yml` | the Rust crates to crates.io, `@blender-ui/native` and `@blender-ui/react` to npm, and a GitHub Release |
+
+`release.yml` first checks that the tag matches the Python and Rust versions
+(`python tools/check_versions.py v0.2.0` runs the same check by hand), then runs the whole
+`ci.yml` suite on every platform, then publishes. A version that is already on a registry is
+skipped, so a run that failed halfway (say, crates.io timing out on the big
+`blenderui-sys` upload) can simply be re-run. The npm packages are versioned on their own; bump
+them in their `package.json` when they change.
+
+One-time setup:
+
+- **crates.io:** a repository secret `CARGO_REGISTRY_TOKEN` (Settings > Secrets and variables >
+ Actions): a crates.io API token with the scopes `publish-new` and `publish-update`.
+- **npm:** no secret. On npmjs.com, open each of `@blender-ui/native` and `@blender-ui/react`
+ > Settings > Trusted Publisher > GitHub Actions, and enter the owner `ppmpreetham`, the
+ repository `BUI` and the workflow filename `release.yml` (leave the environment empty).
+ The workflow publishes with OIDC and npm adds provenance by itself.
+- **PyPI:** no secret, see above.
+
+Try it without publishing: Actions > release > Run workflow, enter the tag and leave
+"publish" unticked. That runs the checks and the CI suite, then `cargo publish --dry-run` and
+`npm publish --dry-run`.
+
## Release checklist
1. Bump `bindings/python/bui/_version.py` (semantic versioning).
2. Add the release to `CHANGELOG.md`.
3. `ctest --test-dir build` passes locally. Optionally run the workflow by
hand with `testpypi` and `pip install -i https://test.pypi.org/simple blenderui`.
-4. `git tag v0.1.0 && git push --tags`. CI builds, tests and publishes.
+4. `git tag v0.2.0 && git push --tags`. CI builds, tests and publishes (see above).
## Known gaps before 1.0
diff --git a/tools/check_versions.py b/tools/check_versions.py
new file mode 100644
index 0000000..71a779d
--- /dev/null
+++ b/tools/check_versions.py
@@ -0,0 +1,55 @@
+"""Check that every published package agrees with a release tag before anything is published.
+
+ python tools/check_versions.py v0.2.0
+
+The Python package, the Rust workspace and the Rust crates' path dependencies share one
+version (the tag). The npm packages are versioned on their own (the native addon can get a
+patch release the Rust crates don't), so they are only listed, not compared; the release
+workflow skips an npm version that is already published.
+"""
+
+import json
+import re
+import sys
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+RUST = ROOT / "bindings" / "rust"
+
+
+def read(path: Path) -> str:
+ return path.read_text(encoding="utf-8")
+
+
+def main() -> int:
+ if len(sys.argv) != 2:
+ print(__doc__)
+ return 2
+ want = sys.argv[1].removeprefix("v")
+ found: dict[str, str] = {}
+
+ found["bindings/python/bui/_version.py"] = re.search(
+ r'__version__\s*=\s*"([^"]+)"', read(ROOT / "bindings/python/bui/_version.py")).group(1)
+ found["bindings/rust/Cargo.toml [workspace.package]"] = re.search(
+ r'^version\s*=\s*"([^"]+)"', read(RUST / "Cargo.toml"), re.M).group(1)
+
+ # the published crates name their siblings with an exact version
+ for crate in ("blenderui", "blenderui-macros", "blenderui-imgui"):
+ text = read(RUST / crate / "Cargo.toml")
+ for dep, ver in re.findall(r'^(blenderui[\w-]*)\s*=\s*\{[^}]*version\s*=\s*"([^"]+)"', text, re.M):
+ found[f"bindings/rust/{crate}/Cargo.toml: {dep}"] = ver
+
+ bad = {k: v for k, v in found.items() if v != want}
+ for k, v in found.items():
+ print(f"{'ok ' if v == want else 'BAD'} {v:8} {k}")
+ for pkg in ("node", "react"):
+ meta = json.loads(read(ROOT / "bindings" / pkg / "package.json"))
+ print(f"npm {meta['version']:8} {meta['name']} (own version; published only if new)")
+ if bad:
+ print(f"\nThe tag says {want}, but {len(bad)} place(s) disagree.")
+ return 1
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())