forked from cmangos/classic-db
-
Notifications
You must be signed in to change notification settings - Fork 0
309 lines (278 loc) · 14.1 KB
/
build-release.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
name: Build Release
on:
schedule:
# every day at 6am
- cron: '0 6 * * *'
env:
MYSQL_BIN_NAME: "mysql-8.0.28-winx64"
MYSQL_BASE_PREBUILD_ADR: "https://dev.mysql.com/get/Downloads/MySQL-8.0/"
MYSQL_BIN_EXT: ".zip"
MYSQL_FINAL_SERVER_FOLDER: "mysql-server"
MYSQL_DEFAULT_ROOT: "cmangos"
CACHED_FOLDER: "${{github.workspace}}\\CachedFolder"
WORK_FOLDER: "${{github.workspace}}\\WorkFolder"
jobs:
build:
runs-on: windows-2022
permissions:
contents: write
steps:
- name: Set Environmental Variables
run: |
echo "MYSQL_BIN_ARCH=${{env.MYSQL_BIN_NAME}}${{env.MYSQL_BIN_EXT}}" >> $env:GITHUB_ENV
echo "MYSQL_PREBUILD_ADR=${{env.MYSQL_BASE_PREBUILD_ADR}}${{env.MYSQL_BIN_NAME}}${{env.MYSQL_BIN_EXT}}" >> $env:GITHUB_ENV
$projectNames = "${{github.repository}}".Split("/")[1]
$expansion="${projectNames}".Split("-")[0]
echo "LAST_BACKUP_ADR=https://github.com/cmangos/${expansion}-db/releases/download/latest/${expansion}-all-backups.tar.gz" >> $env:GITHUB_ENV
echo "BOTS_REPO=cmangos/playerbots" >> $env:GITHUB_ENV
echo "CORE_REPO=cmangos/mangos-${expansion}" >> $env:GITHUB_ENV
echo "CORE_FOLDER=${{github.workspace}}\mangos-${expansion}" >> $env:GITHUB_ENV
echo "DB_FOLDER=${{github.workspace}}\${expansion}-db" >> $env:GITHUB_ENV
echo "EXPANSION_NAME=${expansion}" >> $env:GITHUB_ENV
echo "PROJECT_NAME=cmangos-${expansion}" >> $env:GITHUB_ENV
echo "WORLD_DB_NAME=${expansion}mangos" >> $env:GITHUB_ENV
echo "CHAR_DB_NAME=${expansion}characters" >> $env:GITHUB_ENV
echo "REALM_DB_NAME=${expansion}realmd" >> $env:GITHUB_ENV
echo "LOGS_DB_NAME=${expansion}logs" >> $env:GITHUB_ENV
md -Force "${{env.CACHED_FOLDER}}"
md -Force "${{env.WORK_FOLDER}}"
- name: Checkout DB
uses: actions/checkout@v2
with:
path: ${{env.DB_FOLDER}}
- name: Checkout CORE
uses: actions/checkout@v2
with:
repository: ${{env.CORE_REPO}}
path: ${{env.CORE_FOLDER}}
- name: Create modules folder
run: |
mkdir -p ${{env.CORE_FOLDER}}/src/modules
- name: Checkout PlayerBots
uses: actions/checkout@v2
with:
repository: ${{env.BOTS_REPO}}
path: ${{env.CORE_FOLDER}}/src/modules/PlayerBots
- name: Cache MySQL Official .zip
uses: actions/cache@v2
id: cache-mysqldownload
with:
path: "${{env.CACHED_FOLDER}}"
key: ${{ runner.os }}-${{ hashFiles('.github/workflows/build-release.yml') }}
- if: steps.cache-mysqldownload.outputs.cache-hit != 'true'
name: Download official mysql prebuild server
run: |
$MysqlArchive = Join-Path ${{env.CACHED_FOLDER}} ${{env.MYSQL_BIN_ARCH}}
if (-not(Test-Path -Path ${MysqlArchive} -PathType Leaf))
{
try
{
(New-Object System.Net.WebClient).DownloadFile("${{env.MYSQL_PREBUILD_ADR}}", "${MysqlArchive}");
}
catch [Net.WebException]
{
Write-Host $_.Exception.ToString()
exit 1
}
}
- name: Extract MySQL Archive
run: |
$MysqlArchive = Join-Path ${{env.CACHED_FOLDER}} ${{env.MYSQL_BIN_ARCH}}
Expand-Archive -LiteralPath "${MysqlArchive}" -DestinationPath "${{env.WORK_FOLDER}}" | Out-Null
Rename-Item "${{env.WORK_FOLDER}}\${{env.MYSQL_BIN_NAME}}" "${{env.WORK_FOLDER}}\${{env.MYSQL_FINAL_SERVER_FOLDER}}"
- name: Add Default Config Files and Batch File
run: |
$DefaultConfFile = "# For advice on how to change settings please see`n"
$DefaultConfFile +="# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html`n"
$DefaultConfFile +="`n"
$DefaultConfFile +="[mysqld]`n"
$DefaultConfFile +="`n"
$DefaultConfFile +="basedir = `"${{env.MYSQL_FINAL_SERVER_FOLDER}}`"`n"
$DefaultConfFile +="datadir = `"data`"`n"
$DefaultConfFile +="port = 3306`n"
$BatchFile ="@echo off`n"
$BatchFile +="COLOR F`n"
$BatchFile +="echo ***************************`n"
$BatchFile +="echo * MySQL for CMaNGOS cores *`n"
$BatchFile +="echo * PORT : 3306 *`n"
$BatchFile +="echo ***************************`n"
$BatchFile +="echo.`n"
$BatchFile +="echo MySQL for CMaNGOS is currently running.`n"
$BatchFile +="echo Do not close this windows before your CORE server!`n"
$BatchFile +="echo You can use '.server shutdown 1' on your server console for that.`n"
$BatchFile +="echo You can also close this windows by pressing CTRL + C.`n"
$BatchFile +="echo. `n"
$BatchFile +="echo.`n"
$BatchFile +="`n"
$BatchFile +="for /f %%i in ('dir /a /b ${{env.MYSQL_FINAL_SERVER_FOLDER}}\data') do goto notempty`n"
$BatchFile +="echo First run detected!`n"
$BatchFile +="echo Please wait while initilizing database for first use...`n"
$BatchFile +="${{env.MYSQL_FINAL_SERVER_FOLDER}}\bin\mysqld --defaults-file=${{env.MYSQL_FINAL_SERVER_FOLDER}}\my.ini --initialize-insecure`n"
$BatchFile +="echo !!! YOUR ATTENTION PLEASE !!!`n"
$BatchFile +="echo For your security you have to set a password for root user`n"
$BatchFile +="echo You can do it with the following command`n"
$BatchFile +="echo %CD%\${{env.MYSQL_FINAL_SERVER_FOLDER}}\bin\mysql -uroot -e `"SET PASSWORD = 'Your_Password';`"`n"
$BatchFile +="`n"
$BatchFile +="`n"
$BatchFile +=":notempty`n"
$BatchFile +="${{env.MYSQL_FINAL_SERVER_FOLDER}}\bin\mysqld --defaults-file=${{env.MYSQL_FINAL_SERVER_FOLDER}}\my.ini --standalone --console`n"
$BatchFile +="if errorlevel 1 goto errorstarting`n"
$BatchFile +="goto finish`n"
$BatchFile +="`n"
$BatchFile +=":errorstarting`n"
$BatchFile +="echo.`n"
$BatchFile +="echo ERROR: the MySQL service could not be started.`n"
$BatchFile +="echo Please check if no other MySQL server is running.`n"
$BatchFile +="pause`n"
$BatchFile +="exit 1`n"
$BatchFile +="`n"
$BatchFile +=":finish`n"
$BatchFile +="echo MySQL server is now stopped.`n"
$BatchFile +="pause`n"
$BatchFile +="exit 0`n"
$DefaultConfFile | Out-File -FilePath "${{env.WORK_FOLDER}}\${{env.MYSQL_FINAL_SERVER_FOLDER}}\my.ini" -Encoding ASCII
$BatchFile | Out-File -FilePath "${{env.WORK_FOLDER}}\start-server.bat" -Encoding ASCII
- name: Start MySQL Server
run: |
cd ${{env.WORK_FOLDER}}
$env:Path = "${{env.WORK_FOLDER}}\${{env.MYSQL_FINAL_SERVER_FOLDER}}\bin;$env:Path";
Start-Process cmd.exe "/c ${{env.WORK_FOLDER}}\start-server.bat"
$count = 0
while($true)
{
Start-Sleep -s 5
mysql -uroot --connect-timeout=2 -s -e';' | Out-Null
if ($LastExitCode -eq 0)
{
Write-Host "Success"
mysql -uroot -e"SET PASSWORD = '${{env.MYSQL_DEFAULT_ROOT}}';"
if ($LastExitCode -ne 0)
{
exit 1
}
break
}
else
{
if ($count -gt 30)
{
Write-Host "Fail"
exit 1
}
}
$count = $count + 1
}
- name: Build ${{env.EXPANSION_NAME}}
run: |
cd "${{env.DB_FOLDER}}"
bash InstallFullDB.sh -InstallAll root cmangos DeleteAll
- name: Dumping All DBs
run: |
$env:Path = "${{env.WORK_FOLDER}}\${{env.MYSQL_FINAL_SERVER_FOLDER}}\bin;$env:Path";
$finalFullDBFolder="${{github.workspace}}\sql"
md -Force "${finalFullDBFolder}" | Out-Null
echo "FINAL_SQL_FOLDER=${finalFullDBFolder}" >> $env:GITHUB_ENV
$env:MYSQL_PWD="${{env.MYSQL_DEFAULT_ROOT}}";
mysqldump -u root ${{env.WORLD_DB_NAME}} > "${finalFullDBFolder}\${{env.WORLD_DB_NAME}}.sql";
mysqldump -u root ${{env.CHAR_DB_NAME}} > "${finalFullDBFolder}\${{env.CHAR_DB_NAME}}.sql";
mysqldump -u root ${{env.REALM_DB_NAME}} > "${finalFullDBFolder}\${{env.REALM_DB_NAME}}.sql";
mysqldump -u root ${{env.LOGS_DB_NAME}} > "${finalFullDBFolder}\${{env.LOGS_DB_NAME}}.sql";
- name: Stopping MySQL Server
run: |
Stop-Process -Name mysqld
Start-Sleep -s 10
cd "${{github.workspace}}"
- name: Download sqlite3
run: |
choco install sqlite
- name: Download gawk
run: |
choco install gawk
- name: Checkout mysql2sqlite
uses: actions/checkout@v2
with:
repository: dumblob/mysql2sqlite
path: ${{env.CORE_FOLDER}}/mysql2sqlite
- name: Convert to sqlite
run: |
$finalFullDBFolder="${{github.workspace}}\sql"
gawk -f "${{env.CORE_FOLDER}}/mysql2sqlite/mysql2sqlite" "${finalFullDBFolder}\${{env.WORLD_DB_NAME}}.sql" | sqlite3 "${{env.FINAL_SQL_FOLDER}}\${{env.WORLD_DB_NAME}}.sqlite"
gawk -f "${{env.CORE_FOLDER}}/mysql2sqlite/mysql2sqlite" "${finalFullDBFolder}\${{env.CHAR_DB_NAME}}.sql" | sqlite3 "${{env.FINAL_SQL_FOLDER}}\${{env.CHAR_DB_NAME}}.sqlite"
gawk -f "${{env.CORE_FOLDER}}/mysql2sqlite/mysql2sqlite" "${finalFullDBFolder}\${{env.REALM_DB_NAME}}.sql" | sqlite3 "${{env.FINAL_SQL_FOLDER}}\${{env.REALM_DB_NAME}}.sqlite"
gawk -f "${{env.CORE_FOLDER}}/mysql2sqlite/mysql2sqlite" "${finalFullDBFolder}\${{env.LOGS_DB_NAME}}.sql" | sqlite3 "${{env.FINAL_SQL_FOLDER}}\${{env.LOGS_DB_NAME}}.sqlite"
- name: Preparing Assets
run: |
md -Force "${{github.workspace}}\releases"
7z a -tzip "${{github.workspace}}\releases\${{env.EXPANSION_NAME}}-db-mysql-server.zip" "${{env.WORK_FOLDER}}"
7z a -tzip "${{github.workspace}}\releases\${{env.EXPANSION_NAME}}-world-db.zip" "${{env.FINAL_SQL_FOLDER}}\${{env.WORLD_DB_NAME}}.sql"
7z a -tzip "${{github.workspace}}\releases\${{env.EXPANSION_NAME}}-all-db.zip" "${{env.FINAL_SQL_FOLDER}}\*.sql"
7z a -tzip "${{github.workspace}}\releases\${{env.EXPANSION_NAME}}-sqlite-db.zip" "${{env.FINAL_SQL_FOLDER}}\*.sqlite"
- name: Get Current Date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Upload Snapshot
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.PUSH_RELEASE_TOKEN }}"
automatic_release_tag: "latest"
prerelease: false
title: "Development Build(${{ steps.date.outputs.date }})"
files: releases
notify-success:
name: Send Notification to Discord on Success
runs-on: ubuntu-20.04
permissions:
contents: none
needs:
- build
steps:
- name: Set Environmental Variables
run: |
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "GIT_SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
projectNames="${GITHUB_REPOSITORY#*/}"
expansion="${projectNames%-*}"
echo "EXPANSION_NAME=${expansion}" >> $GITHUB_ENV
- name: Notify
uses: rjstone/discord-webhook-notify@v1.0.4
with:
severity: info
description: |
**New ${{env.EXPANSION_NAME}}-db Prebuild Released!**
details: |
- **Branch:** `${{env.GIT_BRANCH}}`
- **Commit SHA:** [${{github.repository}}/${{env.GIT_SHORT_SHA}}](${{github.server_url}}/${{ github.repository }}/commit/${{github.sha}})
- **Exported SQL:** [Download SQL File](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.EXPANSION_NAME}}-all-db.zip)
- **Exported World SQL:** [Download SQL File](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.EXPANSION_NAME}}-world-db.zip)
- **[Preconfigured MySQL Server (Windows x64 Release)](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.EXPANSION_NAME}}-db-mysql-server.zip)**
You may apply the exported and world SQL files directly to their respective databases. The `root` MySQL user password is `cmangos` - **do not forget** to change that! If you find any bugs or issues please report them [here](https://github.com/cmangos/issues/issues/new/choose).
footer: Created by the CMaNGOS Team!
webhookUrl: ${{ secrets.DISCORD_WEBHOOK_RELEASE }}
notify-failure:
name: Send Notification to Discord on Failure
runs-on: ubuntu-20.04
permissions:
contents: none
if: failure()
steps:
- name: Set Environmental Variables
run: |
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "GIT_SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
projectNames="${GITHUB_REPOSITORY#*/}"
expansion="${projectNames%-*}"
echo "EXPANSION_NAME=${expansion}" >> $GITHUB_ENV
- name: Notify
uses: rjstone/discord-webhook-notify@v1.0.4
with:
severity: error
description: |
**${{env.EXPANSION_NAME}}-db Prebuild Failed**
details: |
- **Branch:** ${{env.GIT_BRANCH}}
- **Pusher:** ${{github.event.pusher.name}}
- **Author:** ${{github.event.head_commit.author.name}}
- **Commit SHA:** [${{github.repository}}/${{env.GIT_SHORT_SHA}}](${{github.server_url}}/${{ github.repository }}/commit/${{github.sha}})
- **Build Log:** [actions/runs/${{github.run_id}}](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}})
footer: CMaNGOS Developers Notified!
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}