From 3646908a0023aa8492a9ecbcc643672257dd9f6c Mon Sep 17 00:00:00 2001 From: Hsdi Date: Sun, 15 Mar 2026 23:51:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99=E7=9A=84?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=B7=A5=E4=BD=9C=E6=B5=81=E6=96=87=E4=BB=B6?= =?UTF-8?q?=20build-exe.yml=20=E5=92=8C=20build-exe-Miu.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-exe-Miu.yml | 134 --------------- .github/workflows/build-exe.yml | 245 ---------------------------- 2 files changed, 379 deletions(-) delete mode 100644 .github/workflows/build-exe-Miu.yml delete mode 100644 .github/workflows/build-exe.yml diff --git a/.github/workflows/build-exe-Miu.yml b/.github/workflows/build-exe-Miu.yml deleted file mode 100644 index 8532a49..0000000 --- a/.github/workflows/build-exe-Miu.yml +++ /dev/null @@ -1,134 +0,0 @@ -name: Build Windows EXE with Full Image -on: - push: - # 推荐:只在打标签时触发 Release - tags: - - 'v*' # 例如推送 v1.0.0, v2.1.3 等标签时触发 - # 如果你想在每次推送时都创建,也可以保留 branches,但通常会打 tag - branches: ["main"] - -jobs: - build: - runs-on: Ubuntu_docker_act - steps: - - uses: actions/checkout@v4 - - # 步骤1:下载 Python 3.9.9 安装包(保持文件名一致) - - name: Download Python 3.9.9 installer - run: | - wget https://mirrors.tuna.tsinghua.edu.cn/python/3.9.9/python-3.9.9-amd64.exe - ls -lh python-3.9.9-amd64.exe - # 验证文件完整性 - file python-3.9.9-amd64.exe - - - name: Reset Wine environment (clean slate) - run: | - echo "=== 备份并删除旧的 Wine 配置目录 ===" - # 如果 ~/.wine 目录存在,先重命名备份(或直接删除) - if [ -d "$HOME/.wine" ]; then - mv "$HOME/.wine" "$HOME/.wine.bak.$(date +%s)" - echo "Old .wine directory backed up." - fi - - echo "=== 初始化一个新的干净的Wine环境 ===" - # 初始化Wine环境,使用 xvfb-run 避免任何图形界面问题 - # 设置 WINEARCH 为 win64 以支持64位 - export WINEARCH=win64 - xvfb-run wineboot -u - - echo "=== 验证新环境 ===" - # 等待几秒让环境初始化完成 - sleep 5 - wine --version - xvfb-run wine cmd /c "echo Wine environment is ready" - - # 步骤3:安装 Python(使用正确的文件名) - - name: Install Python in Wine - run: | - echo "Current directory: $(pwd)" - ls -lah - - if [ ! -f python-3.9.9-amd64.exe ]; then - echo "Installer not found!" - exit 1 - fi - - # 直接用 wine 运行 - xvfb-run -a wine python-3.9.9-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 - - # 等待安装 - sleep 20 - - # 步骤4:更彻底地查找 Python - - name: Find and verify Python - run: | - echo "=== Searching all possible Python locations ===" - # 查找所有 python.exe - find /root/.wine/drive_c -name "python.exe" 2>/dev/null | while read path; do - echo "Found: $path" - echo "Version info:" - wine "$path" --version 2>/dev/null || echo "Cannot run $path" - done - - # 尝试常见路径 - COMMON_PATHS=( - "/root/.wine/drive_c/Python39/python.exe" - "/root/.wine/drive_c/Python39-32/python.exe" - "/root/.wine/drive_c/Program Files/Python39/python.exe" - "/root/.wine/drive_c/users/runner/AppData/Local/Programs/Python/Python39/python.exe" - ) - - for path in "${COMMON_PATHS[@]}"; do - if [ -f "$path" ]; then - echo "Found Python at standard location: $path" - PYTHON_EXE="$path" - break - fi - done - - if [ -z "$PYTHON_EXE" ]; then - echo "Python not found in standard locations" - exit 1 - fi - - echo "PYTHON_EXE=$PYTHON_EXE" >> $GITHUB_ENV - wine "$PYTHON_EXE" --version - - # 步骤5:安装依赖 - - name: Install dependencies - run: | - # 先配置 pip 使用清华源(或其他国内源) - wine "$PYTHON_EXE" -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple - wine "$PYTHON_EXE" -m pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn - # 升级 pip - wine "$PYTHON_EXE" -m pip install --upgrade pip - # 安装包 - wine "$PYTHON_EXE" -m pip install pyinstaller keyboard pywin32 - - # 步骤6:构建 EXE - - name: Build EXE - run: | - wine "$PYTHON_EXE" -m PyInstaller --onefile --windowed --name Shortcut_Sync_PotPlayer main.py - - # 步骤7:上传构建产物(修复版本) - - name: Upload Artifact - uses: christopherhx/gitea-upload-artifact@v4 # 关键修复! - with: - name: Shortcut_Sync_PotPlayer - path: dist/Shortcut_Sync_PotPlayer.exe - - - name: Create Release and Upload Asset - # 使用专门为 Gitea 开发的 release action - # 这是一个在 Gitea 生态中广泛使用的版本 [citation:2][citation:5] - uses: https://gitea.com/actions/release-action@main - with: - # 文件路径:指向你 PyInstaller 生成的 EXE 文件 - files: dist/Shortcut_Sync_PotPlayer.exe - # API 密钥:使用 Gitea 自动提供的 token,用于认证 - api_key: '${{ secrets.GITHUB_TOKEN }}' - # 可选:设置 Release 的标题,默认会使用 tag 名称 - name: 'Release ${{ github.ref_name }}' - # 可选:是否为草稿 (true/false) - draft: false - # 可选:是否为预发布 (true/false) - prerelease: false \ No newline at end of file diff --git a/.github/workflows/build-exe.yml b/.github/workflows/build-exe.yml deleted file mode 100644 index 43cea70..0000000 --- a/.github/workflows/build-exe.yml +++ /dev/null @@ -1,245 +0,0 @@ -name: Build Windows EXE - -on: - push: - workflow_dispatch: - -env: - APP_NAME: Shortcut_Sync_PotPlayer - PACKAGE_NAME: shortcut-sync-potplayer - PYTHON_VERSION: "3.9.1" - PYTHON_DIR: 'C:\Python391' - PYTHON_EXE: 'C:\Python391\python.exe' - -jobs: - build: - runs-on: ubuntu-22.04 - - steps: - - name: Checkout repository - shell: bash - env: - ACTIONS_TOKEN: ${{ github.token }} - GIT_TERMINAL_PROMPT: 0 - run: | - pwd - ls -la - - if [ -f main.py ]; then - echo "Repository already available in workspace." - exit 0 - fi - - if ! command -v git >/dev/null 2>&1; then - sudo apt-get update - sudo apt-get install -y --no-install-recommends git ca-certificates - fi - - repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" - - if [ ! -d .git ]; then - git init . - fi - - git config --global --add safe.directory "$PWD" - - if git remote get-url origin >/dev/null 2>&1; then - git remote set-url origin "$repo_url" - else - git remote add origin "$repo_url" - fi - - fetch_target() { - local target="$1" - git fetch --depth=1 origin "$target" - } - - fetch_with_basic_auth() { - local target="$1" - local username="$2" - local auth_header - auth_header="$(printf '%s:%s' "$username" "${ACTIONS_TOKEN}" | base64 -w0)" - git \ - -c http.extraHeader="Authorization: Basic ${auth_header}" \ - fetch --depth=1 origin "$target" - } - - if fetch_target "${GITHUB_SHA}" || fetch_target "${GITHUB_REF}"; then - echo "Fetched repository without authentication." - elif [ -n "${ACTIONS_TOKEN:-}" ] && (fetch_with_basic_auth "${GITHUB_SHA}" "${GITHUB_ACTOR:-git}" || fetch_with_basic_auth "${GITHUB_REF}" "${GITHUB_ACTOR:-git}"); then - echo "Fetched repository with actor token authentication." - elif [ -n "${ACTIONS_TOKEN:-}" ] && (fetch_with_basic_auth "${GITHUB_SHA}" "oauth2" || fetch_with_basic_auth "${GITHUB_REF}" "oauth2"); then - echo "Fetched repository with oauth2 token authentication." - elif [ -n "${ACTIONS_TOKEN:-}" ] && (fetch_with_basic_auth "${GITHUB_SHA}" "git" || fetch_with_basic_auth "${GITHUB_REF}" "git"); then - echo "Fetched repository with git token authentication." - else - echo "Failed to fetch repository contents from ${repo_url}." - exit 1 - fi - - git checkout --force FETCH_HEAD - git log -1 --oneline - test -f main.py - - - name: Setup Wine - shell: bash - run: | - WINEPREFIX="$RUNNER_TEMP/wine" - echo "WINEPREFIX=$WINEPREFIX" >> "$GITHUB_ENV" - echo "WINEDEBUG=-all" >> "$GITHUB_ENV" - export WINEPREFIX - export WINEDEBUG=-all - - sudo dpkg --add-architecture i386 - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - wine64 \ - wine32 \ - curl \ - ca-certificates \ - jq \ - xvfb \ - zip - - xvfb-run -a wine64 wineboot --init - wineserver -w - wine64 --version - - - name: Install Windows Python - shell: bash - run: | - curl -fsSL \ - "https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-amd64.exe" \ - -o /tmp/python-installer.exe - - xvfb-run -a wine64 /tmp/python-installer.exe \ - /quiet \ - InstallAllUsers=1 \ - PrependPath=1 \ - Include_pip=1 \ - Include_test=0 \ - SimpleInstall=1 \ - "TargetDir=${PYTHON_DIR}" - - wineserver -w - rm -f /tmp/python-installer.exe - xvfb-run -a wine64 "${PYTHON_EXE}" --version - - - name: Install dependencies - shell: bash - run: | - xvfb-run -a wine64 "${PYTHON_EXE}" -m pip install --upgrade pip setuptools wheel - - if [ -f requirements.txt ]; then - xvfb-run -a wine64 "${PYTHON_EXE}" -m pip install --no-cache-dir -r requirements.txt - fi - - xvfb-run -a wine64 "${PYTHON_EXE}" -m pip install --no-cache-dir \ - pyinstaller \ - keyboard \ - pywin32 - - xvfb-run -a wine64 "${PYTHON_EXE}" -c "import keyboard, win32api, win32gui; print('dependencies ok')" - - - name: Build EXE - shell: bash - run: | - xvfb-run -a wine64 "${PYTHON_EXE}" -m PyInstaller \ - --noconfirm \ - --clean \ - --onefile \ - --windowed \ - --name "${APP_NAME}" \ - main.py - - test -f "dist/${APP_NAME}.exe" - - - name: Package build - id: package - shell: bash - run: | - if [[ "$GITHUB_REF" == refs/tags/* ]]; then - version="$GITHUB_REF_NAME" - else - version="run-${GITHUB_RUN_NUMBER}-${GITHUB_SHA::7}" - fi - - archive_name="${APP_NAME}-${version}-windows-x64.zip" - archive_path="dist/${archive_name}" - - zip -j "$archive_path" "dist/${APP_NAME}.exe" - - echo "version=${version}" >> "$GITHUB_OUTPUT" - echo "archive_name=${archive_name}" >> "$GITHUB_OUTPUT" - echo "archive_path=${archive_path}" >> "$GITHUB_OUTPUT" - - - name: Upload package to Gitea Packages - id: publish_package - shell: bash - env: - ACTIONS_TOKEN: ${{ github.token }} - run: | - owner="${GITHUB_REPOSITORY%%/*}" - package_url="${GITHUB_SERVER_URL}/api/packages/${owner}/generic/${PACKAGE_NAME}/${{ steps.package.outputs.version }}/${{ steps.package.outputs.archive_name }}" - - curl --fail-with-body --silent --show-error \ - -X PUT \ - -H "Authorization: token ${ACTIONS_TOKEN}" \ - -H "Content-Type: application/zip" \ - --upload-file "${{ steps.package.outputs.archive_path }}" \ - "$package_url" - - echo "package_url=${package_url}" >> "$GITHUB_OUTPUT" - if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then - echo "Built package: ${package_url}" >> "$GITHUB_STEP_SUMMARY" - fi - - - name: Create release on tag - if: startsWith(github.ref, 'refs/tags/') - shell: bash - env: - ACTIONS_TOKEN: ${{ github.token }} - run: | - api_url="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}" - releases_url="${api_url}/repos/${GITHUB_REPOSITORY}/releases" - tag_name="${GITHUB_REF_NAME}" - release_name="${tag_name}" - body="Windows build package: ${{ steps.publish_package.outputs.package_url }}" - - existing_release_id="$( - curl --silent \ - -H "Authorization: token ${ACTIONS_TOKEN}" \ - "${releases_url}" | jq -r --arg tag "$tag_name" '.[] | select(.tag_name == $tag) | .id' | head -n 1 - )" - - if [ -n "$existing_release_id" ] && [ "$existing_release_id" != "null" ]; then - echo "Release already exists for ${tag_name}, skipping creation." - exit 0 - fi - - payload="$( - jq -n \ - --arg tag_name "$tag_name" \ - --arg target_commitish "$GITHUB_SHA" \ - --arg name "$release_name" \ - --arg body "$body" \ - '{ - tag_name: $tag_name, - target_commitish: $target_commitish, - name: $name, - body: $body, - draft: false, - prerelease: false - }' - )" - - curl --fail-with-body --silent --show-error \ - -X POST \ - -H "Authorization: token ${ACTIONS_TOKEN}" \ - -H "Content-Type: application/json" \ - -d "$payload" \ - "$releases_url" > /dev/null - - if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then - echo "Release created for ${tag_name}" >> "$GITHUB_STEP_SUMMARY" - fi