-
Notifications
You must be signed in to change notification settings - Fork 1
164 lines (143 loc) · 4.82 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: 🚀 Deploy
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
fix-php:
runs-on: ubuntu-latest
name: 🛠 Fix PHP formatting
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
coverage: none
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: 🔍 Read .env
run: grep -E 'PHP_VERSION' .env.prod >> $GITHUB_ENV
- uses: ramsey/composer-install@v3
- run: mkdir -p .tmp/rector
- uses: actions/cache@v3
with:
path: .tmp/rector
key: ${{ runner.os }}-rector-${{ github.run_id }}
restore-keys: ${{ runner.os }}-rector-
- name: Run rector
run: vendor/bin/rector --ansi
- run: mkdir -p .tmp/pint
- name: Cache Pint
uses: actions/cache@v3
with:
path: .tmp/pint.cache
key: ${{ runner.os }}-pint-${{ github.run_id }}
restore-keys: ${{ runner.os }}-pint-
- name: Run pint
run: ./vendor/bin/pint
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix code style
skip_fetch: true
test:
name: Run all tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: password
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
coverage: none
- name: 🔍 Read .env
run: (grep -E 'PHP_VERSION' .env.prod >> $GITHUB_ENV && cp .env.ci .env)
- uses: ramsey/composer-install@v3
- name: 🖱️ Set Node v${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- name: 📥 Install front-end dependencies
run: npm ci --ignore-scripts
- name: 🔨 build front-end
run: npm run build
- name: 🐘 Run PHP tests
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_CONNECTION: mysql
DB_DATABASE: test_db
DB_USERNAME: user
DB_PASSWORD: password
run: (php artisan key:generate && php artisan migrate && php artisan test)
- uses: actions/upload-artifact@v1
if: failure()
with:
name: laravel-failure-artifact
path: storage/logs/laravel.log
deploy:
needs:
- fix-php
- test
name: Deploy
runs-on: ubuntu-latest
env:
BUILD_SOURCE_DIR: .
BUILD_ARTIFACT_STAGING_DIR: build/
BUILD_ARTIFACT_DESTINATION_DIR: /domains/ysbrand.dev/deployment/uploads/
steps:
- name: 🛎️ Checkout project
uses: actions/checkout@v3
- name: 🔍 Read .env
run: grep -E 'PHP_VERSION|NODE_VERSION' .env.prod >> $GITHUB_ENV
- name: 🖱️ Setup PHP v${{ env.PHP_VERSION }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
- uses: ramsey/composer-install@v3
with:
composer-options: "--ignore-platform-reqs --optimize-autoloader --prefer-dist --no-dev"
- name: 🖱️ Set Node v${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- name: 📥 Install front-end dependencies
run: npm ci --ignore-scripts
- name: 🔨 build front-end
run: npm run build
- name: 🗑️ Remove storage directory
run: rm -rf storage
- name: 📁 Create build directory
run: mkdir ${{ env.BUILD_ARTIFACT_STAGING_DIR }}
- name: 🗄️ ZIP Build
uses: TheDoctor0/[email protected]
with:
filename: ${{ env.BUILD_ARTIFACT_STAGING_DIR }}build.zip
path: ${{ env.BUILD_SOURCE_DIR }}
exclusions: 'storage/* build/* node_modules/*'
- name: ➗ Calculate checksum
run: openssl md5 ${{ env.BUILD_ARTIFACT_STAGING_DIR }}build.zip | cut -d" " -f2 > ${{ env.BUILD_ARTIFACT_STAGING_DIR }}checksum.txt
- name: 📂 Sync files
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.HOST_SERVER }}
username: ${{ secrets.FTP_USER }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ${{ env.BUILD_ARTIFACT_STAGING_DIR }}
server-dir: ${{ env.BUILD_ARTIFACT_DESTINATION_DIR }}