diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e1fdc123..405c853f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,6 +62,26 @@ jobs: echo "node-linker=hoisted" >> .npmrc pnpm install + - name: Inject version into app package.json + shell: bash + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + VERSION="${{ inputs.version }}" + else + VERSION="${{ github.ref_name }}" + VERSION="${VERSION#v}" + fi + echo "Injecting version: $VERSION" + node -e " + const fs = require('fs'); + for (const p of ['apps/desktop/package.json', 'apps/cli/package.json']) { + const pkg = JSON.parse(fs.readFileSync(p, 'utf-8')); + pkg.version = '${VERSION}'; + fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n'); + console.log(p + ' → ' + '${VERSION}'); + } + " + - name: Cache Electron and electron-builder binaries uses: actions/cache@v5 with: @@ -139,6 +159,26 @@ jobs: echo "node-linker=hoisted" >> .npmrc pnpm install + - name: Inject version into app package.json + shell: bash + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + VERSION="${{ inputs.version }}" + else + VERSION="${{ github.ref_name }}" + VERSION="${VERSION#v}" + fi + echo "Injecting version: $VERSION" + node -e " + const fs = require('fs'); + for (const p of ['apps/desktop/package.json', 'apps/cli/package.json']) { + const pkg = JSON.parse(fs.readFileSync(p, 'utf-8')); + pkg.version = '${VERSION}'; + fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n'); + console.log(p + ' → ' + '${VERSION}'); + } + " + - name: Cache Electron and electron-builder binaries uses: actions/cache@v5 with: @@ -332,3 +372,70 @@ jobs: r2-bucket: ${{ secrets.R2_BUCKET_NAME }} source-dir: dist-yml destination-dir: releases/download + + publish-cli: + needs: [release] + runs-on: ubuntu-latest + + # 必须显式声明 id-token 写入权限,用于 OIDC 与 npm 握手交换临时 Token + permissions: + contents: read + id-token: write + + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Setup Node.js + uses: actions/setup-node@v5 + with: + node-version: '24' + package-manager-cache: false + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: | + echo "node-linker=hoisted" >> .npmrc + pnpm install + + - name: Determine version and npm tag + id: npm_meta + shell: bash + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + VERSION="${{ inputs.version }}" + else + VERSION="${{ github.ref_name }}" + VERSION="${VERSION#v}" + fi + echo "version=$VERSION" >> $GITHUB_OUTPUT + + if [[ "$VERSION" =~ -beta\. ]]; then + echo "tag=beta" >> $GITHUB_OUTPUT + elif [[ "$VERSION" =~ -alpha\. ]]; then + echo "tag=alpha" >> $GITHUB_OUTPUT + elif [[ "$VERSION" =~ -rc\. ]]; then + echo "tag=rc" >> $GITHUB_OUTPUT + else + echo "tag=latest" >> $GITHUB_OUTPUT + fi + + echo "Publishing chatlab-cli@$VERSION with tag $(grep tag <<< "$(cat $GITHUB_OUTPUT)" | tail -1 | cut -d= -f2)" + + - name: Inject version + run: | + node -e " + const fs = require('fs'); + const pkg = JSON.parse(fs.readFileSync('apps/cli/package.json', 'utf-8')); + pkg.version = '${{ steps.npm_meta.outputs.version }}'; + fs.writeFileSync('apps/cli/package.json', JSON.stringify(pkg, null, 2) + '\n'); + " + + - name: Build CLI (with Web UI) + run: pnpm --filter chatlab-cli run build:full + + - name: Publish to npm + working-directory: apps/cli + run: npm publish --tag ${{ steps.npm_meta.outputs.tag }} --provenance diff --git a/apps/cli/package.json b/apps/cli/package.json index a4fc8171..21791957 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -1,6 +1,6 @@ { "name": "chatlab-cli", - "version": "0.1.0", + "version": "0.0.0", "description": "ChatLab CLI & Service - Chat history analysis tool", "bin": { "chatlab": "bin/chatlab.mjs" diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 424c4a57..8a7d2e15 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -1,6 +1,6 @@ { "name": "@openchatlab/desktop", - "version": "0.20.0", + "version": "0.0.0", "productName": "ChatLab", "private": true, "description": "ChatLab Desktop — Electron 桌面客户端",