|
| 1 | +name: Publish Package & Docs |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write # 用于 Changesets 创建 PR |
| 10 | + id-token: write |
| 11 | + pages: write # 必须:部署 Pages 需要 |
| 12 | + deployments: write |
| 13 | + |
| 14 | +concurrency: ${{ github.workflow }}-${{ github.ref }} # 避免重复发布,旧的action运行完成后才会执行新的 |
| 15 | + |
| 16 | +jobs: |
| 17 | + # 任务 1:发布到 npm |
| 18 | + release: |
| 19 | + name: Release & Publish |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 # 必须获取完整历史,Changesets 才能计算变更 |
| 25 | + - uses: pnpm/action-setup@v3 |
| 26 | + - uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: 24 |
| 29 | + cache: "pnpm" |
| 30 | + registry-url: "https://registry.npmjs.org" |
| 31 | + - run: pnpm install --frozen-lockfile |
| 32 | + - name: Create Release PR or Publish |
| 33 | + id: changesets |
| 34 | + uses: changesets/action@v1 |
| 35 | + with: |
| 36 | + publish: pnpm release |
| 37 | + env: |
| 38 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # for write repo |
| 39 | + |
| 40 | + # 任务 2:部署文档到 GitHub Pages |
| 41 | + deploy-docs: |
| 42 | + name: Deploy Documentation |
| 43 | + needs: release # 等待发布任务完成,确保文档是最新的 |
| 44 | + runs-on: ubuntu-latest |
| 45 | + environment: |
| 46 | + name: github-pages |
| 47 | + url: ${{ steps.deployment.outputs.page_url }} |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + - uses: pnpm/action-setup@v3 |
| 51 | + - uses: actions/setup-node@v4 |
| 52 | + with: |
| 53 | + node-version: 24 |
| 54 | + cache: "pnpm" |
| 55 | + |
| 56 | + - run: pnpm install --frozen-lockfile |
| 57 | + - name: Build Docs |
| 58 | + run: pnpm build |
| 59 | + |
| 60 | + - name: Move Files |
| 61 | + run: | |
| 62 | + # cp demo to docs |
| 63 | + cp -r apps/dev/dist apps/docs/.vitepress/dist/v1-demo-windowed |
| 64 | +
|
| 65 | + - name: Upload artifact |
| 66 | + uses: actions/upload-pages-artifact@v3 |
| 67 | + with: |
| 68 | + path: "./apps/docs/.vitepress/dist" |
| 69 | + |
| 70 | + - name: Deploy to GitHub Pages |
| 71 | + id: deployment |
| 72 | + uses: actions/deploy-pages@v4 |
0 commit comments