name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Build
run: npm run build
- name: Run tests
run: npm test
- name: Check for vulnerabilities
run: npm audit --audit-level=high
continue-on-error: true
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- run: npm ci
- name: Type check
run: npm run typecheck
publish:
needs: [build, typecheck]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Upgrade npm for OIDC support
run: npm install -g npm@latest
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Check if version already published
id: version_check
run: |
LOCAL_VERSION=$(node -p "require('./package.json').version")
echo "local_version=$LOCAL_VERSION" >> $GITHUB_OUTPUT
# Check if this version exists on npm
NPM_VERSION=$(npm view dbeaver-mcp-server version 2>/dev/null || echo "0.0.0")
echo "npm_version=$NPM_VERSION" >> $GITHUB_OUTPUT
if [ "$LOCAL_VERSION" = "$NPM_VERSION" ]; then
echo "should_publish=false" >> $GITHUB_OUTPUT
echo "Version $LOCAL_VERSION already published, skipping"
else
echo "should_publish=true" >> $GITHUB_OUTPUT
echo "Will publish $LOCAL_VERSION (npm has $NPM_VERSION)"
fi
- name: Publish to npm (OIDC trusted publishing)
if: steps.version_check.outputs.should_publish == 'true'
run: npm publish --provenance --access public
- name: Create git tag
if: steps.version_check.outputs.should_publish == 'true'
run: |
VERSION=${{ steps.version_check.outputs.local_version }}
git tag "v${VERSION}"
git push origin "v${VERSION}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}