From 31673ee5210102a024dfde5028e71d196d4c4926 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 4 Mar 2026 18:25:19 +0800 Subject: [PATCH] fix: require node.js env when uv sync --- .github/workflows/release.yml | 35 ++++++++++++++++++++++++++++++++++- scripts/hatch_build.py | 14 +++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d434d0495..41f59f0a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/scripts/hatch_build.py b/scripts/hatch_build.py index 9317dd18f..431465b54 100644 --- a/scripts/hatch_build.py +++ b/scripts/hatch_build.py @@ -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"