forked from cmangos/classic-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script now support - Multiple user menu - User settings directly modifiable in the script - Live check of all settings - Display status of current db - Filling clean db from scratch with normal user (mangos user if DB already exist) - Setting mangos user, creating and filling all data from scratch with root access - Support of user ip limitation for mangos user - Help to identify when db need to be updated - Update from core folder to all DB - Some advanced feature like delete everything if need - Edit RealmList directly from this script no need for mysql client - help switch and some usefull switchs Fix appveyor script Rework CI script and use Github Action - fix install script - use github action instead of appveyor - build all databases - build mysql server for windows database using official download - provide ready to use mysql server for windows users - provide ready to use dumped sql for all databases Support older bash version for mac os also switch to another method to convert string case Another try to fix mac os build Implement backups/restore feature Some more improvement - make main menu more clear - add -Backup argument wich support full option - add backup by default before droping world, char, and realm db - add more warnings - fix a bug with last quote of the title not being removed More improvements - CI now can break faster if build fail for any reason and notify discord - CI use now the script itself to generate backup file - Backup/restore now work for any db name - Added support of downloading latest working backup directly from the script - Removed unecessary info from main menu - Implemented restore command line - Implemented db and users creation from command line - Script is now able to autodetect content version, title and last update revision ... stuff like code clean, warnings and comments.
- Loading branch information
Showing
4 changed files
with
3,110 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,302 @@ | ||
name: Build check | ||
|
||
on: | ||
push: | ||
branches: | ||
- "*" | ||
|
||
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-check: | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Setup environment variables | ||
run: | | ||
projectNames="${GITHUB_REPOSITORY#*/}" | ||
expension="${projectNames%-*}" | ||
echo "EXPENSION_NAME=${expension}" >> $GITHUB_ENV | ||
echo "CORE_REPO="cmangos/mangos-${expension} >> $GITHUB_ENV | ||
echo "CORE_FOLDER="${{github.workspace}}/mangos-${expension} >> $GITHUB_ENV | ||
echo "DB_FOLDER="${{github.workspace}}/${expension}-db >> $GITHUB_ENV | ||
- 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: Build ${{env.EXPENSION_NAME}}-db | ||
run: | | ||
sudo /etc/init.d/mysql start | ||
cd ${{env.DB_FOLDER}} | ||
./InstallFullDB.sh -InstallAll root root DeleteAll | ||
./InstallFullDB.sh -Backup full | ||
tar -czvf "${{github.workspace}}/${{env.EXPENSION_NAME}}-all-backups.tar.gz" -C backups --exclude=".gitignore" . | ||
sudo /etc/init.d/mysql stop | ||
- uses: dev-drprasad/[email protected] | ||
with: | ||
delete_release: true # default: false | ||
tag_name: latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PUSH_RELEASE_TOKEN }} | ||
|
||
- name: Get current date | ||
id: date | ||
run: echo "::set-output name=date::$(date +'%Y-%m-%d %H:%M')" | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
id: create_release | ||
with: | ||
name: Development Build(${{ steps.date.outputs.date }}) | ||
body: | | ||
# :rescue_worker_helmet: Assets description | ||
- :computer: ${{env.EXPENSION_NAME}}-db-mysql-server.zip | ||
***Ready to use ${{env.MYSQL_BIN_NAME}} for windows with db data already installed*** | ||
- :cd: ${{env.EXPENSION_NAME}}-all-backups.tar.gz | ||
***Backup of all of databases that you can put in backups folder*** | ||
- :cd: ${{env.EXPENSION_NAME}}-world-db.zip | ||
***Dump of world db only in sql form*** | ||
- :cd: ${{env.EXPENSION_NAME}}-all-db.zip | ||
***Dump of all databases in sql form*** | ||
token: ${{ secrets.PUSH_RELEASE_TOKEN }} | ||
files: "${{github.workspace}}/${{env.EXPENSION_NAME}}-all-backups.tar.gz" | ||
tag_name: latest | ||
prerelease: true | ||
target_commitish: ${{ github.event.before }} | ||
|
||
build: | ||
runs-on: windows-2019 | ||
needs: build-check | ||
|
||
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] | ||
$expension="${projectNames}".Split("-")[0] | ||
echo "LAST_BACKUP_ADR=https://github.com/cmangos/${expension}-db/releases/download/latest/${expension}-all-backups.tar.gz" >> $env:GITHUB_ENV | ||
echo "CORE_REPO=cmangos\mangos-${expension}" >> $env:GITHUB_ENV | ||
echo "CORE_FOLDER=${{github.workspace}}\mangos-${expension}" >> $env:GITHUB_ENV | ||
echo "DB_FOLDER=${{github.workspace}}\${expension}-db" >> $env:GITHUB_ENV | ||
echo "EXPENSION_NAME=${expension}" >> $env:GITHUB_ENV | ||
echo "PROJECT_NAME=cmangos-${expension}" >> $env:GITHUB_ENV | ||
echo "WORLD_DB_NAME=${expension}mangos" >> $env:GITHUB_ENV | ||
echo "CHAR_DB_NAME=${expension}characters" >> $env:GITHUB_ENV | ||
echo "REALM_DB_NAME=${expension}realmd" >> $env:GITHUB_ENV | ||
echo "LOGS_DB_NAME=${expension}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: 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: Download last backup file | ||
run: | | ||
cd "${{env.DB_FOLDER}}\backups" | ||
curl -L ${{env.LAST_BACKUP_ADR}} -o all-backups.tar.gz | ||
tar -xzvf all-backups.tar.gz | ||
- name: Build ${{env.EXPENSION_NAME}} | ||
run: | | ||
cd "${{env.DB_FOLDER}}" | ||
bash InstallFullDB.sh -CreateAllDBandUser root cmangos DeleteAll | ||
bash InstallFullDB.sh -Restore all-databases false | ||
- 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: Preparing assets | ||
run: | | ||
7z a -tzip "${{github.workspace}}\${{env.EXPENSION_NAME}}-db-mysql-server.zip" "${{env.WORK_FOLDER}}" | ||
7z a -tzip "${{github.workspace}}\${{env.EXPENSION_NAME}}-world-db.zip" "${{env.FINAL_SQL_FOLDER}}\${{env.WORLD_DB_NAME}}.sql" | ||
7z a -tzip "${{github.workspace}}\${{env.EXPENSION_NAME}}-all-db.zip" "${{env.FINAL_SQL_FOLDER}}\*.sql" | ||
- name: Upload binaries to release | ||
uses: svenstaro/[email protected] | ||
with: | ||
repo_token: ${{ secrets.PUSH_RELEASE_TOKEN }} | ||
file: "${{github.workspace}}\\*.zip" | ||
tag: latest | ||
overwrite: true | ||
file_glob: true | ||
|
||
notify: | ||
name: Discord Notification | ||
runs-on: ubuntu-20.04 | ||
needs: | ||
- build-check | ||
if: failure() | ||
|
||
steps: | ||
- name: Env | ||
run: | | ||
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | ||
echo "GIT_SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV | ||
- name: Notify | ||
uses: rjstone/[email protected] | ||
with: | ||
severity: error | ||
username: ${{ github.event.repository.name }} | ||
description: | | ||
**Linux buid failed** | ||
details: | | ||
- **Branch:** ${{env.GIT_BRANCH}} | ||
- **Pusher:** ${{github.event.pusher.name}} | ||
- **Author:** ${{github.event.head_commit.author.name}} | ||
- **Commit:** [${{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: Next time ${{github.event.pusher.name}}! | ||
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} | ||
avatarUrl: https://github.githubassets.com/images/modules/logos_page/Octocat.png |
Oops, something went wrong.