diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..1947fef --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,31 @@ +name: PR Check for gcsim scripts + +on: + pull_request: + paths: + - 'gcsim/scripts/**' + types: + - opened + - synchronize + - reopened + +jobs: + pr-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install Dependencies + run: | + python -m pip install -r gcsim/requirements.txt + + - name: Check GCSIM scripts + run: | + python gcsim/main.py pr diff --git a/gcsim/main.py b/gcsim/main.py index a7a047c..af5703f 100644 --- a/gcsim/main.py +++ b/gcsim/main.py @@ -6,6 +6,7 @@ from pathlib import Path import aiofiles import re import gcsim_pypi +import sys data_path = Path("gcsim.json") gcsim_path = Path("gcsim") @@ -41,9 +42,14 @@ async def run_gcsim(path: Path) -> bool: _, stderr = await process.communicate() err = stderr.decode() if err: - print(f"{path.name} 解析失败 {err}") + text = f"{path.name} 解析失败 \n\n{err}" + if sys.argv[-1] == "pr": + raise ValueError(text) + print(text) return False return True + except ValueError as e: + raise e except Exception: return False