|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - alpha |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + release: |
| 19 | + name: Release |
| 20 | + runs-on: ubuntu-latest |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + node-version: [18] |
| 24 | + |
| 25 | + steps: |
| 26 | + # 检出代码库 |
| 27 | + - name: Checkout repo |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + # 设置 Node.js 版本 |
| 33 | + - name: Setup Node ${{ matrix.node-version }} |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: ${{ matrix.node-version }} |
| 37 | + registry-url: 'https://registry.npmjs.org/' |
| 38 | + |
| 39 | + # 启用 Corepack 以支持 Yarn 4 |
| 40 | + - name: Enable Corepack |
| 41 | + run: corepack enable |
| 42 | + |
| 43 | + # 准备 Yarn 4.x |
| 44 | + - name: Prepare Yarn |
| 45 | + run: corepack prepare yarn@4.4.1 --activate |
| 46 | + |
| 47 | + # 加载依赖缓存 |
| 48 | + - name: Load cached dependencies |
| 49 | + uses: actions/cache@v4.1.1 |
| 50 | + id: cache |
| 51 | + with: |
| 52 | + path: | |
| 53 | + **/node_modules |
| 54 | + **/.turbo |
| 55 | + /home/runner/.cache/Cypress |
| 56 | + key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }} |
| 57 | + |
| 58 | + # 安装依赖 |
| 59 | + - name: Install dependencies |
| 60 | + run: yarn install |
| 61 | + |
| 62 | + # 构建项目 |
| 63 | + - name: Build packages |
| 64 | + run: yarn build |
| 65 | + |
| 66 | + # 运行单元测试 |
| 67 | + - name: Unit test |
| 68 | + run: yarn run test |
| 69 | + |
| 70 | + # 运行 E2E 测试 |
| 71 | + - name: E2E test |
| 72 | + uses: cypress-io/github-action@v6 |
| 73 | + with: |
| 74 | + browser: chrome |
| 75 | + start: yarn run example |
| 76 | + wait-on: 'http://localhost:8881/examples/default-mode.html' |
| 77 | + |
| 78 | + # 创建 Release PR 或发布稳定版本到 npm |
| 79 | + - name: Create Release PR or publish stable version to npm |
| 80 | + id: changesets |
| 81 | + uses: changesets/action@v1 |
| 82 | + with: |
| 83 | + createGithubReleases: false |
| 84 | + publish: yarn changeset publish --tag alpha --access=public |
| 85 | + title: ${{ github.ref_name == 'master' && 'Publish a new stable version' || 'Publish a new pre-release version' }} |
| 86 | + commit: >- |
| 87 | + ${{ github.ref_name == 'master' && 'chore(release): publish a new release version' || 'chore(release): publish a new pre-release version' }} |
| 88 | + env: |
| 89 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments