name: Deploy to Azure App Service
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
AZURE_WEBAPP_NAME: bitrix24-mcp-server
AZURE_WEBAPP_PACKAGE_PATH: '.'
NODE_VERSION: '18.x'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build TypeScript
run: npm run build
- name: Run tests
run: npm test
continue-on-error: true
- name: Create deployment package
run: |
# Create a clean deployment directory
mkdir deployment
# Copy necessary files
cp package.json deployment/
cp package-lock.json deployment/
cp server.js deployment/
cp web.config deployment/
cp -r build deployment/
# Copy source files for reference (optional)
cp -r src deployment/
# Create production package.json (remove dev dependencies)
cd deployment
npm ci --only=production
# Go back to root
cd ..
- name: Deploy to Azure Web App
if: github.ref == 'refs/heads/main'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: './deployment'
- name: Configure App Settings
if: github.ref == 'refs/heads/main'
uses: azure/appservice-settings@v1
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
app-settings-json: |
[
{
"name": "BITRIX24_WEBHOOK_URL",
"value": "${{ secrets.BITRIX24_WEBHOOK_URL }}",
"slotSetting": false
},
{
"name": "NODE_ENV",
"value": "production",
"slotSetting": false
},
{
"name": "LOG_LEVEL",
"value": "info",
"slotSetting": false
}
]
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
- name: Restart App Service
if: github.ref == 'refs/heads/main'
run: |
# Wait a moment for settings to apply
sleep 10
# The app will restart automatically after settings change
- name: Test deployment
if: github.ref == 'refs/heads/main'
run: |
sleep 30
echo "Testing health endpoint..."
curl -f https://${{ env.AZURE_WEBAPP_NAME }}.azurewebsites.net/health || exit 1
echo "Testing MCP webhook validation..."
curl -X POST https://${{ env.AZURE_WEBAPP_NAME }}.azurewebsites.net/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "bitrix24_validate_webhook",
"arguments": {}
},
"id": 1
}' || echo "MCP test failed - check environment variables"