Address PR #1648 review: - Bump the GHCR action majors to match current v1 (docker/login-action v4, docker/metadata-action v6, docker/setup-buildx-action v4, actions/attest-build-provenance v4) to avoid Dependabot churn. - Make the image tags explicit (`type=semver` + `flavor: latest=true`) instead of relying on `flavor.latest=auto`, so a release lands both the version tags and `:latest` — the README's bare `ghcr.io/…/inspector` URL won't 404. - Run the container as the non-root `node` user with /home/node as workdir (its writable home is where the inspector stores the catalog / OAuth state). - Add a HEALTHCHECK that probes `/` via Node's global fetch (no curl in slim). - Trim specification/ and docs/ from the build context. (test-servers/ stays — `tsc -b` typechecks the integration tests that import its alias, so excluding it breaks the build.) Re-verified locally: `docker build` succeeds, the container runs as uid 1000 (node), serves `/` (200), and the HEALTHCHECK reports healthy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BrihGWcrM9JGRyu41nzZYw
210 lines
8.7 KiB
YAML
210 lines
8.7 KiB
YAML
name: Run install, format, lint, build, and test on every push
|
|
|
|
on:
|
|
push:
|
|
# A published GitHub release triggers the `publish` job below. The release's
|
|
# target commit determines which workflow runs — so this only publishes when a
|
|
# release is cut from a commit that carries this (v2) workflow.
|
|
release:
|
|
types: [published]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: '22.x'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies (root + all clients)
|
|
# The root postinstall (scripts/install-clients.mjs) cascades
|
|
# `npm install` into clients/web, clients/cli, clients/tui, and
|
|
# clients/launcher, so this single step sets up every client.
|
|
run: npm install
|
|
|
|
- name: Validate (format, lint, build, fast tests)
|
|
# Each client self-validates: format:check + lint + build + test (no
|
|
# coverage instrumentation — fast). This also builds every client bundle
|
|
# (web dist, cli/tui/launcher) that the smokes below need. The heavier
|
|
# per-file coverage gate runs in its own step below. Unit tests run in
|
|
# both steps (fast here, instrumented under coverage); the double unit
|
|
# run is an accepted trade-off for keeping this fast build step intact.
|
|
# A future optimization could split coverage into per-client parallel
|
|
# jobs, but that's a larger restructure and deliberately out of scope.
|
|
run: npm run validate
|
|
|
|
- name: Enforce per-file coverage gate (≥90% on all four dimensions)
|
|
# CI-ENFORCED coverage gate (#1550): runs `npm run coverage`, which
|
|
# chains every client's `test:coverage` (v8-instrumented) and fails the
|
|
# job if ANY file drops below 90% on lines, statements, functions, or
|
|
# branches. This is the whole point of the step — a PR that regresses
|
|
# coverage below the threshold now blocks merge instead of relying on a
|
|
# contributor remembering to run the gate locally.
|
|
#
|
|
# This also covers the web integration project: web's `test:coverage`
|
|
# runs `--project=unit --project=integration --coverage`, so the former
|
|
# standalone `Run web integration tests` step was removed to avoid
|
|
# running the integration suite twice.
|
|
run: npm run coverage
|
|
|
|
- name: Run cross-client smokes
|
|
# End-to-end smokes through the built launcher (--help dispatch + prod
|
|
# CLI/web). Not part of any client's `validate`: it needs the
|
|
# cli/tui/launcher bundles, which `validate` above already built
|
|
# (smoke:web builds clients/web/dist on demand — #1486). smoke:tui
|
|
# self-skips here — the Ink TUI needs a real TTY (raw mode) that headless
|
|
# CI lacks, so its boot/render check is local-only.
|
|
run: npm run smoke
|
|
|
|
- name: Cache Playwright browsers
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cache/ms-playwright
|
|
key: playwright-${{ runner.os }}-${{ hashFiles('clients/web/package-lock.json') }}
|
|
|
|
- name: Install Playwright browsers
|
|
working-directory: ./clients/web
|
|
run: npx playwright install --with-deps chromium
|
|
|
|
- name: Run Storybook play-function tests
|
|
working-directory: ./clients/web
|
|
run: npm run test:storybook
|
|
|
|
# Publish the single `@modelcontextprotocol/inspector` package to npm on a
|
|
# published GitHub release. v2 is not an npm workspace, so there is no
|
|
# `publish-all` / `--workspaces` (v1) — just one `npm publish`, whose `prepack`
|
|
# (`npm run build`) builds every client bundle into the `files` allowlist.
|
|
# `pack:verify` runs first as the pre-publish gate: it builds, packs the real
|
|
# tarball, installs it into a clean throwaway consumer, and drives the
|
|
# installed `mcp-inspector` bin (web/cli/tui) end to end — so a broken package
|
|
# is caught before it reaches npm rather than after.
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'release'
|
|
environment: release
|
|
needs: build
|
|
# Serialize publishes so two releases cut in quick succession can't run
|
|
# overlapping `npm publish`es. Never cancel an in-flight publish.
|
|
concurrency:
|
|
group: publish-npm
|
|
cancel-in-progress: false
|
|
permissions:
|
|
contents: read
|
|
# Required for npm provenance (`--provenance` mints a signed attestation
|
|
# via GitHub's OIDC token). The repo is public, so provenance is available.
|
|
id-token: write
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: '22.x'
|
|
cache: 'npm'
|
|
registry-url: 'https://registry.npmjs.org'
|
|
|
|
- name: Assert release tag matches package version
|
|
# `npm publish` ships whatever `version` is in the root package.json,
|
|
# regardless of the release's tag. Fail fast (before the heavy install /
|
|
# pack:verify) if they disagree — e.g. a release drafted without running
|
|
# `npm version`, or cut from the wrong commit — since publishing is
|
|
# irreversible. Tolerates the conventional leading `v` (npm version tags
|
|
# as `vX.Y.Z`). The tag arrives via `env:` (not spliced into the script)
|
|
# to avoid the script-injection surface of interpolating `${{ }}` into a
|
|
# `run:` block.
|
|
env:
|
|
TAG: ${{ github.event.release.tag_name }}
|
|
run: |
|
|
PKG="$(node -p "require('./package.json').version")"
|
|
if [ "${TAG#v}" != "$PKG" ]; then
|
|
echo "Release tag '$TAG' does not match package.json version '$PKG'"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Install dependencies (root + all clients)
|
|
run: npm install
|
|
|
|
- name: Verify the publishable tarball end to end
|
|
# Builds, `npm pack`s, installs the tarball into a clean consumer, and
|
|
# drives the installed bin. Needs registry access to pull the tarball's
|
|
# runtime deps — available here. `smoke:tui` inside it self-skips on CI.
|
|
run: npm run pack:verify
|
|
|
|
- name: Publish to npm (single package, with provenance)
|
|
# `prepack` (`npm run build`) rebuilds the client bundles into the tarball.
|
|
# The build runs three times on this path (build job → pack:verify →
|
|
# prepack); the redundancy is intentional — each is a clean-tree rebuild
|
|
# and the `prepack` one is what actually populates the published tarball,
|
|
# so don't "optimize" it away.
|
|
run: npm publish --access public --provenance
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
|
|
# Build and push the multi-arch container image to GHCR on a published
|
|
# release. The image installs the packed tarball (`Dockerfile`) so it ships
|
|
# the same artifact as npm. Independent of the npm `publish` job (both gated on
|
|
# the release event) — a container failure doesn't block the npm publish.
|
|
publish-github-container-registry:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'release'
|
|
environment: release
|
|
needs: build
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
attestations: write
|
|
id-token: write
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Log in to the Container registry
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}
|
|
# Be explicit rather than relying on `flavor.latest=auto`: on a release
|
|
# cut both the version tags and `latest` land, so the README's bare
|
|
# `ghcr.io/…/inspector` (implicit `:latest`) never 404s.
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
flavor: |
|
|
latest=true
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: Build and push Docker image
|
|
id: push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
- name: Generate artifact attestation
|
|
uses: actions/attest-build-provenance@v4
|
|
with:
|
|
subject-name: ghcr.io/${{ github.repository }}
|
|
subject-digest: ${{ steps.push.outputs.digest }}
|
|
push-to-registry: true
|