-
Notifications
You must be signed in to change notification settings - Fork 1
115 lines (104 loc) · 4.08 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
name: Deploy
on:
pull_request:
branches:
- develop
jobs:
deploy:
runs-on: ubuntu-latest
env:
TARGET: ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }}
KEY: /tmp/private-key
DIR: "~/motsflex-save"
DICOS: "~/dicos"
PUBLIC: "~/motsflex-save/public"
SERVER: "~/motsflex-save/server.js"
ASSETS: "$PUBLIC/assets"
INDEX_HTML: "$PUBLIC/index.html"
# if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup ssh
run: |
mkdir -p ~/.ssh/ && touch ~/.ssh/known_hosts
ssh-keyscan ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
echo "${{ secrets.SSH_PRIVATE_KEY }}" > $KEY
chmod 600 $KEY
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Determine Deployment Type
if: ${{ success() }}
run: |
echo "DEPLOY_ASSETS=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:assets') }}" >> $GITHUB_ENV
echo "DEPLOY_SERVER=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:server') }}" >> $GITHUB_ENV
echo "DEPLOY_CLIENT=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:client') }}" >> $GITHUB_ENV
# if [[ ${{env.DEPLOY_ASSETS}} ='false' && ${{env.DEPLOY_SERVER}} ='false' && ${{env.DEPLOY_CLIENT}} ='false' ]]; then
# exit 1;
# fi
- name: Install Dependencies
if: ${{ success() }}
run: npm ci
- name: Build
if: ${{ success() }}
run: npm run build
- name: Deploy
if: ${{ success() }}
run: |
if [ "$DEPLOY_ASSETS" = 'true' ]; then
echo "Deploying JS assets"
ssh -i $KEY $TARGET "rm -rf ${{ env.ASSETS }} && mkdir -p ${{ env.ASSETS }}"
scp -i $KEY -r dist/public/assets "$TARGET:${{ env.ASSETS }}"
scp -i $KEY -r dist/public/index.html "$TARGET:${{$ env.INDEX_HTML }}"
# scp "${{ env.SSH }} "
# rm -rf $PUBLIC/assets && mkdir -p $PUBLIC/assets
# cp -r dist/public/assets $PUBLIC/assets
# cp -r dist/public/index.html $PUBLIC/index.html
fi
# if [ "$DEPLOY_CLIENT" = 'true' ]; then
# echo "Deploying full client"
# rm -rf $PUBLIC && mkdir -p $PUBLIC
# cp -r dist/public $PUBLIC
# cp $DICOS/*.zip $PUBLIC/assets
# fi
# if [ "$DEPLOY_SERVER" = 'true' ]; then
# echo "Deploying server code"
# cp -r dist/server.js $SERVER
# fi
- name: Cleanup
run: "rm -f $KEY && rm -rf ~/.ssh"
# - name: Deploy
# uses: appleboy/ssh-action@master
# env:
# DEPLOY_ASSETS: "${{ env.DEPLOY_ASSETS }}"
# DEPLOY_SERVER: "${{ env.DEPLOY_SERVER }}"
# DEPLOY_CLIENT: "${{ env.DEPLOY_CLIENT }}"
# with:
# host: ${{ secrets.SERVER_HOST }}
# username: ${{ secrets.SERVER_USERNAME }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
# port: 22
# envs: DEPLOY_ASSETS,DEPLOY_SERVER,DEPLOY_CLIENT,PUBLIC,ASSETS,INDEX_HTML,DICOS,SERVER
# script: |
# cd ~/tmp/mots-fleches
# git pull origin develop
# npm install
# npm run build
# if [ "$DEPLOY_ASSETS" = 'true' ]; then
# echo "Deploying JS assets"
# rm -rf $ASSETS && mkdir -p $ASSETS
# cp -r dist/public/assets $ASSETS
# cp -r dist/public/index.html $INDEX_HTML
# fi
# if [ "$DEPLOY_CLIENT" = 'true' ]; then
# echo "Deploying full client"
# rm -rf $PUBLIC && mkdir -p $PUBLIC
# cp -r dist/public $PUBLIC
# cp $DICOS/*.zip $ASSETS
# fi
# if [ "$DEPLOY_SERVER" = 'true' ]; then
# echo "Deploying server code"
# cp -r dist/server.js $SERVER
# fi