diff --git a/.github/workflows/plugins-pr-verify.yml b/.github/workflows/plugins-pr-verify.yml index 6a4ff97b..0787738e 100644 --- a/.github/workflows/plugins-pr-verify.yml +++ b/.github/workflows/plugins-pr-verify.yml @@ -1,14 +1,14 @@ -# 插件 PR 合并前检查(这里没通过就不能合并;合并后由官方发布到插件市场) -# 只检查本次改动涉及的插件:目录与 id、从源码编译、清单规范 + AST 安全扫描、插件自带测试、版本号必须升高 -# 需要在仓库 Settings → Branches 把 main 的「verify-plugins」设为必须通过的检查 -name: 插件合并前检查 +# Pre-merge verification for plugin pull requests (required before merge; merged plugins are published by maintainers to the plugin marketplace) +# Checks only plugins modified in this PR: directory & id, build from source, manifest spec + AST security scan, plugin tests, and version bump +# Configure "verify-plugins" as a required status check for the main branch under Settings -> Branches +name: Verify Plugin PR on: pull_request: branches: - main -# 外部贡献者的 PR 只有只读权限、拿不到任何密钥;严禁改成 pull_request_target +# External contributor PRs only receive read-only permissions with no secrets; never switch to pull_request_target permissions: contents: read @@ -22,22 +22,22 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 steps: - - name: 拉取代码 + - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - - name: 安装 Node.js + - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 24 cache: npm - - name: 安装依赖(不执行依赖包的安装脚本) + - name: Install dependencies (ignore lifecycle scripts) run: npm ci --ignore-scripts - - name: 规范包自测 + - name: Run plugin spec self-tests run: node --test packages/ztools-plugins-spec/tests/*.test.mjs - - name: 检查本次改动涉及的插件 + - name: Verify changed plugins run: node scripts/verify-changed-plugins.mjs --base "origin/${{ github.base_ref }}" diff --git a/.github/workflows/plugins-release.yml b/.github/workflows/plugins-release.yml index 3bb268d4..4031dd4e 100644 --- a/.github/workflows/plugins-release.yml +++ b/.github/workflows/plugins-release.yml @@ -1,7 +1,7 @@ -# 插件发布:main 分支有合并就从源码重新构建全部插件,上传阿里云 OSS 并刷新 CDN -# 产物:plugins-v2/<作者>//-<版本>.zip、icon,以及插件目录 catalog.json / plugins.json -# 任一插件构建或安全扫描失败时整次发布中止,线上目录保持上一版不变 -name: 插件发布 +# Plugin release: rebuild all plugins from source on merges to main, upload to Alibaba Cloud OSS, and purge CDN +# Artifacts: plugins-v2///-.zip, icons, and marketplace catalog.json / plugins.json +# If any plugin fails build or security scan, the entire release aborts and the live catalog stays untouched +name: Publish Plugins to CDN on: push: @@ -16,7 +16,7 @@ on: workflow_dispatch: inputs: dry_run: - description: '只演练,不实际上传' + description: 'Dry run only (preview upload plan without publishing to CDN)' required: false type: boolean default: true @@ -24,7 +24,7 @@ on: permissions: contents: read -# 连续合并时排队依次发布,避免两次发布交错覆盖插件目录 +# Queue consecutive releases to avoid concurrent catalog overwrites concurrency: group: plugins-release cancel-in-progress: false @@ -33,27 +33,30 @@ jobs: publish: # Credentials are provisioned separately; bootstrap merges must not publish partial releases. if: github.event_name == 'workflow_dispatch' || vars.PLUGIN_CDN_ENABLED == 'true' - name: 构建并发布到 CDN + name: Build and Publish to CDN runs-on: ubuntu-latest timeout-minutes: 30 environment: plugins-cdn steps: - - name: 拉取代码 + - name: Checkout repository uses: actions/checkout@v4 - - name: 安装 Node.js + - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 24 cache: npm - - name: 安装依赖(不执行依赖包的安装脚本) + - name: Install dependencies (ignore lifecycle scripts) run: npm ci --ignore-scripts - - name: 从源码编译全部插件 + - name: Run plugin spec self-tests + run: node --test packages/ztools-plugins-spec/tests/*.test.mjs + + - name: Build all plugins from source run: node scripts/build-declarative.mjs --all - - name: 安全扫描、打包并生成插件目录 + - name: Security scan, package, and generate catalog run: | node scripts/build-plugins-release.mjs \ --plugins-dir extensions \ @@ -61,7 +64,7 @@ jobs: --cdn-base-url "https://cdn.ztools.cn" \ --url-prefix plugins-v2 - - name: 上传阿里云 OSS 并刷新 CDN + - name: Upload to Alibaba Cloud OSS and purge CDN env: OSS_ACCESS_KEY_ID: ${{ secrets.OSS_ACCESS_KEY_ID }} OSS_ACCESS_KEY_SECRET: ${{ secrets.OSS_ACCESS_KEY_SECRET }} @@ -73,17 +76,17 @@ jobs: run: | DRY_RUN_FLAG="" if [ "$DRY_RUN" = "true" ]; then - echo "手动选择了演练模式,只打印上传计划,不实际上传" + echo "Dry-run mode enabled: printing upload plan without uploading." DRY_RUN_FLAG="--dry-run" fi - # 没配阿里云密钥时脚本直接报错,不会假装上传成功 + # Fails immediately if OSS/CDN credentials are missing (never reports false success) node scripts/deploy-plugins-storage.mjs \ --dir dist/plugins \ --cdn-base-url "https://cdn.ztools.cn" \ --oss-prefix plugins-v2 \ $DRY_RUN_FLAG - - name: 保存发布产物 + - name: Upload release artifacts if: always() uses: actions/upload-artifact@v4 with: @@ -92,7 +95,7 @@ jobs: retention-days: 30 if-no-files-found: ignore - - name: 发布摘要 + - name: Publish summary if: success() env: DRY_RUN: ${{ github.event.inputs.dry_run }} @@ -102,18 +105,27 @@ jobs: const index = JSON.parse(fs.readFileSync('dist/plugins/catalog.json', 'utf8')); const platformOf = (p) => { const list = Array.isArray(p.platforms) ? p.platforms : []; - if (list.includes('windows') && list.includes('macos')) return '跨平台'; - if (list.includes('macos')) return '仅 macOS'; - if (list.includes('windows')) return '仅 Windows'; + if (list.includes('windows') && list.includes('macos')) return 'Cross-platform'; + if (list.includes('macos')) return 'macOS only'; + if (list.includes('windows')) return 'Windows only'; return '-'; }; + const minAppOf = (p) => { + const targets = Array.isArray(p.targets) ? p.targets.filter((t) => t && t.runtime === 'electron') : []; + const win = targets.find((t) => t.platform === 'windows')?.minAppVersion; + const mac = targets.find((t) => t.platform === 'macos')?.minAppVersion; + if (win && mac) return win === mac ? win : 'Win: ' + win + ' / Mac: ' + mac; + if (win && targets.some((t) => t.platform === 'macos')) return 'Win: ' + win + ' / Mac: -'; + if (mac && targets.some((t) => t.platform === 'windows')) return 'Win: - / Mac: ' + mac; + return win || mac || p.minAppVersion || '-'; + }; const rows = index.plugins.map((p) => p.revoked - ? '| ' + p.name + ' | ' + p.id + ' | ' + p.version + ' | - | 已下架 | - |' - : '| ' + p.name + ' | ' + p.id + ' | ' + p.version + ' | ' + platformOf(p) + ' | ' + (p.size / 1024).toFixed(1) + ' KB | ' + p.sha256.slice(0, 12) + ' |'); - const summary = [process.env.DRY_RUN === 'true' ? '### 插件发布演练通过(未上传)' : '### 插件发布完成', '', - '- 插件目录:' + index.cdnBaseUrl + '/plugins-v2/catalog.json', - '- 插件数:' + index.total, - '- 生成时间:' + index.generatedAt, '', - '| 名称 | ID | 版本 | 平台 | 大小 | SHA-256 |', '| --- | --- | --- | --- | --- | --- |', ...rows].join('\n'); + ? '| ' + p.name + ' | ' + p.id + ' | ' + p.version + ' | - | - | Revoked | - |' + : '| ' + p.name + ' | ' + p.id + ' | ' + p.version + ' | ' + platformOf(p) + ' | ' + minAppOf(p) + ' | ' + (p.size / 1024).toFixed(1) + ' KB | ' + p.sha256.slice(0, 12) + ' |'); + const summary = [process.env.DRY_RUN === 'true' ? '### Plugin Release Dry Run Passed (Not Uploaded)' : '### Plugin Release Completed', '', + '- Catalog URL: ' + index.cdnBaseUrl + '/plugins-v2/catalog.json', + '- Total plugins: ' + index.total, + '- Generated at: ' + index.generatedAt, '', + '| Name | ID | Version | Platform | Min App Version | Size | SHA-256 |', '| --- | --- | --- | --- | --- | --- | --- |', ...rows].join('\n'); fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary + '\n'); "