fix: require node.js env when uv sync

This commit is contained in:
Soulter
2026-03-04 18:25:19 +08:00
parent ff22030dde
commit 31673ee521
2 changed files with 47 additions and 2 deletions
+34 -1
View File
@@ -184,7 +184,8 @@ jobs:
publish-pypi:
name: Publish PyPI
runs-on: ubuntu-24.04
needs: publish-release
needs:
- publish-release
steps:
- name: Checkout repository
uses: actions/checkout@v6
@@ -192,6 +193,36 @@ jobs:
fetch-depth: 0
ref: ${{ inputs.ref || github.ref }}
- name: Resolve tag
id: tag
shell: bash
run: |
if [ "${{ github.event_name }}" = "push" ]; then
tag="${GITHUB_REF_NAME}"
elif [ -n "${{ inputs.tag }}" ]; then
tag="${{ inputs.tag }}"
else
tag="$(git describe --tags --abbrev=0)"
fi
if [ -z "$tag" ]; then
echo "Failed to resolve tag." >&2
exit 1
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- name: Download dashboard artifact
uses: actions/download-artifact@v8
with:
name: Dashboard-${{ steps.tag.outputs.tag }}
path: dashboard-artifact
- name: Unpack dashboard dist into package tree
shell: bash
run: |
mkdir -p astrbot/dashboard/dist
unzip -q "dashboard-artifact/AstrBot-${{ steps.tag.outputs.tag }}-dashboard.zip" -d dashboard-artifact/unpacked
cp -r dashboard-artifact/unpacked/dist/. astrbot/dashboard/dist/
- name: Set up Python
uses: actions/setup-python@v6
with:
@@ -203,6 +234,8 @@ jobs:
- name: Build package
shell: bash
# Dashboard assets are already in astrbot/dashboard/dist/;
# ASTRBOT_BUILD_DASHBOARD is intentionally unset so the hatch hook skips npm.
run: uv build
- name: Publish to PyPI
+13 -1
View File
@@ -1,13 +1,20 @@
"""
Custom Hatchling build hook.
During `hatch build` (or `pip wheel`), this hook:
Only runs when the environment variable ASTRBOT_BUILD_DASHBOARD=1 is set,
so that `uv sync` / editable installs are never affected.
Usage:
ASTRBOT_BUILD_DASHBOARD=1 uv build
When enabled, this hook:
1. Runs `npm run build` inside the `dashboard/` directory.
2. Copies the resulting `dashboard/dist/` tree into
`astrbot/dashboard/dist/` so the static assets are shipped
inside the Python wheel.
"""
import os
import shutil
import subprocess
import sys
@@ -20,6 +27,11 @@ class CustomBuildHook(BuildHookInterface):
PLUGIN_NAME = "custom"
def initialize(self, version: str, build_data: dict) -> None:
# Only run when explicitly requested (e.g. during CI / release builds).
# This prevents `uv sync` / editable installs from triggering npm.
if os.environ.get("ASTRBOT_BUILD_DASHBOARD", "").strip() != "1":
return
root = Path(self.root)
dashboard_src = root / "dashboard"
dist_src = dashboard_src / "dist"