-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (67 loc) · 2.53 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
name: Deploy
on:
push:
branches:
- master
pull_request:
types:
- opened
- reopened
- synchronize
env:
BUILD_SCRIPT: yarn stand:build
BUILD_SCRIPT_OUTPUT: build
APP_NAME: stats
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Делаем checkout текущей ветки
- uses: actions/checkout@master
# Устанавливаем Node.JS для сборки приложения
- uses: actions/setup-node@v1
with:
node-version: 18
- name: Install yarn
id: yarn-setup
run: |
yarn policies set-version 1.22.18
echo "::set-output name=cache_dir::$(yarn cache dir)"
- name: Настройка кэширования yarn
uses: actions/cache@v2
with:
path: ${{ steps.yarn-setup.outputs.cache_dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn --frozen-lockfile
# Записываем в переменные окружения имя текущей ветки
# Чтобы избежать конфиликтов с URL, меняем точки на _, а слеши на минусы
- name: Get branch name
shell: bash
run: |
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g' | sed 's/\./_/g')" >> $GITHUB_ENV
# Собираем приложение
- name: Build Appliction
run: $BUILD_SCRIPT
# Доставляем собранное приложение на сервер
- name: Deploy to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEPLOY_SERVER_HOST }}
username: ${{ secrets.DEPLOY_SERVER_USERNAME }}
key: ${{ secrets.DEPLOY_SERVER_KEY }}
source: ${{ env.BUILD_SCRIPT_OUTPUT }}
target: /srv/www/${{ env.APP_NAME }}/${{ env.BRANCH_NAME }}
strip_components: 1
overwrite: true
rm: true
- name: Print Info
run: echo "🎉 Deployed at https://${{env.BRANCH_NAME}}---${{env.APP_NAME}}.${{secrets.DEPLOY_DOMAIN}}"
- name: Add comment
if: ${{ github.event_name == 'pull_request'}}
uses: allthatjazzleo/actions-pull-request-add-comment@master
with:
message: '🎉 **Deployed at** https://${{env.BRANCH_NAME}}---${{env.APP_NAME}}.${{secrets.DEPLOY_DOMAIN}}'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}