-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (80 loc) · 2.74 KB
/
build.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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Build and Deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 20.x ]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8.14.0
- name: pnmp, build, and test
run: |
pnpm install
pnpm build
pnpm test
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to Azure
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 400 private_key
ssh -o StrictHostKeyChecking=no -i private_key [email protected] '
# Load nvm and dependencies
source /home/hd/.nvm/nvm.sh
source /home/hd/.bashrc
source /home/hd/.profile
export PNPM_HOME="/home/hd/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
nvm use node
# Ensure the directory exists
DIR=/home/hd/base-nest-api
if [ ! -d $DIR ]
then
git clone https://github.com/gabrielmaialva33/base-nest-api.git $DIR
else
echo "Directory $DIR already exists"
fi
cd $DIR
rm -rf $DIR/dist
git checkout main && git fetch --all && git reset --hard origin/main && git pull origin main
# Install dependencies, prune the database, run migrations and seeds, and build the app
pnpm install && pnpm db:prune:sqlite && pnpm db:migrate && pnpm db:seed && pnpm build
# Check if the app is running and kill it
if [ $(tmux ls | grep base-nest-api | wc -l) -gt 0 ]
then
tmux kill-session -t base-nest-api
echo "Session killed. 🗡️"
else
echo "No session to kill. 🤷"
fi
# Start the app
tmux new-session -d -s base-nest-api 'pnpm start:prod'
echo "Session started. 🚀"
# Check if the app is running
if [ $(tmux ls | grep -c "base-nest-api") -eq 1 ]
then
echo "App is running. ✅"
else
echo "App is not running. ❌"
exit 1
fi
echo "Deployed successfully. 🎉"
exit 0
'