Skip to content

Fix .sh scripts

Fix .sh scripts #4

name: Auto-update app on development VPS
on:
push:
branches:
- dev
jobs:
deploy:
name: Deploy latest updates to development server
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run commands on remote VPS server
env:
PRIVATE_KEY: ${{secrets.PRIVATE_KEY}}
HOSTNAME: ${{secrets.PROD_HOST}}
USER_NAME: ${{secrets.PROD_USER}}
GITHUB_TOKEN: ${{secrets.SMTP_DEPLOYMENT_KEY}}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
echo 'Script execution started'
cd /var/www/
echo 'Stopping application'
pm2 stop all
echo 'Removing old project'
sudo rm -r -f ./smtp_server/
mkdir smtp_server
cd smtp_server
echo 'Initialization empty local repository'
git init
echo 'Adding remote repository'
git remote add origin https://$GITHUB_TOKEN@github.com/yunusmi/smtp_server.git
git pull origin dev
if [ $? -eq 0 ]; then
echo 'GIT pull success'
else
echo 'GIT pull failure'
exit 1;
fi
echo 'Install nodejs dependencies'
npm ci
echo 'Finished installing nodejs dependencies'
echo 'Building application'
npm run build
echo 'Building was completed successfully'
echo 'Starting application'
npx pm2 start ./dist/main.js
echo 'Application started successfully'
pm2 save
echo 'Script execution completed'
'