Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/adj-tester.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: Run ADJ validation
run: |
python3 .github/workflows/scripts/adj-tester/main.py > /dev/null 2>&1
python3 .github/workflows/scripts/adj-tester/main.py

- name: Notify Slack on failure
if: failure()
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/scripts/adj-tester/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ADJ Validator

Version: 11.1.2
Version: 11.1.3

JavierRibaldelRio

Expand All @@ -13,6 +13,7 @@
(e.g. uniqueness constraints and IPv4 validation).
"""

import argparse
import sys
from pathlib import Path

Expand All @@ -23,7 +24,7 @@
is_valid_ipv4,
print_results,
logError,
info_message,
set_color_enabled,
validate_with_schema,
)

Expand Down Expand Up @@ -452,10 +453,10 @@ def check_packet_json(
has_period_type = "period_type" in pkt
has_period = "period" in pkt
has_socket = "socket" in pkt

# Count how many of the three fields are present
fields_present = sum([has_period_type, has_period, has_socket])

# If any field is present, all three must be present
if fields_present > 0 and fields_present < 3:
error_list.append(
Expand Down Expand Up @@ -598,6 +599,16 @@ def main():
non-zero status code if any validation step fails.
"""

parser = argparse.ArgumentParser(description="Validate ADJ JSON schemas")
parser.add_argument(
"--no-color",
action="store_true",
help="Disable ANSI color codes in output",
)
args = parser.parse_args()

set_color_enabled(not args.no_color)

# App header
print_header("JSON Validation Script")

Expand Down
32 changes: 31 additions & 1 deletion .github/workflows/scripts/adj-tester/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
from pathlib import Path
from jsonschema import Draft7Validator

# Global switch to control whether ANSI colors are used in output.
# This is controlled from CLI via the `--no-color` flag.
ENABLE_COLOR = True


def set_color_enabled(enabled: bool):
"""Enable or disable ANSI color output.

Args:
enabled: If False, all helper output functions will omit ANSI
escape sequences.
"""

global ENABLE_COLOR
ENABLE_COLOR = enabled


def print_header(header: str):
"""Print a simple boxed header to stdout.
Expand Down Expand Up @@ -39,10 +55,14 @@ def format_status(message: str, validated: bool = False):
red "Failed".
"""

if not ENABLE_COLOR:
result = "Passed" if validated else "Failed"
return f"{message} {result}"

# ANSI color codes used for terminal output
if not validated:
result = "\033[31mFailed\033[0m" # red
elif validated:
else:
result = "\033[32mPassed\033[0m" # green

return f"{message} {result}"
Expand All @@ -51,6 +71,9 @@ def format_status(message: str, validated: bool = False):
def info_message(message: str):
"""format to blue color and return the message string."""

if not ENABLE_COLOR:
return message

return f"\033[34m{message}\033[0m"


Expand All @@ -69,6 +92,10 @@ def log_message(message: str, status: int = 0):
(success).
"""

if not ENABLE_COLOR:
print(message)
return

colors = {-1: "\033[31m", 1: "\033[32m"}
color = colors.get(status, "")
reset = "\033[0m" if color else ""
Expand Down Expand Up @@ -143,6 +170,9 @@ def logError(label: str, path: str, message: str):
single formatted string instead of printing directly.
"""

if not ENABLE_COLOR:
return f"{label}: {path} → {message}"

return f"\033[31m{label}: {path} → {message}\033[0m"


Expand Down
Loading