Skip to content

Commit

Permalink
fix: entrypoint.py
Browse files Browse the repository at this point in the history
  • Loading branch information
somaz94 committed Feb 7, 2025
1 parent b7e2abc commit d039b60
Showing 1 changed file with 74 additions and 9 deletions.
83 changes: 74 additions & 9 deletions entrypoint.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -74,14 +114,27 @@ 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"),
)


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)
Expand All @@ -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"),
Expand All @@ -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)

0 comments on commit d039b60

Please sign in to comment.