name: Test and Release MCP Web Docs
on:
push:
branches:
- '**'
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
env:
CACHE_VERSION: ${{ vars.CACHE_VERSION }}
BUILD_VERSION: mcp-web-docs-${{ github.run_id }}-${{ github.run_number }}
NODE_MODULES_CACHE_PREFIX: node-${{ vars.CACHE_VERSION }}
jobs:
deps:
name: Install Dependencies
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Restore node modules cache
uses: actions/cache/restore@v5
id: cache-node-modules
with:
path: node_modules
key: ${{ env.NODE_MODULES_CACHE_PREFIX }}-${{ hashFiles('package-lock.json') }}
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
- name: Install Dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: npm ci --ignore-scripts
- name: Build native modules
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: npm rebuild sqlite3
- name: Save node modules cache
uses: actions/cache/save@v5
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
with:
path: node_modules
key: ${{ steps.cache-node-modules.outputs.cache-primary-key }}
lint-typeCheck:
name: Code linting and type checking
runs-on: ubuntu-latest
needs: [deps]
strategy:
matrix:
command:
- npm run lint
- npm run prettier:ci
- npm run test:types
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Restore node modules cache
uses: actions/cache/restore@v5
with:
path: node_modules
key: ${{ env.NODE_MODULES_CACHE_PREFIX }}-${{ hashFiles('package-lock.json') }}
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
- run: ${{ matrix.command }}
lint-typeCheck-report:
name: Code linting and type checking Report
runs-on: ubuntu-latest
needs: [lint-typeCheck]
if: ${{ always() }}
steps:
- name: Linting and type checking fail
run: exit 1
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
test:
name: Unit Tests
runs-on: ubuntu-latest
needs: [deps]
strategy:
matrix:
shardIndex: [1, 2, 3]
shardTotal: [3]
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Restore node modules cache
uses: actions/cache/restore@v5
with:
path: node_modules
key: ${{ env.NODE_MODULES_CACHE_PREFIX }}-${{ hashFiles('package-lock.json') }}
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
- name: Tests for shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }}
run: npm run test:coverage -- --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
test-report:
name: Unit Tests Report
runs-on: ubuntu-latest
needs: [test]
if: ${{ always() }}
steps:
- name: Unit tests fail
run: exit 1
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
# We run this in PR branches to help catch incompatible package upgrades
build:
needs: [deps]
name: Build package
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Restore node modules cache
uses: actions/cache/restore@v5
with:
path: node_modules
key: ${{ env.NODE_MODULES_CACHE_PREFIX }}-${{ hashFiles('package-lock.json') }}
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
- name: Build
run: npm run build
shell: bash
- name: Save build
uses: actions/cache/save@v5
with:
path: build
key: ${{ env.BUILD_VERSION }}
release:
needs: [deps, lint-typeCheck, test, build]
name: Release NPM Package
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' }}
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false # Security: don't persist git credentials
- name: Restore node modules cache
uses: actions/cache/restore@v5
with:
path: node_modules
key: ${{ env.NODE_MODULES_CACHE_PREFIX }}-${{ hashFiles('package-lock.json') }}
- name: Restore build cache
uses: actions/cache/restore@v5
with:
path: build
key: ${{ env.BUILD_VERSION }}
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Verify provenance of installed dependencies
run: npm audit signatures
- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run create-release