diff --git a/entrypoint.py b/entrypoint.py index 7ef899e..980646c 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -1,15 +1,44 @@ import os import subprocess import sys +import logging +def print_header(title): + print("\n" + "=" * 50) + print(f"πŸš€ {title}") + print("=" * 50 + "\n") + +def print_section(title): + print(f"\nπŸ“‹ {title}:") + +def print_success(message): + print(f"βœ… {message}") + +def print_error(message): + print(f"❌ {message}") + +# λ‘œκΉ… μ„€μ • +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(levelname)s - %(message)s', + datefmt='%Y-%m-%d %H:%M:%S' +) +logger = logging.getLogger(__name__) def run_command(command): - print(f"Executing command: {command}") - result = subprocess.run(command, shell=True, text=True, capture_output=True) - if result.stdout: - print(f"Command output: {result.stdout.strip()}") - if result.stderr: - print(f"Command errors: {result.stderr.strip()}") + print(f"βš™οΈ Executing: {command}") + try: + result = subprocess.run(command, shell=True, text=True, capture_output=True, check=True) + if result.stdout: + logger.info(f"Command output:\n{result.stdout.strip()}") + if result.stderr: + logger.warning(f"Command stderr:\n{result.stderr.strip()}") + print_success("Command executed successfully") + return True + except subprocess.CalledProcessError as e: + print_error(f"Command failed: {e}") + logger.error(f"Error output:\n{e.stderr}") + sys.exit(1) def get_extension(format): @@ -29,9 +58,20 @@ def adjust_path(path): def compress(source, format, include_root): + print_header("Compression Process Started") + + if not os.path.exists(source): + print_error(f"Source path '{source}' does not exist") + sys.exit(1) + source = adjust_path(source) - cwd = os.getcwd() # Save current directory - print(f"Initial CWD: {cwd}") # Debug: Show initial working directory + print_section("Configuration") + print(f" β€’ Source: {source}") + print(f" β€’ Format: {format}") + print(f" β€’ Include Root: {include_root}") + + cwd = os.getcwd() + print(f" β€’ Initial Directory: {cwd}") dest = os.getenv("DEST", os.getenv("GITHUB_WORKSPACE", os.getcwd())) if dest and not os.path.exists(dest): @@ -74,6 +114,8 @@ def compress(source, format, include_root): sys.exit(f"Unsupported format: {format}") os.chdir(cwd) # Restore original working directory. print(f"Restored CWD: {os.getcwd()}") # Debug: Show restored working directory + print_success(f"Compression completed: {full_dest}") + print("\n" + "=" * 50) print( f"file_path={full_dest}", file=open(os.getenv("GITHUB_OUTPUT", "/dev/stdout"), "a"), @@ -81,7 +123,18 @@ def compress(source, format, include_root): def decompress(source, format): + print_header("Decompression Process Started") + + if not os.path.exists(source): + print_error(f"Source file '{source}' does not exist") + sys.exit(1) + source = adjust_path(source) + print_section("Configuration") + print(f" β€’ Source: {source}") + print(f" β€’ Format: {format}") + print(f" β€’ Destination: {os.getenv('DEST', 'current directory')}") + dest = os.getenv("DEST", os.getenv("GITHUB_WORKSPACE", os.getcwd())) if dest and not os.path.exists(dest): os.makedirs(dest) @@ -104,7 +157,8 @@ def decompress(source, format): run_command(f"tar -P -xjvf {source} {tar_options}") else: sys.exit(f"Unsupported format: {format}") - + print_success("Decompression completed successfully") + print("\n" + "=" * 50) print( f"file_path={dest if dest else 'current directory'}", file=open(os.getenv("GITHUB_OUTPUT", "/dev/stdout"), "a"), @@ -116,7 +170,18 @@ def decompress(source, format): source = os.getenv("SOURCE") format = os.getenv("FORMAT") include_root = os.getenv("INCLUDEROOT", "true") + + print_header("Compress/Decompress Action") + print_section("Environment Configuration") + print(f" β€’ Command: {command}") + print(f" β€’ Source: {source}") + print(f" β€’ Format: {format}") + print(f" β€’ Include Root: {include_root}") + if command == "compress": compress(source, format, include_root) elif command == "decompress": decompress(source, format) + else: + print_error(f"Invalid command: {command}") + sys.exit(1)