Skip to content

Commit

Permalink
Merge pull request #6 from hipejoe/Update20241223
Browse files Browse the repository at this point in the history
Update20241223
  • Loading branch information
hipejoe authored Dec 24, 2024
2 parents a0f18f5 + eafccd2 commit 9cf086c
Show file tree
Hide file tree
Showing 45 changed files with 454 additions and 184 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Codestyle
on:
pull_request:
types:
- opened
- reopened
- synchronize
paths:
- src/**
- "!README.md"
Expand All @@ -18,7 +22,7 @@ jobs:
with:
python-version: '3.10'
- name: AzerothCore codestyle
run: python ./apps/codestyle/codestyle.py
run: python ./apps/codestyle/codestyle-cpp.py
- name: C++ Advanced
run: |
sudo apt update -y
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/core-build-pch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
branches:
- 'master'
pull_request:
types: ['opened', 'synchronize', 'reopened']
types:
- opened
- reopened
- synchronize

concurrency:
group: ${{ github.head_ref }} || concat(${{ github.ref }}, ${{ github.workflow }})
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/core_modules_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ on:
- 'master'
pull_request:
types:
- labeled
- opened
- reopened
- synchronize
paths:
- 'src/*'
- 'src/common/**/*'
- 'src/genrev/**/*'
- 'src/server/*'
- 'src/server/apps/**/*'
- 'src/server/database/**/*'
- 'src/server/game/**/*'
- 'src/server/shared/**/*'
- 'src/tools/**/*'

concurrency:
group: ${{ github.head_ref }} || concat(${{ github.ref }}, ${{ github.workflow }})
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ on:
pull_request:
types:
- labeled
- opened
- synchronize
- reopened

concurrency:
group: ${{ github.head_ref }} || concat(${{ github.ref }}, ${{ github.workflow }})
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
triage:
runs-on: ubuntu-24.04
permissions: write-all
if: github.repository == 'azerothcore/azerothcore-wotlk'
if: github.repository == 'azerothcore/azerothcore-wotlk' && !github.event.pull_request.draft
steps:
- uses: actions/checkout@v4
with:
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/sql-codestyle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Codestyle
on:
pull_request:
types:
- opened
- reopened
- synchronize
paths:
- data/**
- "!README.md"
Expand All @@ -10,8 +14,12 @@ jobs:
triage:
runs-on: ubuntu-latest
name: SQL
if: github.repository == 'azerothcore/azerothcore-wotlk'
if: github.repository == 'azerothcore/azerothcore-wotlk' && !github.event.pull_request.draft
steps:
- uses: actions/checkout@v4
- name: Check pending SQL
run: source ./apps/ci/ci-pending.sh
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: AzerothCore codestyle
run: python ./apps/codestyle/codestyle-sql.py
2 changes: 0 additions & 2 deletions .github/workflows/tools_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ on:
pull_request:
types:
- labeled
- opened
- reopened
- synchronize

concurrency:
Expand Down
36 changes: 0 additions & 36 deletions apps/ci/ci-pending.sh

This file was deleted.

14 changes: 14 additions & 0 deletions apps/codestyle/codestyle.py → apps/codestyle/codestyle-cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def misc_codestyle_check(file: io, file_path: str) -> None:

# used to check for "if/else (...) {" "} else" ignores "if/else (...) {...}" "#define ... if/else (...) {"
ifelse_curlyregex = r"^[^#define].*\s+(if|else)(\s*\(.*\))?\s*{[^}]*$|}\s*else(\s*{[^}]*$)"
# used to catch double semicolons ";;" ignores "(;;)"
double_semiregex = r"[^(];;[^)]"
# used to catch tabs
tab_regex = r"\t"

# Parse all the file
for line_number, line in enumerate(file, start = 1):
if 'const auto&' in line:
Expand All @@ -240,6 +245,15 @@ def misc_codestyle_check(file: io, file_path: str) -> None:
print(
f"Curly brackets are not allowed to be leading or trailing if/else statements. Place it on a new line: {file_path} at line {line_number}")
check_failed = True
if re.match(double_semiregex, line):
print(
f"Double semicolon (;;) found in {file_path} at line {line_number}")
check_failed = True
if re.match(tab_regex, line):
print(
f"Tab found! Replace it to 4 spaces: {file_path} at line {line_number}")
check_failed = True

# Handle the script error and update the result output
if check_failed:
error_handler = True
Expand Down
141 changes: 141 additions & 0 deletions apps/codestyle/codestyle-sql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import io
import os
import sys
import re
import glob

# Get the pending directory of the project
base_dir = os.getcwd()
pattern = os.path.join(base_dir, 'data/sql/updates/pending_db_*')
src_directory = glob.glob(pattern)

# Global variables
error_handler = False
results = {
"Multiple blank lines check": "Passed",
"Trailing whitespace check": "Passed",
"SQL codestyle check": "Passed",
}

# Collect all files in all directories
def collect_files_from_directories(directories: list) -> list:
all_files = []
for directory in directories:
for root, _, files in os.walk(directory):
for file in files:
if not file.endswith('.sh'): # Skip .sh files
all_files.append(os.path.join(root, file))
return all_files

# Main function to parse all the files of the project
def parsing_file(files: list) -> None:
print("Starting AzerothCore SQL Codestyle check...")
print(" ")
print("Please read the SQL Standards for AzerothCore:")
print("https://www.azerothcore.org/wiki/sql-standards")
print(" ")

# Iterate over all files
for file_path in files:
try:
with open(file_path, 'r', encoding='utf-8') as file:
multiple_blank_lines_check(file, file_path)
trailing_whitespace_check(file, file_path)
sql_check(file, file_path)
except UnicodeDecodeError:
print(f"\nCould not decode file {file_path}")
sys.exit(1)

# Output the results
print("")
for check, result in results.items():
print(f"{check} : {result}")
if error_handler:
print("\nPlease fix the codestyle issues above.")
sys.exit(1)
else:
print(f"\nEverything looks good")

# Codestyle patterns checking for multiple blank lines
def multiple_blank_lines_check(file: io, file_path: str) -> None:
global error_handler, results
file.seek(0) # Reset file pointer to the beginning
check_failed = False
consecutive_blank_lines = 0
# Parse all the file
for line_number, line in enumerate(file, start = 1):
if line.strip() == '':
consecutive_blank_lines += 1
if consecutive_blank_lines > 1:
print(f"Multiple blank lines found in {file_path} at line {line_number - 1}")
check_failed = True
else:
consecutive_blank_lines = 0
# Additional check for the end of the file
if consecutive_blank_lines >= 1:
print(f"Multiple blank lines found at the end of: {file_path}")
check_failed = True
# Handle the script error and update the result output
if check_failed:
error_handler = True
results["Multiple blank lines check"] = "Failed"

# Codestyle patterns checking for whitespace at the end of the lines
def trailing_whitespace_check(file: io, file_path: str) -> None:
global error_handler, results
file.seek(0) # Reset file pointer to the beginning
check_failed = False
# Parse all the file
for line_number, line in enumerate(file, start = 1):
if line.endswith(' \n'):
print(f"Trailing whitespace found: {file_path} at line {line_number}")
check_failed = True
if check_failed:
error_handler = True
results["Trailing whitespace check"] = "Failed"

# Codestyle patterns checking for various codestyle issues
def sql_check(file: io, file_path: str) -> None:
global error_handler, results
file.seek(0) # Reset file pointer to the beginning
check_failed = False

# Parse all the file
for line_number, line in enumerate(file, start = 1):
if [match for match in ['broadcast_text'] if match in line]:
print(
f"DON'T EDIT broadcast_text TABLE UNLESS YOU KNOW WHAT YOU ARE DOING!\nThis error can safely be ignored if the changes are approved to be sniffed: {file_path} at line {line_number}")
check_failed = True
if [match for match in [';;'] if match in line]:
print(
f"Double semicolon (;;) found in {file_path} at line {line_number}")
check_failed = True
if re.match(r"\t", line):
print(
f"Tab found! Replace it to 4 spaces: {file_path} at line {line_number}")
check_failed = True

# Ignore comments (remove content after --)
line_without_comment = re.sub(r'--.*', '', line).strip()
# Check if the last non-empty line ends with a semicolon
if not line_without_comment.endswith(';'):
print(
f"The last non-empty line does not end with a semicolon: {file_path}")
check_failed = True

last_line = line[-1].strip()
if last_line:
print(
f"The last line is not a newline. Please add a newline: {file_path}")
check_failed = True

# Handle the script error and update the result output
if check_failed:
error_handler = True
results["SQL codestyle check"] = "Failed"

# Collect all files from matching directories
all_files = collect_files_from_directories(src_directory)

# Main function
parsing_file(all_files)
5 changes: 5 additions & 0 deletions data/sql/updates/db_world/2024_12_22_00.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- DB update 2024_12_20_02 -> 2024_12_22_00

-- Remove Black Pearl Item from all creature loot tables.

DELETE FROM `creature_loot_template` WHERE (`Entry` IN (6347, 6348, 6349, 6350, 6351, 6352, 6369, 6370, 6371, 6372, 6649, 7246, 7864, 7885, 7886, 7977, 8136, 8408, 8716, 8761, 8905, 11741, 11783, 11793, 12207, 12397, 13599, 13896, 14123, 14446, 14638, 14639, 15206, 504, 595, 747, 750, 751, 752, 922, 950, 979, 1729, 1791, 1809, 1907, 2043, 2255, 2408, 2505, 2544, 2574, 2583, 2659, 2680, 2701, 2715, 2718, 2791, 2793, 2817, 2926, 3715, 4096, 4374, 4467, 4648, 4663, 4687, 5232, 5238, 5268, 5269, 5286, 5307, 5308, 5328, 5331, 5332, 5333, 5334, 5335, 5336, 5337, 5343, 5423, 5431, 5432, 5461, 5462, 5466, 5615, 5616, 5618, 5623, 5843, 5856, 5974, 6116, 6117, 6135, 6136, 6137, 6138, 6140, 6143, 6144, 6147, 6190, 6193, 6194, 6195, 6196, 6199, 6202)) AND (`Item` IN (7971));
4 changes: 4 additions & 0 deletions data/sql/updates/db_world/2024_12_22_01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- DB update 2024_12_22_00 -> 2024_12_22_01
--
DELETE FROM `command` where `name` = 'reload game_event_npc_vendor';
INSERT INTO `command` (`name`, `security`, `help`) VALUES ('reload game_event_npc_vendor', 3, 'Syntax: .reload game_event_npc_vendor\r Reload game_event_npc_vendor table.');
5 changes: 5 additions & 0 deletions data/sql/updates/db_world/2024_12_22_02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- DB update 2024_12_22_01 -> 2024_12_22_02
--
DELETE FROM `quest_request_items_locale` WHERE `CompletionText` = '';
DELETE FROM `quest_request_items_locale` WHERE `CompletionText` = 'NULL';
DELETE FROM `quest_request_items_locale` WHERE `CompletionText` IS NULL;
18 changes: 9 additions & 9 deletions src/cmake/macros/FindMySQL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ if(WIN32)

set(_MYSQL_ROOT_PATHS
${_MYSQL_ROOT_PATHS}
${_MYSQL_ROOT_PATHS_VERSION_SUBDIRECTORIES}
${_MYSQL_ROOT_PATHS_VERSION_SUBDIRECTORIES}
"${PROGRAM_FILES_64}/MySQL"
"${PROGRAM_FILES_32}/MySQL"
"$ENV{SystemDrive}/MySQL"
Expand All @@ -180,7 +180,7 @@ find_path(MYSQL_INCLUDE_DIR
/usr/local/include
/usr/local/include/mysql
/usr/local/mysql/include
${_MYSQL_ROOT_PATHS}
${_MYSQL_ROOT_PATHS}
PATH_SUFFIXES
include
include/mysql
Expand Down Expand Up @@ -270,20 +270,20 @@ set(MYSQL_REQUIRED_VARS "")
foreach(_comp IN LISTS MySQL_FIND_COMPONENTS)
if(_comp STREQUAL "lib")
set(MySQL_${_comp}_WANTED TRUE)
if(MySQL_FIND_REQUIRED_${_comp})
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_LIBRARY")
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_INCLUDE_DIR")
endif()
if(MySQL_FIND_REQUIRED_${_comp})
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_LIBRARY")
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_INCLUDE_DIR")
endif()
if(EXISTS "${MYSQL_LIBRARY}" AND EXISTS "${MYSQL_INCLUDE_DIR}")
set(MySQL_${_comp}_FOUND TRUE)
else()
set(MySQL_${_comp}_FOUND FALSE)
endif()
elseif(_comp STREQUAL "binary")
set(MySQL_${_comp}_WANTED TRUE)
if(MySQL_FIND_REQUIRED_${_comp})
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_EXECUTABLE")
endif()
if(MySQL_FIND_REQUIRED_${_comp})
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_EXECUTABLE")
endif()
if(EXISTS "${MYSQL_EXECUTABLE}" )
set(MySQL_${_comp}_FOUND TRUE)
else()
Expand Down
Loading

0 comments on commit 9cf086c

Please sign in to comment.