Skip to content

webhook

webhook #12

name: "Deploy Staging"
on:
push:
branches:
- dev
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 10
environment: staging
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add server to known hosts
run: |
ssh-keyscan -H ${{ secrets.STAGING_IP }} >> ~/.ssh/known_hosts
- name: Deploy via SSH
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.STAGING_IP }} '
set -e
export GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"
cd /home/modl/modl-admin
git stash
git pull origin dev
if git diff --name-only HEAD@{1} HEAD | grep -q "^package.*\.json$"; then
npm ci
fi
if git diff --name-only HEAD@{1} HEAD | grep -q "^client/package.*\.json$"; then
cd client
npm ci
cd ..
fi
npm run build
pm2 reload modl-admin --wait-ready
if pm2 describe modl-admin | grep -q "online"; then
echo "PM2 process is running successfully"
else
echo "Error: PM2 process failed to start"
exit 1
fi
'
- name: Notify on failure
if: failure()
run: |
echo "Deployment failed! Check the logs."