Skip to content

Build Release

Build Release #1053

Workflow file for this run

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/[email protected]
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/[email protected]
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 }}