Skip to content

[로또] 김지성 미션 제출합니다. #30

[로또] 김지성 미션 제출합니다.

[로또] 김지성 미션 제출합니다. #30

name: Check No External Libraries
on: pull_request
jobs:
check-no-external-libs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Ensure no external libraries are imported
run: |
python -c "
import os
import ast
allowed_modules = {'sys', 'os', 'math', 'random', 'datetime', 're' 'enum'}
def is_internal_module(module_name):
\"\"\" 내부 모듈(`src/` 폴더 내 Python 파일)인지 확인 \"\"\"
module_path = os.path.join('src', module_name.replace('.', '/') + '.py')
module_dir = os.path.join('src', module_name.replace('.', '/'))
return os.path.exists(module_path) or os.path.isdir(module_dir)
def check_imports(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
tree = ast.parse(f.read(), filename=file_path)
for node in ast.walk(tree):
if isinstance(node, ast.Import):
for alias in node.names:
if alias.name not in allowed_modules and not is_internal_module(alias.name):
raise SystemExit(f'❌ External library detected: {alias.name} in {file_path}')
elif isinstance(node, ast.ImportFrom):
if node.module and node.module not in allowed_modules and not is_internal_module(node.module):
raise SystemExit(f'❌ External library detected: {node.module} in {file_path}')
for root, _, files in os.walk('src'):
for file in files:
if file.endswith('.py'):
check_imports(os.path.join(root, file))"