From 94df038affec51ab5f3feca77d2f2d607853b377 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 2 Dec 2023 18:43:03 +0800 Subject: [PATCH] :construction_worker: Check gcsim scripts pr --- .github/workflows/pr.yml | 31 +++++++++++++++++++++++++++++++ gcsim/main.py | 8 +++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr.yml 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