|
| 1 | +name: 发布扩展 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: release-${{ github.ref }} |
| 13 | + cancel-in-progress: false |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: 校验标签、测试并构建 |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + timeout-minutes: 20 |
| 20 | + steps: |
| 21 | + - name: 检出标签源码 |
| 22 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 23 | + with: |
| 24 | + persist-credentials: false |
| 25 | + |
| 26 | + - name: 设置 Node.js |
| 27 | + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 |
| 28 | + with: |
| 29 | + node-version: '24' |
| 30 | + cache: npm |
| 31 | + |
| 32 | + - name: 校验标签和项目版本 |
| 33 | + run: node scripts/verify-package.cjs --version-only --tag "$GITHUB_REF_NAME" |
| 34 | + |
| 35 | + - name: 按锁文件安装开发依赖 |
| 36 | + run: npm ci |
| 37 | + |
| 38 | + - name: 检查语法、扩展入口和格式 |
| 39 | + run: | |
| 40 | + npm run check |
| 41 | + npm run format:check |
| 42 | +
|
| 43 | + - name: 安装测试浏览器 |
| 44 | + run: npx playwright install --with-deps chromium |
| 45 | + |
| 46 | + - name: 运行单元测试和真实扩展回归 |
| 47 | + run: | |
| 48 | + npm test |
| 49 | + npm run test:e2e |
| 50 | +
|
| 51 | + - name: 构建并验证 ZIP 与 SHA256SUMS |
| 52 | + run: | |
| 53 | + npm run package -- --tag "$GITHUB_REF_NAME" |
| 54 | + npm run package:verify -- --tag "$GITHUB_REF_NAME" |
| 55 | +
|
| 56 | + - name: 保存经过校验的发布资产 |
| 57 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 |
| 58 | + with: |
| 59 | + name: glassnote-release |
| 60 | + path: | |
| 61 | + dist/GlassNote-${{ github.ref_name }}.zip |
| 62 | + dist/SHA256SUMS |
| 63 | + if-no-files-found: error |
| 64 | + compression-level: 0 |
| 65 | + retention-days: 7 |
| 66 | + |
| 67 | + publish: |
| 68 | + name: 发布 GitHub Release |
| 69 | + needs: build |
| 70 | + runs-on: ubuntu-24.04 |
| 71 | + timeout-minutes: 5 |
| 72 | + permissions: |
| 73 | + contents: write |
| 74 | + steps: |
| 75 | + - name: 检出同一标签的校验脚本和发布说明 |
| 76 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 77 | + with: |
| 78 | + persist-credentials: false |
| 79 | + |
| 80 | + - name: 设置 Node.js |
| 81 | + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 |
| 82 | + with: |
| 83 | + node-version: '24' |
| 84 | + |
| 85 | + - name: 下载本次构建的发布资产 |
| 86 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 87 | + with: |
| 88 | + name: glassnote-release |
| 89 | + path: dist |
| 90 | + |
| 91 | + - name: 发布前复验版本、文件清单和 SHA-256 |
| 92 | + run: node scripts/verify-package.cjs --tag "$GITHUB_REF_NAME" |
| 93 | + |
| 94 | + - name: 创建 GitHub Release |
| 95 | + env: |
| 96 | + GH_TOKEN: ${{ github.token }} |
| 97 | + run: | |
| 98 | + archive="dist/GlassNote-${GITHUB_REF_NAME}.zip" |
| 99 | + title="GlassNote ${GITHUB_REF_NAME#v}" |
| 100 | + if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then |
| 101 | + echo '::error::该标签已经存在 Release,拒绝覆盖已发布资产;请使用新版本。' |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + gh release create "$GITHUB_REF_NAME" "$archive" dist/SHA256SUMS --verify-tag --target "$GITHUB_SHA" --title "$title" --notes-file CHANGELOG.md --draft=false --prerelease=false |
0 commit comments