diff --git a/.github/workflows/build-win.yml b/.github/workflows/build-and-release.yml similarity index 57% rename from .github/workflows/build-win.yml rename to .github/workflows/build-and-release.yml index 525828f..8918f8e 100644 --- a/.github/workflows/build-win.yml +++ b/.github/workflows/build-and-release.yml @@ -1,4 +1,4 @@ -name: Build Windows Executable with PyInstaller +name: Build and Release # 触发工作流的事件 on: @@ -7,9 +7,12 @@ on: - 'v*' jobs: - build-windows: + build-and-release: # 使用 Windows 运行环境 - runs-on: windows-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ windows-latest, macos-latest ] steps: # 检出代码 @@ -20,37 +23,45 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.12.8' # 保持用户指定的 Python 版本 - architecture: 'x64' + python-version: '3.12.8' # 安装依赖和 PyInstaller - name: Install dependencies run: | python -m pip install --upgrade pip - if (Test-Path requirements.txt) { pip install -r requirements.txt } + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pip install pyinstaller - shell: pwsh + shell: bash # 运行 PyInstaller 打包 - - name: Build executable + - name: Build with PyInstaller run: | pyinstaller -y --clean -D -c -n wxdown-service --add-data=resources/credential.py:resources/ main.py - shell: pwsh + shell: bash # 调试:列出 dist/ 目录内容 - name: List dist directory run: | - Get-ChildItem -Path dist -Recurse - shell: pwsh + ls -al + shell: bash # 压缩 dist/wxdown-service/ 为 wxdown-service.zip - - name: Create zip archive + - name: Zip the bundle + if: runner.os == 'Windows' run: | Compress-Archive -Path dist/wxdown-service/* -DestinationPath wxdown-service-windows.zip shell: pwsh + - name: Zip the bundle + if: runner.os == 'macOS' + run: | + zip -r wxdown-service-macos.zip dist/wxdown-service + shell: bash + # 上传打包结果 - name: Upload release assets - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: - files: wxdown-service-windows.zip + files: | + wxdown-service-windows.zip + wxdown-service-macos.zip diff --git a/cert/__init__.py b/cert/__init__.py index e69de29..1fc8ba5 100644 --- a/cert/__init__.py +++ b/cert/__init__.py @@ -0,0 +1,24 @@ +import platform +import subprocess + + +def is_certificate_installed(cert_name = 'mitmproxy'): + if platform.system() == 'Windows': + import wincertstore + + stores = ["MY", "ROOT", "CA"] + for store in stores: + with wincertstore.CertSystemStore(store) as store: + for cert in store.itercerts(): + name = cert.get_name() + if name == cert_name: + return True + return False + elif platform.system() == 'Darwin': + try: + result = subprocess.run(['security', 'find-certificate', '-c', cert_name], capture_output=True, text=True) + return result.returncode == 0 + except FileNotFoundError: + raise NotImplementedError("此系统中未找到 security 命令") + else: + raise NotImplementedError(f"暂不支持该系统: {platform.system()}") diff --git a/cert/macos.py b/cert/macos.py deleted file mode 100644 index 46a3abb..0000000 --- a/cert/macos.py +++ /dev/null @@ -1,9 +0,0 @@ -import subprocess - - -def is_certificate_installed(cert_name = 'mitmproxy'): - try: - result = subprocess.run(['security', 'find-certificate', '-c', cert_name], capture_output=True, text=True) - return result.returncode == 0 - except FileNotFoundError: - raise NotImplementedError("此系统中未找到 security 命令") diff --git a/cert/win.py b/cert/win.py deleted file mode 100644 index 952ba1b..0000000 --- a/cert/win.py +++ /dev/null @@ -1,12 +0,0 @@ -import wincertstore - - -def is_certificate_installed(cert_name = "mitmproxy"): - stores = ["MY", "ROOT", "CA"] - for storename in stores: - with wincertstore.CertSystemStore(storename) as store: - for cert in store.itercerts(): - name = cert.get_name() - if name == cert_name: - return True - return False diff --git a/utils.py b/utils.py index 8acc06e..23bf7df 100644 --- a/utils.py +++ b/utils.py @@ -2,8 +2,7 @@ import re import urllib.request import requests - -from cert import win +import cert # 检查代理是否正确 @@ -24,7 +23,7 @@ def is_proxy_correct(target_proxy_address): # 检查证书是否安装 def wait_until_certificate_installed(): while True: - if win.is_certificate_installed('mitmproxy'): + if cert.is_certificate_installed('mitmproxy'): break else: input(