Dispatch Publish #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 工作流名称 | |
| name: Dispatch Publish | |
| # 运行时显示的名称 | |
| run-name: Dispatch Publish | |
| # 触发条件配置 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: '选择发布/部署版本tag (alpha/beta/rc/latest)' | |
| required: true | |
| default: 'alpha' | |
| type: choice | |
| options: | |
| - alpha | |
| - beta | |
| - rc | |
| - latest | |
| publish_npm: | |
| description: '是否发布npm包(未勾选则只部署文档)' | |
| required: true | |
| default: false | |
| type: boolean | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.sha }} | |
| cancel-in-progress: true | |
| # 定义工作流中的作业 | |
| jobs: | |
| build: | |
| # 指定运行环境为最新版本的ubuntu | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| # 步骤1: 检出代码 | |
| - name: CheckOut Code | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| # 步骤2: 设置pnpm包管理器 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v5 | |
| # 步骤3: 设置Node.js环境 | |
| - name: Setup Node | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 24 # 使用Node.js 24版本 | |
| package-manager-cache: false | |
| registry-url: 'https://registry.npmjs.org' # 设置npm registry地址 | |
| # 步骤4: 获取pnpm缓存目录路径 | |
| - name: Get pnpm store directory | |
| id: pnpm-cache | |
| run: | | |
| echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT | |
| # 步骤5: 配置pnpm缓存 | |
| - uses: actions/cache@v5 | |
| name: Setup pnpm cache | |
| with: | |
| path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} | |
| # 使用操作系统类型和依赖配置文件的哈希值作为缓存键 | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/package.json', 'pnpm-workspace.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| # 步骤6: 安装项目依赖 | |
| - name: Install dependencies | |
| run: pnpm i --no-frozen-lockfile | |
| # 步骤7: 构建组件 | |
| - name: Run Build Components | |
| run: pnpm build | |
| # 步骤8: 构建文档 | |
| - name: Build VitePress | |
| run: pnpm build:docs --nocomponents | |
| env: | |
| VITEPRESS_BASE: /tiny-robot/${{ inputs.tag }}/ | |
| PLAYGROUND_BASE: /tiny-robot/${{ inputs.tag }}/playground | |
| - name: Verify build output | |
| run: ls -la ./docs/dist | |
| - name: Upload package artifacts | |
| if: ${{ inputs.publish_npm }} | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: dispatch-package-dist | |
| path: | | |
| packages/components/dist | |
| packages/kit/dist | |
| packages/svgs/dist | |
| if-no-files-found: error | |
| retention-days: 1 | |
| - name: Upload docs artifacts | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: dispatch-docs-dist | |
| path: docs/dist | |
| if-no-files-found: error | |
| retention-days: 1 | |
| publish: | |
| needs: build | |
| if: ${{ inputs.publish_npm }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: CheckOut Code | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v5 | |
| - name: Setup Node | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 24 | |
| package-manager-cache: false | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install publish dependencies | |
| run: pnpm i --no-frozen-lockfile --ignore-scripts | |
| - name: Download package artifacts | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: dispatch-package-dist | |
| path: ./packages | |
| # 步骤9: 发布组件到NPM | |
| - name: Publish components | |
| run: pnpm lerna publish from-package --pre-dist-tag ${{ inputs.tag }} --yes | |
| deploy-docs: | |
| needs: [build, publish] | |
| if: ${{ always() && needs.build.result == 'success' && (needs.publish.result == 'success' || needs.publish.result == 'skipped') }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download docs artifacts | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: dispatch-docs-dist | |
| path: ./docs/dist | |
| - name: Deploy docs | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./docs/dist | |
| destination_dir: ./${{ inputs.tag }}/ | |
| keep_files: true | |
| force_orphan: false | |
| user_name: 'github-actions[bot]' | |
| user_email: 'github-actions[bot]@users.noreply.github.com' |