-
Notifications
You must be signed in to change notification settings - Fork 2
142 lines (122 loc) · 4.26 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: "🏗️ Build and deploy"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
run-tests:
name: "🧪 Run tests"
runs-on: ubuntu-20.04
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: mondegc_testing
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout full repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Detect secrets
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_NOTIFY_USER_LIST: '@Roxayl'
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: curl, gd, iconv, json, mbstring, pdo, pdo_mysql, zip
- name: Install PHP dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Initialize environment and database
env:
DB_HOST: 127.0.0.1
DB_PASSWORD: root
DB_DATABASE: mondegc_testing
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
run: |
chmod -R 777 storage bootstrap/cache
php artisan monde:init-env
php artisan monde:init-testing
php artisan migrate -v
- name: Execute unit and feature tests via PHPUnit
env:
DB_HOST: 127.0.0.1
DB_PASSWORD: root
DB_DATABASE: mondegc_testing
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
run: php artisan test
run-backups:
name: "💾 Run backups"
runs-on: ubuntu-20.04
needs: run-tests
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Backup user files and database
uses: appleboy/[email protected]
with:
host: ${{ secrets.PROD_SSH_HOST }}
port: ${{ secrets.PROD_SSH_PORT }}
username: ${{ secrets.PROD_SSH_USERNAME }}
password: ${{ secrets.PROD_SSH_PASSWORD }}
script_stop: true
script: |
cd "${{ vars.PROD_FULL_DIR }}"
php artisan backup:run
deploy-to-prod:
name: "🚀 Deploy to production"
runs-on: ubuntu-20.04
needs: run-backups
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Prepare deployment
uses: appleboy/[email protected]
with:
host: ${{ secrets.PROD_SSH_HOST }}
port: ${{ secrets.PROD_SSH_PORT }}
username: ${{ secrets.PROD_SSH_USERNAME }}
password: ${{ secrets.PROD_SSH_PASSWORD }}
script: |
cd "${{ vars.PROD_FULL_DIR }}"
php artisan down --refresh=60 --retry=60
- name: Deploy sources
uses: SamKirkland/[email protected]
with:
protocol: ftps
server: ${{ secrets.PROD_SSH_HOST }}
port: ${{ secrets.PROD_FTP_PORT }}
username: ${{ secrets.PROD_SSH_USERNAME }}
password: ${{ secrets.PROD_SSH_PASSWORD }}
local-dir: ./
server-dir: ${{ vars.PROD_FTP_DIR }}
exclude: |
**/.git*
**/.git*/**
**/node_modules/**
log-level: standard
- name: Cleanup deployment
uses: appleboy/[email protected]
with:
host: ${{ secrets.PROD_SSH_HOST }}
port: ${{ secrets.PROD_SSH_PORT }}
username: ${{ secrets.PROD_SSH_USERNAME }}
password: ${{ secrets.PROD_SSH_PASSWORD }}
script: |
cd "${{ vars.PROD_FULL_DIR }}"
composer install --no-dev --classmap-authoritative --no-ansi --no-interaction --no-progress
BUILD_NUMBER=${{ github.run_number }}
find ./.env -type f -exec sed -i '' -e "/^APP_BUILD=/s/=.*/=\'$BUILD_NUMBER\'/" {} \;
php artisan optimize:clear
php artisan migrate --force
php artisan monde:generate-htaccess
php artisan monde:regenerate-influences
php artisan scribe:generate
php artisan up