name: Build and Release
on:
push:
branches: [ master ]
tags: [ 'v*' ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., v1.0.0)'
required: true
type: string
create_release:
description: 'Create GitHub release'
required: false
default: true
type: boolean
permissions:
contents: write
actions: read
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build ${{ matrix.platform.name }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- name: windows-x64
os: windows-latest
target: x86_64-pc-windows-msvc
executable: sqlx-mcp.exe
- name: linux-x64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
executable: sqlx-mcp
- name: macos-x64
os: macos-latest
target: x86_64-apple-darwin
executable: sqlx-mcp
- name: macos-arm64
os: macos-latest
target: aarch64-apple-darwin
executable: sqlx-mcp
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.platform.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.platform.target }}-
${{ runner.os }}-cargo-
- name: Install Linux dependencies
if: matrix.platform.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config
- name: Build
run: cargo build --release --target ${{ matrix.platform.target }}
- name: Create artifact directory
run: mkdir -p artifacts/${{ matrix.platform.name }}
- name: Copy executable (Unix)
if: matrix.platform.os != 'windows-latest'
run: |
cp target/${{ matrix.platform.target }}/release/${{ matrix.platform.executable }} artifacts/${{ matrix.platform.name }}/
chmod +x artifacts/${{ matrix.platform.name }}/${{ matrix.platform.executable }}
- name: Copy executable (Windows)
if: matrix.platform.os == 'windows-latest'
run: |
Copy-Item "target/${{ matrix.platform.target }}/release/${{ matrix.platform.executable }}" "artifacts/${{ matrix.platform.name }}/"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: sqlx-mcp-${{ matrix.platform.name }}
path: artifacts/${{ matrix.platform.name }}/${{ matrix.platform.executable }}
if-no-files-found: error
release:
name: Create Release
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.create_release)
permissions:
contents: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get release version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
echo "tag_name=${{ inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Create tag (if workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
uses: actions/github-script@v7
with:
script: |
const tag = '${{ inputs.version }}';
const sha = context.sha;
try {
// Create the tag
await github.rest.git.createTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag,
message: `Release ${tag}`,
object: sha,
type: 'commit'
});
// Create the reference
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tag}`,
sha: sha
});
console.log(`Tag ${tag} created successfully`);
} catch (error) {
console.log(`Tag ${tag} might already exist: ${error.message}`);
}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Create release archives
run: |
cd dist
for dir in sqlx-mcp-*; do
platform=${dir#sqlx-mcp-}
cd "$dir"
if [[ "$platform" == *"windows"* ]]; then
zip -r "../sqlx-mcp-$platform.zip" *
else
tar -czf "../sqlx-mcp-$platform.tar.gz" *
fi
cd ..
done
ls -la *.{zip,tar.gz} 2>/dev/null || true
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.tag_name }}
name: Release ${{ steps.version.outputs.version }}
files: |
dist/*.zip
dist/*.tar.gz
body: |
## SQLx MCP Server Release ${{ steps.version.outputs.version }}
Cross-platform binaries for the SQLx MCP Server - A comprehensive database management MCP server.
### Downloads
- **Windows x64**: `sqlx-mcp-windows-x64.zip`
- **Linux x64**: `sqlx-mcp-linux-x64.tar.gz`
- **macOS x64 (Intel)**: `sqlx-mcp-macos-x64.tar.gz`
- **macOS ARM64 (Apple Silicon)**: `sqlx-mcp-macos-arm64.tar.gz`
### Installation
#### Option 1: NPM (Recommended)
```bash
npm install -g @sqlx-mcp/sqlx-mcp
```
#### Option 2: Download Binary
1. Download the appropriate binary for your platform
2. Extract the archive
3. Place the executable in your desired location
### Usage
```bash
# With environment variable
export DATABASE_URL="postgresql://user:pass@localhost/mydb"
sqlx-mcp
# With command line argument
sqlx-mcp --database-url "postgresql://user:pass@localhost/mydb"
```
### Claude Desktop Configuration
```json
{
"mcpServers": {
"sqlx-mcp": {
"command": "sqlx-mcp",
"args": ["--database-url", "your-database-url"]
}
}
}
```
### Documentation
- [Complete Usage Guide](https://github.com/${{ github.repository }}/blob/master/README_USAGE.md)
- [NPM Package Guide](https://github.com/${{ github.repository }}/blob/master/NPM_USAGE.md)
- [Deployment Guide](https://github.com/${{ github.repository }}/blob/master/DEPLOYMENT_GUIDE.md)
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-platform-packages:
name: Publish Platform Packages
runs-on: ubuntu-latest
needs: release
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.create_release)
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Get release version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
# 移除v前缀
VERSION=${VERSION#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Wait for GitHub release
run: |
echo "Waiting for GitHub release to be available..."
sleep 30
# 验证release是否可用
RELEASE_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ steps.version.outputs.version }}"
for i in {1..10}; do
if curl -s "$RELEASE_URL" | grep -q '"tag_name"'; then
echo "Release is available!"
break
fi
echo "Waiting for release... (attempt $i/10)"
sleep 10
done
- name: Download and prepare platform packages
uses: actions/download-artifact@v4
with:
path: dist
- name: Publish platform packages
run: node scripts/publish-platform-packages.js
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
publish-main-package:
name: Publish Main Package
runs-on: ubuntu-latest
needs: publish-platform-packages
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.create_release)
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Get release version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
# 移除v前缀
VERSION=${VERSION#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Publish main package
run: node scripts/publish-main-package.js
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}