-
Notifications
You must be signed in to change notification settings - Fork 5
136 lines (135 loc) · 6.24 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Deploy PROD
env:
JWT_SIGNATURE: ${{ vars.JWT_SIGNATURE }}
CORS_ALLOW_URL: ${{ vars.CORS_ALLOW_URL }}
API_PORT: ${{ vars.API_PORT }}
CLIENT_ID: ${{ vars.CLIENT_ID }}
CLIENT_SECRET: ${{ vars.CLIENT_SECRET }}
on:
push:
branches:
- dev
- main
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Set ENV
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "SERVER_HOST=${{ vars.PROD_SERVER_HOST }}" >> $GITHUB_ENV
echo "SERVER_USERNAME=${{ vars.PROD_SERVER_USERNAME }}" >> $GITHUB_ENV
elif [ "${{ github.ref }}" == "refs/heads/dev" ]; then
echo "SERVER_HOST=${{ vars.DEV_SERVER_HOST }}" >> $GITHUB_ENV
echo "SERVER_USERNAME=${{ vars.DEV_SERVER_USERNAME }}" >> $GITHUB_ENV
fi
- name: Deploy to Server
uses: appleboy/ssh-action@master
with:
host: ${{ env.SERVER_HOST }}
username: ${{ env.SERVER_USERNAME }}
key: ${{ vars.SSH_PRIVATE_KEY }}
port: ${{ vars.SSH_PORT }}
script: |
echo "--------"
echo "### CMD: cd BikeHub"
cd BikeHub
echo "Done!"
echo "--------"
echo "### CMD: git reset --hard"
git reset --hard
echo "Done!"
echo "--------"
echo "### CMD: find . -name 'package-lock.json' -exec rm -f {} +"
find . -name 'package-lock.json' -exec rm -f {} +
echo "### CMD: find . -name 'yarn.lock' -exec rm -f {} +"
find . -name 'yarn.lock' -exec rm -f {} +
echo "Done!"
echo "--------"
branch_name=$(basename "${{ github.ref }}")
echo "### CMD: git switch $branch_name"
git switch "$branch_name"
echo "Done!"
echo "--------"
echo "### CMD: git pull origin $branch_name"
git pull origin $branch_name
echo "Done!"
echo "--------"
echo "### CMD: npm install &deploy.txt& yarn install"
npm install && yarn install
echo "Done!"
echo "--------"
echo "### CMD: cd ~/BikeHub/api && cp .env.example .env"
cd ~/BikeHub/api && cp .env.example .env
echo "Done!"
echo "--------"
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "start deploying in ${{ github.ref }}"
echo "### CMD: change VITE_MODE to prod"
sed -i 's/^VITE_MODE=.*/VITE_MODE=prod/' ~/BikeHub/frontend/.env
echo "Done!"
echo "### CMD: change DB_MODE/NODE_ENV to local"
sed -i 's/^NODE_ENV=.*/NODE_ENV=prod/' ~/BikeHub/api/.env
sed -i 's/^DB_MODE=.*/DB_MODE=local/' ~/BikeHub/api/.env
echo "Done!"
echo "### CMD: cd ~/BikeHub/api && yarn build"
cd ~/BikeHub/api && yarn build
echo "### CMD: pm2 reload startapi --update-env"
pm2 reload startapi --update-env
echo "### CMD: cd ~/BikeHub/frontend && yarn build"
cd ~/BikeHub/frontend && yarn build
echo "### CMD: pm2 reload startfrontend --update-env"
pm2 reload startfrontend --update-env
echo "### CMD: pm2 reload prisma --update-env"
pm2 reload prisma --update-env
echo "### CMD: update deploy.txt"
echo "---------------------------" >> deploy.txt
echo "Date: $(date)" >> deploy.txt
echo "Branch: ${{ github.ref }}" >> deploy.txt
echo "Last Commit Message: ${{ github.event.head_commit.message }}" >> deploy.txt
echo "Last Commit Author: ${{ github.event.head_commit.author.name }}" >> deploy.txt
echo "Pusher: ${{ github.actor }}" >> deploy.txt
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "Pull Request Author: ${{ github.event.pull_request.user.login }}" >> deploy.txt
echo "Merged By: ${{ github.event.pull_request.merged_by.login }}" >> deploy.txt
fi
echo "### CMD: cp deploy.txt dist/deploy.txt"
cp deploy.txt dist/deploy.txt
echo "Done!"
fi
if [ "${{ github.ref }}" = "refs/heads/dev" ]; then
echo "start deploying in ${{ github.ref }}"
echo "### CMD: change VITE_MODE to dev"
sed -i 's/^VITE_MODE=.*/VITE_MODE=dev/' ~/BikeHub/frontend/.env
echo "Done!"
echo "### CMD: change DB_MODE/NODE_ENV to local"
sed -i 's/^NODE_ENV=.*/NODE_ENV=dev/' ~/BikeHub/api/.env
sed -i 's/^DB_MODE=.*/DB_MODE=local/' ~/BikeHub/api/.env
echo "Done!"
echo "### CMD: cd ~/BikeHub/api && yarn build"
cd ~/BikeHub/api && yarn build
echo "### CMD: pm2 reload startapi --update-env"
pm2 reload startapi --update-env
echo "### CMD: cd ~/BikeHub/frontend && yarn build"
cd ~/BikeHub/frontend && yarn build
echo "### CMD: pm2 reload startfrontend --update-env"
pm2 reload startfrontend --update-env
echo "### CMD: pm2 reload prisma --update-env"
pm2 reload prisma --update-env
echo "### CMD: update deploy.txt"
echo "---------------------------" >> deploy.txt
echo "Date: $(date)" >> deploy.txt
echo "Branch: ${{ github.ref }}" >> deploy.txt
echo "Last Commit Message: ${{ github.event.head_commit.message }}" >> deploy.txt
echo "Last Commit Author: ${{ github.event.head_commit.author.name }}" >> deploy.txt
echo "Pusher: ${{ github.actor }}" >> deploy.txt
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "Pull Request Author: ${{ github.event.pull_request.user.login }}" >> deploy.txt
echo "Merged By: ${{ github.event.pull_request.merged_by.login }}" >> deploy.txt
fi
echo "### CMD: cp deploy.txt dist/deploy.txt"
cp deploy.txt dist/deploy.txt
echo "Done!"
fi
echo "--------"