-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (55 loc) · 2.29 KB
/
actions.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
name: Deploy
on:
push:
branches: main
env:
VERSION: ${{ github.run_number }}-${{ github.run_attempt }}-${{ github.run_id }}
REPO_NAME: ${{ github.event.repository.name }}
jobs:
main:
runs-on: mbp-13
environment: prod
steps:
- name: checkout code
uses: actions/checkout@v4
- name: install node, update npm
run: |
\. "$HOME/.nvm/nvm.sh"
nvm install --lts
npm i -g npm
- name: install packages, build
run: |
\. "$HOME/.nvm/nvm.sh"
npm pkg delete scripts.prepare
NODE_ENV=${{ secrets.NODE_ENV }} npm ci
npm run build
- name: create .env
run: |
echo "ADMIN_ID=${{ secrets.ADMIN_ID }}" >> .env
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" >> .env
echo "LOGTAIL_TOKEN=${{ secrets.LOGTAIL_TOKEN }}" >> .env
echo "LOG_LEVEL=${{ secrets.LOG_LEVEL }}" >> .env
echo "MONGO_DB_URL=${{ secrets.MONGO_DB_URL }}" >> .env
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
echo "VERSION=${{ env.VERSION }}" >> .env
- name: copy files
run: |
mkdir -p ~/Deployments/${{ env.REPO_NAME }}/${{ env.VERSION }}
cp -a . "$_" && cd "$_"
cd .. && echo ${{ env.VERSION }} > latest
- name: delete old deployments
run: |
cd ~/Deployments/${{ env.REPO_NAME }}
MAX_DEPLOYMENTS=3
ls -td */ | tail -n +$((MAX_DEPLOYMENTS+1)) | xargs rm -rf
# set up pm2 startup, log rotate manually
- name: install, configure pm2
run: |
\. "$HOME/.nvm/nvm.sh"
cd ~/Deployments/${{ env.REPO_NAME }}/${{ env.VERSION }}
npm i -g pm2@latest
pm2 update
pm2 stop ${{ env.REPO_NAME }} || true
pm2 delete ${{ env.REPO_NAME }} || true
pm2 start npm --name ${{ env.REPO_NAME }} --exp-backoff-restart-delay=${{ secrets.RESTART_DELAY }} -- run start
pm2 save