-
Notifications
You must be signed in to change notification settings - Fork 8
74 lines (67 loc) · 2.51 KB
/
push.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
name: Code Deployment and Environment Setup
on:
push:
branches:
- main
jobs:
build:
name: Run remote SSH commands
runs-on: ubuntu-latest
steps:
- name: Clone or pull repository
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.KEY }}
script_stop: false
script: |
if [ -d ${{ secrets.PATH }} ]; then
cd ${{ secrets.PATH }}
git pull
else
mkdir -p ${{ secrets.PATH }}
cd ${{ secrets.PATH }}
git clone [email protected]:${{ github.repository }}.git .
fi
- name: Update environment variables
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.KEY }}
script_stop: false
script: |
# Bash function to replace env variables
replace_env() {
local env_var=$1
local new_value=$2
awk -v var="${env_var}" -v val="${new_value}" -F '=' '{OFS=FS} $1 == var {$2 = val} 1' .env > .env.tmp && mv .env.tmp .env
}
cd ${{ secrets.PATH }}
# Replace .env with vars
replace_env 'NAME' '${{ vars.NAME }}'
replace_env 'ASTRO_HOST' '${{ vars.ASTRO_HOST }}'
replace_env 'PAYLOAD_HOST' '${{ vars.PAYLOAD_HOST }}'
replace_env 'PAYLOAD_URL' '${{ vars.PAYLOAD_URL }}'
replace_env 'PAYLOAD_PORT' '${{ vars.PAYLOAD_PORT }}'
# Replace .env with secrets
replace_env 'PAYLOAD_SECRET' '${{ secrets.PAYLOAD_SECRET }}'
replace_env 'MONGODB_URI' 'mongodb://${{ secrets.MONGODB_USER }}:${{ secrets.MONGODB_PW }}@mongo:27017'
replace_env 'MONGODB_USER' '${{ secrets.MONGODB_USER }}'
replace_env 'MONGODB_PW' '${{ secrets.MONGODB_PW }}'
replace_env 'TOKEN' '${{ secrets.TOKEN }}'
# Replace .env with GitHub repository
replace_env 'REPOSITORY' '${{ github.repository }}'
mkdir -p ./astro
cp .env ./astro/.env
- name: Start Production Services
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.KEY }}
script: |
cd ${{ secrets.PATH }}
yarn prod payload
yarn prod astro