-
Notifications
You must be signed in to change notification settings - Fork 0
247 lines (216 loc) Β· 8.67 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: Deploy via ftp
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: build-deploy
jobs:
deploy:
name: Deploy to FTP
runs-on: ubuntu-latest
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
src:
- "Src/**"
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1
with:
versionSpec: "5.x"
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v1
with:
useConfigFile: true
- name: Cache Composer dependencies
uses: actions/cache@v4
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
uses: "php-actions/composer@v6"
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
with:
php_extensions: sockets
dev: no
progress: yes
working_dir: "./Src/"
- name: Create .htaccess secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "Deny from all" >> .htaccess
- name: Create CPanel secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "<?php" >> cPanel.secrets.php
echo "\$cPanelApiToken = \"${{ secrets.CPANEL_API_TOKEN }}\";" >> cPanel.secrets.php
echo "\$cPanelBaseUrl = \"${{ secrets.CPANEL_BASE_URL }}\";" >> cPanel.secrets.php
echo "\$cPanelUsername = \"${{ secrets.CPANEL_USERNAME }}\";" >> cPanel.secrets.php
- name: Create GitHub secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "<?php" >> gitHub.secrets.php
echo "\$gitHubToken = \"${{ secrets.GH_TOKEN }}\";" >> gitHub.secrets.php
- name: Create HealthCheck secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "<?php" >> healthChecksIo.secrets.php
echo "\$healthChecksIoReadKeys[] = \"${{ secrets.HEALTHCHECKSIO_RK1 }}\";" >> healthChecksIo.secrets.php
echo "\$healthChecksIoReadKeys[] = \"${{ secrets.HEALTHCHECKSIO_RK2 }}\";" >> healthChecksIo.secrets.php
echo "\$healthChecksIoReadKeys[] = \"${{ secrets.HEALTHCHECKSIO_RK3 }}\";" >> healthChecksIo.secrets.php
- name: Create MySQL secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "<?php" >> mySql.secrets.php
echo "\$mySqlHost = \"127.0.0.1\";" >> mySql.secrets.php
echo "\$mySqlUser = \"${{ secrets.MYSQL_USER }}\";" >> mySql.secrets.php
echo "\$mySqlPassword = \"${{ secrets.MYSQL_PASSWORD }}\";" >> mySql.secrets.php
echo "\$mySqlDatabase = \"${{ secrets.MYSQL_DATABASE }}\";" >> mySql.secrets.php
- name: Create RabbitMQ secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "<?php" >> rabbitMq.secrets.php
echo "\$rabbitMqConnectionStrings[] = \"${{ secrets.RABBITMQ_CS1 }}\";" >> rabbitMq.secrets.php
echo "\$rabbitMqConnectionStrings[] = \"${{ secrets.RABBITMQ_CS2 }}\";" >> rabbitMq.secrets.php
echo "\$rabbitMqConnectionStrings[] = \"${{ secrets.RABBITMQ_CS3 }}\";" >> rabbitMq.secrets.php
echo "\$rabbitMqConnectionStrings[] = \"${{ secrets.RABBITMQ_CS4 }}\";" >> rabbitMq.secrets.php
echo "\$rabbitMqConnectionStrings[] = \"${{ secrets.RABBITMQ_CS5 }}\";" >> rabbitMq.secrets.php
echo "\$rabbitMqConnectionStrings[] = \"${{ secrets.RABBITMQ_CS6 }}\";" >> rabbitMq.secrets.php
echo "\$rabbitMqConnectionStrings[] = \"${{ secrets.RABBITMQ_CS7 }}\";" >> rabbitMq.secrets.php
- name: Create UpTimeRobot secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "<?php" >> upTimeRobot.secrets.php
echo "\$upTimeRobotToken = \"${{ secrets.UPTIMEROBOT_TOKEN }}\";" >> upTimeRobot.secrets.php
- name: Create Webhooks secrets file
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd Src
mkdir -p secrets
cd secrets
echo "<?php" >> webhooks.secrets.php
echo "\$webhooksApiToken = \"${{ secrets.WEBHOOKS_API_TOKEN }}\";" >> webhooks.secrets.php
- name: Upload files
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ${{ secrets.FTP_SERVER }}
user: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
localDir: "Src/"
remoteDir: "/"
database_migrations:
name: Database migrations
runs-on: ubuntu-latest
needs: [deploy]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check changes in Sql folder
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
sql:
- "Sql/**"
- "Tools/**"
- name: Attach WireGuard connection
shell: bash
run: |
sudo apt install resolvconf
sudo apt install wireguard
echo "${{ secrets.WIREGUARD_CONFIG }}" > wg0.conf
sudo chmod 600 wg0.conf
sudo wg-quick up ./wg0.conf
- name: Check if the schema version table exists
id: new_installation
if: steps.changes.outputs.sql == 'true' || github.event_name == 'workflow_dispatch'
env:
MYSQL_PWD: ${{ secrets.MYSQL_PASSWORD_MIGRATION }}
run: |
chmod +x Tools/db-check.sh
Tools/db-check.sh "${{ secrets.MYSQL_SERVER }}" "${{ secrets.MYSQL_USER_MIGRATION }}" "${{ secrets.MYSQL_DATABASE }}"
- name: Run database migrations
if: steps.changes.outputs.sql == 'true' || github.event_name == 'workflow_dispatch' || steps.new_installation.outputs.not_found == 'true'
env:
MYSQL_PWD: ${{ secrets.MYSQL_PASSWORD_MIGRATION }}
run: |
chmod +x Tools/db-migration.sh
Tools/db-migration.sh Sql "${{ secrets.MYSQL_SERVER }}" "${{ secrets.MYSQL_USER_MIGRATION }}" "${{ secrets.MYSQL_DATABASE }}"
- name: Detach WireGuard connection
shell: bash
run: sudo wg-quick down ./wg0.conf
automated-api-tests:
name: Automated API tests (Postman)
runs-on: ubuntu-latest
needs: [deploy, database_migrations]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check changes
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
any:
- "Sql/**"
- "Src/**"
- "Tools/**"
- name: Install Postman CLI
run: |
curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh
- name: Login to Postman CLI
run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }}
- name: Run API tests
run: |
postman collection run 23511-01109172-13a0-4cdb-bd0c-18a71d624a48 -e 23511-95105c79-d4eb-4388-9ff9-eb5dee83fdcf
create_release:
name: Create release
needs: [deploy, database_migrations, automated-api-tests]
env:
SEMVER: ${{ needs.deploy.outputs.semVer }}
runs-on: ubuntu-latest
steps:
- name: Create Release
uses: ncipollo/release-action@v1.14.0
with:
skipIfReleaseExists: true
allowUpdates: false
draft: false
makeLatest: true
tag: v${{ env.SEMVER }}
name: Release v${{ env.SEMVER }}
generateReleaseNotes: true
body: Release ${{ env.SEMVER }} of ${{ github.repository }}