File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Deploy to production
2+ on :
3+ push :
4+ branches :
5+ - main
6+ - develop
7+
8+ jobs :
9+ build-and-deploy :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Checkout repository
14+ uses : actions/checkout@v2
15+
16+ - name : Set up Node.js
17+ uses : actions/setup-node@v2
18+ with :
19+ node-version : ' 20'
20+
21+ - name : Install dependencies
22+ run : npm install
23+
24+ - name : Build project
25+ run : npm run build
26+
27+ - name : Deploy to Self-Hosted Server
28+ env :
29+ SSH_PRIVATE_KEY : ' SHA256:sNWJn78radNW6ErUdZ5R0Hgdeb7rsZ06YXII85MJ5Nw'
30+ SSH_HOST : ' https://server.irpsc.com'
31+ SSH_USERNAME : ' frdevelop2'
32+ REMOTE_DEPLOY_PATH : ' /home/frdevelop2/public_html'
33+ SSH_PORT : 4041
34+ run : |
35+ mkdir -p ~/.ssh
36+ echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
37+ chmod 600 ~/.ssh/id_rsa
38+ ssh-keyscan -p $SSH_PORT $SSH_HOST >> ~/.ssh/known_hosts
39+ rsync -avz --delete ./build/ $SSH_USERNAME@$SSH_HOST:$REMOTE_DEPLOY_PATH
40+
41+ # Set the name of the application
42+ APP_NAME="frdevelop2"
43+
44+ # Check if the application is already running
45+ if ssh -p $SSH_PORT $SSH_USERNAME@$SSH_HOST "pm2 show $APP_NAME &> /dev/null"; then
46+ # Restart the application
47+ ssh -p $SSH_PORT $SSH_USERNAME@$SSH_HOST "pm2 restart $APP_NAME"
48+ else
49+ # Start the application
50+ ssh -p $SSH_PORT $SSH_USERNAME@$SSH_HOST "pm2 start npm start --name $APP_NAME"
51+ fi
You can’t perform that action at this time.
0 commit comments