# ============================================================================ # .github/workflows/ci.yml —— 测试 + 自动发布 # ---------------------------------------------------------------------------- # - push/PR 到 main: 运行 npm test(冒烟) # - tag v* 触发: 运行测试后自动 npm publish(需 NPM_TOKEN secret) # ============================================================================ name: CI on: push: branches: [main] tags: ['v*'] pull_request: branches: [main] jobs: test: name: Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 cache: npm - run: npm ci - name: Build dynamic-mount body (required by smoke) run: npm run build:body - run: npm test publish: name: Publish to npm needs: test if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest permissions: contents: read steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 cache: npm registry-url: https://registry.npmjs.org - run: npm ci - name: Publish (skip when the version already exists) run: | VER="${GITHUB_REF_NAME#v}" if [ -z "${NODE_AUTH_TOKEN}" ]; then echo "::warning::NPM_TOKEN 未配置 — 跳过 npm 发布(tag 仍然有效)。" echo "配置方式: 仓库 Settings → Secrets and variables → Actions → New repository secret, 名称 NPM_TOKEN," echo "值为 npm Automation token(粒度访问令牌即可); 配置后重新推送该 tag 即可发布。" echo "也可在本机 npm login 后直接 npm publish(两条路径产出的包完全一致)。" exit 0 fi if npm view dsh-workbench-ecs@"$VER" version >/dev/null 2>&1; then echo "dsh-workbench-ecs@$VER already published — skipping" exit 0 fi npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}