name: Publish to npm on: release: types: [published] # Minimal permissions + id-token for npm provenance (Sigstore) permissions: contents: read id-token: write jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - uses: actions/setup-node@v7 with: node-version: 22 registry-url: https://registry.npmjs.org cache: npm - run: npm ci --ignore-scripts - run: npm audit --audit-level=moderate - run: npm run build - run: npm run lint - run: npm test # Publish with provenance attestation (Sigstore) # Cryptographically links npm package to this repo + commit # Users can verify: npm audit signatures # Idempotent: skip if this version is already on npm, so a transient # MCP-registry failure below can be retried via `gh run rerun --failed` # without tripping on a duplicate npm publish. - name: Publish to npm (idempotent, with provenance) run: | VERSION=$(node -p "require('./package.json').version") if npm view "guardvibe@$VERSION" version >/dev/null 2>&1; then echo "guardvibe@$VERSION already on npm — skipping npm publish (registry-only retry)." else npm publish --provenance fi env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # npm now takes a minute or two to serve a freshly published version (and # its automated review can hold a version for 30+ minutes), and # the MCP Registry validates against npm — without this wait the registry # step fails with "version ... was not found (status: 404)". - name: Wait for npm to serve the new version run: | VERSION=$(node -p "require('./package.json').version") for i in $(seq 1 135); do if npm view "guardvibe@$VERSION" version --prefer-online >/dev/null 2>&1; then echo "guardvibe@$VERSION is available on npm." exit 0 fi echo "Waiting for guardvibe@$VERSION on npm ($i/135)..." sleep 20 done echo "guardvibe@$VERSION not visible on npm after 45 minutes." >&2 exit 1 # Publish to official MCP Registry - name: Install mcp-publisher run: | curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher - name: Authenticate to MCP Registry run: ./mcp-publisher login github-oidc - name: Update server.json version run: | VERSION=${GITHUB_REF#refs/tags/v} jq --arg v "$VERSION" '.version = $v | .packages[0].version = $v' server.json > server.tmp && mv server.tmp server.json - name: Publish to MCP Registry run: ./mcp-publisher publish