Skip to content

Merge pull request #7 from gikuser/rework2 #3

Merge pull request #7 from gikuser/rework2

Merge pull request #7 from gikuser/rework2 #3

name: Deploy to Staging Environment
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
deploy-staging:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
- name: Build React App
run: npm run build-react
- name: Copy Files to Staging Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_STAGING }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: "./*"
target: "/home/ubuntu/app"
- name: Start Application on Staging
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_STAGING }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ubuntu/app
npm install --production
pm2 restart all || pm2 start index.js --name "react-node-app"
pm2 save
- name: Send Success Email
if: success()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: Deployment to STAGING Successful
body: |
Changes have been merged to main and deployed to Staging.
Access it here: http://${{ secrets.HOST_STAGING }}:3000
to: ${{ secrets.QA_EMAIL }}
from: DevOps Automation