Dispatch Publish #11
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: | |
| version: | |
| description: 输入您将要发布的版本号(默认使用 packages/fluent-editor/package.json 中的版本号),例如:`0.1.0`。 | |
| required: false | |
| type: string | |
| tag: | |
| description: "选择发布/部署版本tag (alpha/beta/rc/latest)" | |
| required: true | |
| default: "alpha" | |
| type: choice | |
| options: | |
| - alpha | |
| - beta | |
| - rc | |
| - latest | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.sha }} | |
| cancel-in-progress: true | |
| # 定义工作流中的作业 | |
| jobs: | |
| build: | |
| # 指定运行环境为最新版本的ubuntu | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.ver.outputs.value }} | |
| steps: | |
| # 步骤1: 检出代码 | |
| - name: CheckOut Code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| # 步骤2: 设置pnpm包管理器 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| # 步骤3: 设置Node.js环境 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 # 使用Node.js 20版本 | |
| 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@v3 | |
| name: Setup pnpm cache | |
| with: | |
| path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} | |
| # 使用操作系统类型和pnpm-lock.yaml的哈希值作为缓存键 | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| # 步骤6: 安装项目依赖 | |
| - name: Install dependencies | |
| run: pnpm i --no-frozen-lockfile | |
| - name: Get version | |
| id: ver | |
| run: | | |
| # 优先用手动输入的版本号 | |
| if [ -n "${{ inputs.version }}" ]; then | |
| VERSION="${{ inputs.version }}" | |
| else | |
| VERSION="$(node -p "require('./packages/fluent-editor/package.json').version")" | |
| fi | |
| echo "version: $VERSION" | |
| echo "value=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Build lib | |
| run: | | |
| pnpm build:lib | |
| cd packages/fluent-editor | |
| echo "version: ${{ steps.ver.outputs.value }}" | |
| pnpm pre-release -v ${{ steps.ver.outputs.value }} | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-artifact | |
| path: packages/fluent-editor/dist/ | |
| # Publish job | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist-artifact | |
| path: packages/fluent-editor/dist/ | |
| - name: Show version and tag | |
| run: | | |
| echo "publish version: ${{ needs.build.outputs.version }}" | |
| echo "publish tag: ${{ inputs.tag }}" | |
| # 步骤8: 发布组件到NPM | |
| - name: Publish @opentiny/fluent-editor | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc | |
| echo "ls" | |
| ls | |
| cd packages/fluent-editor/dist | |
| ls | |
| npm publish --tag ${{ inputs.tag }} | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |