Repository navigation
mcpp-vscode 0.6.0: 侧边栏重组、库生态、缓存视图与仓库工程化 (#17) #18
Workflow file for this run
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: 发布 VSIX | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 检出 tag | |
| uses: actions/checkout@v4 | |
| - name: 配置 Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| - name: 安装依赖 | |
| run: npm ci | |
| - name: 校验 tag 与扩展版本 | |
| shell: bash | |
| run: | | |
| PACKAGE_VERSION="$(node -p 'require("./package.json").version')" | |
| if [[ "$GITHUB_REF_NAME" != "v${PACKAGE_VERSION}" ]]; then | |
| echo "tag $GITHUB_REF_NAME 与 package.json 版本 $PACKAGE_VERSION 不一致。" | |
| exit 1 | |
| fi | |
| echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> "$GITHUB_ENV" | |
| - name: 运行测试 | |
| run: npm test | |
| - name: 打包 VSIX | |
| run: npm run package | |
| # 发布的产物正是那个曾经把本地 .dev-profile/ 打进去的地方(4035 文件 / 64 MB), | |
| # 所以体积与目录守卫在这里比在 CI 里更重要。 | |
| - name: 校验 VSIX 体积与内容 | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| VSIX="mcpp-vscode-${PACKAGE_VERSION}.vsix" | |
| SIZE=$(stat -c %s "$VSIX") | |
| COUNT=$(unzip -l "$VSIX" | tail -1 | awk '{print $2}') | |
| echo "VSIX: $COUNT files, $((SIZE / 1024)) KiB" | |
| if [ "$COUNT" -gt 200 ]; then echo "文件数异常:$COUNT"; exit 1; fi | |
| if [ "$SIZE" -gt 1048576 ]; then echo "体积异常:$SIZE 字节"; exit 1; fi | |
| for forbidden in .dev-profile/ .agents/ test/ tools/ src/ node_modules/; do | |
| if unzip -l "$VSIX" | grep -q "extension/$forbidden"; then | |
| echo "产物里混入了本地内容:$forbidden" | |
| exit 1 | |
| fi | |
| done | |
| unzip -t "$VSIX" >/dev/null | |
| echo "VSIX 内容与体积正常" | |
| - name: 生成 SHA-256 校验文件 | |
| shell: bash | |
| run: sha256sum "mcpp-vscode-${PACKAGE_VERSION}.vsix" > "mcpp-vscode-${PACKAGE_VERSION}.vsix.sha256" | |
| - name: 创建或更新 GitHub Release | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| VSIX="mcpp-vscode-${PACKAGE_VERSION}.vsix" | |
| CHECKSUM="${VSIX}.sha256" | |
| if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then | |
| gh release upload "$GITHUB_REF_NAME" "$VSIX" "$CHECKSUM" --clobber | |
| else | |
| gh release create "$GITHUB_REF_NAME" "$VSIX" "$CHECKSUM" \ | |
| --title "mcpp-vscode ${PACKAGE_VERSION}" \ | |
| --generate-notes | |
| fi | |
| # 两个市场收到的都是刚上传给 GitHub Release 的同一只 VSIX(SHA-256 对得上)。 | |
| # 分工是作者定的:Open VSX 是本流水线的必发目标——缺 token 显式失败,不静默跳过; | |
| # Marketplace 机会发布——没配 token 就打一行说明跳过,Release 本身不因此失败。 | |
| # secret 名即仓库已配置的 OPENVSX_TOKEN;--pat 显式传入,不依赖 CLI 的环境变量约定。 | |
| - name: 发布到 Open VSX | |
| shell: bash | |
| env: | |
| OPENVSX_TOKEN: ${{ secrets.OPENVSX_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| if [ -z "${OPENVSX_TOKEN:-}" ]; then | |
| echo "缺少 OPENVSX_TOKEN:Open VSX 是必发目标,发布 tag 不能没有它。" | |
| echo "到 open-vsx.org → Settings → Access Tokens 创建 publish 作用域的 token," | |
| echo "再配到本仓库 Settings → Secrets and variables → Actions 的 OPENVSX_TOKEN。" | |
| exit 1 | |
| fi | |
| npx ovsx publish "mcpp-vscode-${PACKAGE_VERSION}.vsix" --pat "$OPENVSX_TOKEN" | |
| - name: 发布到 Visual Studio Marketplace(未配置 token 则跳过) | |
| shell: bash | |
| env: | |
| VSCE_PAT: ${{ secrets.VSCE_PAT }} | |
| run: | | |
| set -euo pipefail | |
| if [ -z "${VSCE_PAT:-}" ]; then | |
| echo "未配置 VSCE_PAT:跳过 Marketplace 发布(Open VSX 与 GitHub Release 不受影响)。" | |
| exit 0 | |
| fi | |
| npx vsce publish --packagePath "mcpp-vscode-${PACKAGE_VERSION}.vsix" |