From 1d6fc0a861d132808181b8c9a6ccea1297e31e92 Mon Sep 17 00:00:00 2001 From: XFY9326 Date: Mon, 26 Feb 2024 12:49:44 +0800 Subject: [PATCH] Fix --- .github/workflows/release.yml | 2 ++ .github/workflows/test.yml | 2 ++ build_protobuf.py | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 560ded1..6e45853 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,6 +20,8 @@ jobs: python-version: "3.10" - name: Install Protoc uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Install dependencies run: | python -m pip install --upgrade pip wheel setuptools diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5774fc..205444f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,8 @@ jobs: python-version: "3.10" - name: Install Protoc uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Install dependencies run: | python -m pip install --upgrade pip wheel setuptools diff --git a/build_protobuf.py b/build_protobuf.py index 25a6016..01d8a7b 100644 --- a/build_protobuf.py +++ b/build_protobuf.py @@ -1,7 +1,7 @@ import os from pathlib import Path -PROJECT_ROOT = Path(__file__).parent.absolute() +PROJECT_ROOT = Path(__file__).resolve().parent.absolute() PROTOC_PATH = "protoc" PROTO_DIR = PROJECT_ROOT.joinpath("proto") @@ -12,6 +12,7 @@ print("protoc not found") exit(1) + print() if PYTHON_OUTPUT_DIR.exists(): old_files = [i for i in os.listdir(PYTHON_OUTPUT_DIR) if i.endswith(("_pb2.py", "_pb2.pyi"))] if len(old_files) > 0: @@ -23,11 +24,21 @@ PYTHON_OUTPUT_DIR.mkdir() PYTHON_OUTPUT_DIR.joinpath("__init__.py").touch() + print() print("Creating protobuf files") - os.system(" ".join([ + proto_files = [f"\"{i}\"" for i in PROTO_DIR.glob("*.proto")] + protoc_cmd = [ str(PROTOC_PATH), f"--proto_path=\"{PROTO_DIR}\"", f"--pyi_out=\"{PYTHON_OUTPUT_DIR}\"", f"--python_out=\"{PYTHON_OUTPUT_DIR}\"", - f"\"{PROTO_DIR.joinpath('*')}\"" - ])) + *proto_files + ] + print("Commands:", "\n".join(protoc_cmd)) + + result = os.system(" ".join(protoc_cmd)) + print() + if result == 0: + print("Protobuf files create success") + else: + print("Protobuf files create failed")