Skip to content

Workflow file for this run

name: Deploy to Azure App Service
on:
push:
branches:
- master
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-deploy:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
node-version: [20]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1 # Only fetch the latest commit
- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run security audit
run: npm audit
- name: Build
env:
NODE_ENV: production
SKIP_LINT: true
run: npm run build
- name: Prepare deployment package
run: |
mkdir deploy
cp -r dist server node_modules package.json deploy/
cd deploy
zip -9 -r ../package.zip . # Maximum compression
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure App Service
id: deploy
uses: azure/webapps-deploy@v3
with:
app-name: uptime-kuma-version-three
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: package.zip
clean: true
- name: Verify Deployment
run: |
# Wait for deployment to stabilize
sleep 30
# Get deployment status
DEPLOY_STATUS=$(az webapp show --name uptime-kuma-version-three --resource-group TestRG --query state -o tsv)
if [ "$DEPLOY_STATUS" != "Running" ]; then
echo "Deployment verification failed. Status: $DEPLOY_STATUS"
exit 1
fi
- name: Restart App Service
if: success() # Only run if previous steps succeeded
run: |
az webapp restart --name uptime-kuma-version-three --resource-group TestRG
- name: Update App Settings
if: success()
uses: azure/CLI@v1
with:
inlineScript: |
az webapp config appsettings set \
--name uptime-kuma-version-three \
--resource-group TestRG \
--settings \
STARTUP_COMMAND="node server/server.js" \
NODE_ENV="production" \
WEBSITES_PORT="3001" \
SCM_DO_BUILD_DURING_DEPLOYMENT="false"
- name: Notify on Failure
if: failure()
uses: actions/github-script@v6
with:
script: |
const issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Deployment Failed',
body: `Deployment failed in workflow run: ${context.workflow_run_id}`
});
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}