From 405daaba664c412a23bc044c0b7b3be59057ffb4 Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Sat, 14 Dec 2024 20:57:58 +0100 Subject: [PATCH 01/11] Fix `rename_to_minecraft_name` check and add check for empty keys (in social category) --- .github/actions/validate-manifest/validate.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index a44747586..8a828c82b 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -90,6 +90,8 @@ def main(): for key in USERNAME_SOCIAL_KEYS: if key in social and (social[key].startswith('http') or 'www' in social[key]): error += f'- Please use a **username**, not a link (`social.{key}`)\n' + if key in social and social[key].equals(''): + error += f'- Please remove the empty key **{key}** or fill in information.\n' # Check facebook, because it works :) if 'facebook' in social: @@ -105,7 +107,7 @@ def main(): int(data['discord']['server_id']) except ValueError: error += f'- Please use a **numeric** value for your server id (`discord.server_id`)\n' - if 'rename_to_minecraft_name' in 'discord' in data == True: + if 'rename_to_minecraft_name' in data['discord'] and data['discord']['rename_to_minecraft_name'] == True: comment += f'- `discord.rename_to_minecraft_name` is reserved for LabyMod Partners. Change it to `false`. If you are a partner, please ignore this message.\n' if 'user_stats' in data and ('{userName}' not in data['user_stats'] and '{uuid}' not in data['user_stats']): From e50553a2612d8aa1d270e3a4e8e22867e60b747f Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Mon, 16 Dec 2024 07:44:44 +0100 Subject: [PATCH 02/11] Whoops, Java doesn't belong here --- .github/actions/validate-manifest/validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 8a828c82b..74223e32f 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -90,7 +90,7 @@ def main(): for key in USERNAME_SOCIAL_KEYS: if key in social and (social[key].startswith('http') or 'www' in social[key]): error += f'- Please use a **username**, not a link (`social.{key}`)\n' - if key in social and social[key].equals(''): + if key in social and social[key] == '': error += f'- Please remove the empty key **{key}** or fill in information.\n' # Check facebook, because it works :) From 6d8086289f9828c3607247dd9517721d8a99dd74 Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Tue, 17 Dec 2024 06:52:33 +0100 Subject: [PATCH 03/11] Fix maintenance check --- .github/actions/validate-manifest/validate.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 74223e32f..1a4f185be 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -184,6 +184,7 @@ def post_comment(comment: str, request_type: str = 'reviews'): def check_server_online_state(ip: str, wildcards: list): + offline_text = 'In general, we only accept pull requests from servers, **that are online**.\nPlease change this, otherwise we cannot review your server correctly and have to deny the pull request.\n\n' print(f'Check server status for {ip}') url = f'https://api.mcsrvstat.us/2/{ip}' @@ -212,10 +213,7 @@ def check_server_online_state(ip: str, wildcards: list): server_ip = response['ip_address'] print(f"Checked server status successfully: {response['online']}") - offline_text = "In general, we only accept pull requests from servers, **that are online**. " \ - "Please change this, otherwise we cannot review your server correctly and have to deny the pull request.\n\n" \ - "If your server is currently online, then our api returned a wrong status, we will have a look at it :)\n\n" \ - f"Reference: [API URL ({url})]({url})" + offline_text += f"Reference: [API URL ({url})]({url})" if not response['online']: post_comment(f'*Just as an information*:\nYour server {ip} **could be offline**.\n {offline_text}', 'comments') From a61e026ddfe56c3915f7b09efff1b3008ab23ca4 Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Sat, 21 Dec 2024 22:44:59 +0100 Subject: [PATCH 04/11] Add empty key check for every key (in some way) --- .github/actions/validate-manifest/validate.py | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 1a4f185be..47f7ce211 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -90,7 +90,7 @@ def main(): for key in USERNAME_SOCIAL_KEYS: if key in social and (social[key].startswith('http') or 'www' in social[key]): error += f'- Please use a **username**, not a link (`social.{key}`)\n' - if key in social and social[key] == '': + if key in social and social[key] in ('', '-'): error += f'- Please remove the empty key **{key}** or fill in information.\n' # Check facebook, because it works :) @@ -110,8 +110,6 @@ def main(): if 'rename_to_minecraft_name' in data['discord'] and data['discord']['rename_to_minecraft_name'] == True: comment += f'- `discord.rename_to_minecraft_name` is reserved for LabyMod Partners. Change it to `false`. If you are a partner, please ignore this message.\n' - if 'user_stats' in data and ('{userName}' not in data['user_stats'] and '{uuid}' not in data['user_stats']): - error += '- Please use {userName} or {uuid} in your stats url (`user_stats`)\n' if 'location' in data and 'country_code' in data['location']: country_code = data['location']['country_code'] @@ -131,10 +129,34 @@ def main(): stats_url = data['user_stats'] if not stats_url.startswith('https://'): error += f'- Invalid url. URL has to start with **https://** (`user_stats`)\n' + if '{userName}' not in data['user_stats'] and '{uuid}' not in data['user_stats']: + error += '- Please use {userName} or {uuid} in your stats url (`user_stats`)\n' if '://laby.net/' in stats_url: error += f'- Please use **your own page**, not LABY.net (`user_stats`)\n' + if 'message_formats' in data['chat']: + message_format = data['chat']['message_formats'] + if message_format == '^§[a-f0-9](?\\d+)( \\||§8 \\|) §[a-f0-9](?[a-zA-Z0-9_]{2,16})§r§7: §f(?.*)$': + comment += f'- It seems you\'re using the **template regex** for chat message! Please make sure it is the right regex for **your server**!' + if message_format in ('', '-'): + error += f'- Please remove the empty key **message_formats** or fill in information.\n' + + + if 'gamemodes' in data: + gamemodes = data['gamemodes'] + for key, gamemode in gamemodes.items(): + if 'name' not in gamemode or 'color' not in gamemode or gamemode['name'] in ('', '-') or '#' not in gamemode['color']: + error += f"- Please add a name or a color to the gamemode {key}\n" + if 'url' in gamemode and gamemode['url'] in ('', '-'): + error += f"- Please remove the empty url key in gamemode **{key}** or fill in information.\n" + if 'versions' in gamemode and gamemode['versions'] in ('', '-'): + error += f"- Please remove the empty version key in gamemode **{key}** or fill in information.\n" + if 'command' in gamemode and gamemode['command'] in ('', '-'): + error += f"- Please remove the empty command key in gamemode **{key}** or fill in information.\n" + + + if create_comment: post_comment(error) post_comment(comment) From 0f81fdd6c0eb0ee1ee5ada5c2ad299b64bae6dfe Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Sun, 22 Dec 2024 11:55:38 +0100 Subject: [PATCH 05/11] Fix some outputs and hopefully make action fail again when JSON is invalid --- .github/actions/validate-manifest/validate.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 47f7ce211..2d6350430 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -15,7 +15,7 @@ def main(): wildcard_stop = False create_comment = comment_needed() - if create_comment: + if not create_comment: print('No manifest file changed, comment will be skipped.') manifest_files = get_changed_manifest_files() @@ -158,8 +158,12 @@ def main(): if create_comment: - post_comment(error) - post_comment(comment) + post_comment(error, True) + post_comment(comment, False) + + if error != '': + # Make job fail + sys_exit('Invalid data in manifest.json. See comments above or review in PR for more information.') for error in error.split('\n'): # Print error comments, so that the user can relate the issues even if there is no comment @@ -168,10 +172,6 @@ def main(): for comment in comment.split('\n'): print(comment) - if error != '': - # Make job fail - sys_exit('Invalid data in manifest.json. See comments above or review in PR for more information.') - def get_changed_manifest_files(): print('Getting changed files from json') @@ -186,9 +186,9 @@ def get_changed_manifest_files(): return changed_files -def post_comment(comment: str, request_type: str = 'reviews'): - if comment == '': - print('No issues found.') +def post_comment(comment: str, error: bool, request_type: str = 'reviews'): + if not error: + print('No error found.') return if request_type == 'reviews': @@ -238,7 +238,7 @@ def check_server_online_state(ip: str, wildcards: list): offline_text += f"Reference: [API URL ({url})]({url})" if not response['online']: - post_comment(f'*Just as an information*:\nYour server {ip} **could be offline**.\n {offline_text}', 'comments') + post_comment(f'*Just as an information*:\nYour server {ip} **could be offline**.\n {offline_text}', False, 'comments') wildcard_string = '*Just as an information*:\n' wildcard_comment = False @@ -262,7 +262,7 @@ def check_server_online_state(ip: str, wildcards: list): wildcard_string += f'\nPlease make sure it is an [actual wildcard](https://en.wikipedia.org/wiki/Wildcard_DNS_record).\n' if wildcard_comment: - post_comment(wildcard_string, 'comments') + post_comment(wildcard_string, False, 'comments') if 'motd' in response: maintenance_tagged = False @@ -273,7 +273,7 @@ def check_server_online_state(ip: str, wildcards: list): else: print(f'No maintenance found in MOTD') if maintenance_tagged: - post_comment(f'The server {ip} **is in maintenance**.\n {offline_text}') + post_comment(f'The server {ip} **is in maintenance**.\n {offline_text}', True) def comment_needed(): From a6d0277e63194f9b79f08e5f28a90957c34e5300 Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Sun, 22 Dec 2024 12:25:09 +0100 Subject: [PATCH 06/11] Make comment_needed also True if PR was only updated with a new commit aswell --- .github/actions/validate-manifest/validate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 2d6350430..bafe4fd96 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -277,7 +277,8 @@ def check_server_online_state(ip: str, wildcards: list): def comment_needed(): - if os.getenv('PR_ACTION').endswith('opened'): + pr_action = os.getenv('PR_ACTION') + if pr_action in ['opened', 'reopened', 'synchronize']: print('PR opened - Write comment.') return True From 06a595ded1a417d18fcebe6fd0db3b881f1ad2a7 Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Sun, 22 Dec 2024 15:32:35 +0100 Subject: [PATCH 07/11] Logic error --- .github/actions/validate-manifest/validate.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index bafe4fd96..b79a83f54 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -108,7 +108,8 @@ def main(): except ValueError: error += f'- Please use a **numeric** value for your server id (`discord.server_id`)\n' if 'rename_to_minecraft_name' in data['discord'] and data['discord']['rename_to_minecraft_name'] == True: - comment += f'- `discord.rename_to_minecraft_name` is reserved for LabyMod Partners. Change it to `false`. If you are a partner, please ignore this message.\n' + comment += f'- `discord.rename_to_minecraft_name` is reserved for LabyMod Partners. Change it to `false`.' \ + 'If you are a partner, please ignore this message.\n' if 'location' in data and 'country_code' in data['location']: @@ -158,8 +159,10 @@ def main(): if create_comment: - post_comment(error, True) - post_comment(comment, False) + if error != '': + post_comment(error, True) + if comment != '': + post_comment(comment, False) if error != '': # Make job fail From 477f4c2b88362c278b936fc77fe6e11ab54bd281 Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Sun, 22 Dec 2024 15:42:10 +0100 Subject: [PATCH 08/11] Enhance empty key check --- .github/actions/validate-manifest/validate.py | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index b79a83f54..5260ac999 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -45,9 +45,14 @@ def main(): error += '- One of the **required values** is missing\n' continue + if data['direct_ip'] in ['', '-']: + error += f'- Direct IP is required\n' + if data['nice_name'] in ['', '-']: + error += f'- Nice name is required and cannot be empty!\n' + server_directory = manifest_file.replace('minecraft_servers/', '').replace('/manifest.json', '') if server_directory != data['server_name']: - error += '**Servername has to be directory name!**\n' + error += '**Servername has to be directory name!** (all lowercase)\n' # Validate wildcards if 'server_wildcards' in data: @@ -112,13 +117,17 @@ def main(): 'If you are a partner, please ignore this message.\n' - if 'location' in data and 'country_code' in data['location']: - country_code = data['location']['country_code'] - if len(country_code) > 2 or len(country_code) <= 1: - error += '- Use valid format (ISO 3166-1 alpha-2) for country code. (`location.country_code`)\n' + if 'location' in data: + if 'city' in data['location'] and data['location']['city'] in ['', '-']: + error += f'- Please remove the empty key **city** or fill in information.\n' + + if 'country_code' in data['location']: + country_code = data['location']['country_code'] + if len(country_code) > 2 or len(country_code) <= 1: + error += '- Use valid format (ISO 3166-1 alpha-2) for country code. (`location.country_code`)\n' - if not country_code.isupper(): - error += '- Use upper-case for country code. (`location.country_code`)\n' + if not country_code.isupper(): + error += '- Use upper-case for country code. (`location.country_code`)\n' # check hex codes if 'brand' in data: From 26f6dffc14e056b6ec6ee3b7dff53a9cdce3f68a Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Wed, 25 Dec 2024 15:46:46 +0100 Subject: [PATCH 09/11] Add more debugging for wildcard check --- .github/actions/validate-manifest/validate.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 5260ac999..0f3ec0491 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -60,6 +60,7 @@ def main(): if not wildcard.startswith('%.'): wildcard_stop = True error += '- Invalid wildcard entry. Each entry must start with **%.**. Further information here: https://en.wikipedia.org/wiki/Wildcard_DNS_record (`server_wildcards`)\n' + print(f'Found valid wildcard entry: {wildcard}') check_server_online_state( data['direct_ip'], @@ -255,6 +256,7 @@ def check_server_online_state(ip: str, wildcards: list): wildcard_string = '*Just as an information*:\n' wildcard_comment = False for wildcard in wildcards: + print(f'Checking wildcard "{wildcard}"') wildcard_ip = str.replace(wildcard, '%', 'testingstringwildcard') request = requests.get(f'https://api.mcsrvstat.us/2/{wildcard_ip}') @@ -265,9 +267,11 @@ def check_server_online_state(ip: str, wildcards: list): continue if not response['online']: + print(f'Wildcard "{wildcard}" is offline') wildcard_string += f'- Wildcard {wildcard} seems to be invalid. Server is offline with testing wildcard.\n' wildcard_comment = True else: + print(f'Wildcard "{wildcard}" is online') if response['ip'] != server_ip: wildcard_string += f'- Wildcard do not resolve the same ip address: *{wildcard}* => *{response["ip"]}*\n' wildcard_comment = True From ae2d209eb838c1cc93c8a1e4595de27b8800cd0a Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Thu, 26 Dec 2024 19:26:27 +0100 Subject: [PATCH 10/11] Idk why but it seems to have failed before hopefully works now tho --- .github/actions/validate-manifest/validate.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 0f3ec0491..60d8b56d3 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -2,6 +2,7 @@ import os import requests from sys import exit as sys_exit +from re import fullmatch as re_match REQUIRED_KEYS = ['server_name', 'nice_name', 'direct_ip'] USERNAME_SOCIAL_KEYS = ['twitter', 'tiktok', 'facebook', 'instagram', 'teamspeak'] @@ -146,9 +147,10 @@ def main(): if '://laby.net/' in stats_url: error += f'- Please use **your own page**, not LABY.net (`user_stats`)\n' - if 'message_formats' in data['chat']: + if 'chat' in data and 'message_formats' in data['chat']: message_format = data['chat']['message_formats'] - if message_format == '^§[a-f0-9](?\\d+)( \\||§8 \\|) §[a-f0-9](?[a-zA-Z0-9_]{2,16})§r§7: §f(?.*)$': + template_regex = r'^§[a-f0-9](?\\d+)( \\||§8 \\|) §[a-f0-9](?[a-zA-Z0-9_]{2,16})§r§7: §f(?.*)$' + if re_match(template_regex, message_format): comment += f'- It seems you\'re using the **template regex** for chat message! Please make sure it is the right regex for **your server**!' if message_format in ('', '-'): error += f'- Please remove the empty key **message_formats** or fill in information.\n' From 2b1b09fa185b0effa25519909cfae2786071b554 Mon Sep 17 00:00:00 2001 From: DoJapHD Date: Thu, 26 Dec 2024 19:32:00 +0100 Subject: [PATCH 11/11] Idk why but it seems to have failed before hopefully works now tho --- .github/actions/validate-manifest/validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/validate-manifest/validate.py b/.github/actions/validate-manifest/validate.py index 60d8b56d3..af1bd0b31 100644 --- a/.github/actions/validate-manifest/validate.py +++ b/.github/actions/validate-manifest/validate.py @@ -202,7 +202,7 @@ def get_changed_manifest_files(): def post_comment(comment: str, error: bool, request_type: str = 'reviews'): - if not error: + if not error and request_type != 'comment': print('No error found.') return