From ab44a3861626f10820bc64ea8b2f9c11299b6d04 Mon Sep 17 00:00:00 2001 From: lilingfengdev Date: Mon, 10 Jun 2024 20:02:11 +0800 Subject: [PATCH] =?UTF-8?q?Github=E4=BF=9D=E4=BD=91=E6=88=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 35 +++++++++++++++++++++++++++++++++++ generate-bundle.py | 23 +++++++++++++++++++++++ plugin/utils/translate.py | 2 ++ 3 files changed, 60 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 generate-bundle.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..70a48a6 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +permissions: + contents: write + +on: + [push] + +jobs: + build: + name: Auto Release + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install Dependencies and Generate Bundle + run: | + python generate-bundle.py + - name: Auto release + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: ${{ matrix.os }} + prerelease: true + files: | + dist/* \ No newline at end of file diff --git a/generate-bundle.py b/generate-bundle.py new file mode 100644 index 0000000..f31ac8c --- /dev/null +++ b/generate-bundle.py @@ -0,0 +1,23 @@ +import os +import shutil +import urllib.request +import zipfile +import platform + +os.system("python3 -m pip install cn_bing_translator requests pyinstaller") +if platform.system() == 'Windows': + urllib.request.urlretrieve("https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-win64.zip", + "upx.zip") + zip = zipfile.ZipFile("upx.zip") + zip.extract("upx-4.2.4-win64/upx.exe", path=os.getcwd()) + shutil.move("upx-4.2.4-win64/upx.exe", os.path.join(os.getcwd(), "upx.exe")) + +import PyInstaller.__main__ + +os.mkdir("dist") + +flag = ["-F", "main.py", "--optimize", "2"] +if platform.system() != 'Windows': + flag.append("--strip") +PyInstaller.__main__.run(flag) + diff --git a/plugin/utils/translate.py b/plugin/utils/translate.py index d564307..b522f9c 100644 --- a/plugin/utils/translate.py +++ b/plugin/utils/translate.py @@ -1,9 +1,11 @@ from cn_bing_translator import Translator +from functools import lru_cache EN = "en" ZH_CN = "zh-Hans" +@lru_cache(maxsize=None) def translate(text, to_lang=ZH_CN) -> str: translator = Translator() return translator.process(text, toLang=to_lang)