[POLISH] 跳过部分无法完成的节点 #27
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 多平台构建 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: windows-2022 | |
| platform: windows | |
| arch: x64 | |
| ext: .exe | |
| name: Windows | |
| icon: 🪟 | |
| - os: macos-latest | |
| platform: macos | |
| arch: x64 | |
| ext: "" | |
| name: macOS | |
| icon: 🍎 | |
| - os: ubuntu-latest | |
| platform: linux | |
| arch: x64 | |
| ext: "" | |
| name: Linux | |
| icon: 🐧 | |
| steps: | |
| - name: ${{ matrix.icon }} 检出代码 (${{ matrix.name }}) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - name: 获取版本信息 | |
| shell: bash | |
| run: | | |
| echo "TAG_NAME=${{github.ref_name}}" >> $GITHUB_ENV | |
| if git describe --tags --abbrev=0 HEAD^ 2>/dev/null; then | |
| echo "PREV_TAG=$(git describe --tags --abbrev=0 HEAD^)" >> $GITHUB_ENV | |
| else | |
| echo "PREV_TAG=" >> $GITHUB_ENV | |
| fi | |
| - name: 生成更新日志 | |
| if: matrix.platform == 'windows' | |
| shell: bash | |
| run: | | |
| # 生成唯一的访问统计ID(移除点和特殊字符) | |
| VIEW_COUNTER_ID=$(echo "11273-mooc-work-answer-${{ env.TAG_NAME }}" | sed 's/[^a-zA-Z0-9-]/-/g') | |
| badge1="[](https://github.com/11273/mooc-work-answer/releases/tag/${{ env.TAG_NAME }})" | |
| badge2="[](https://github.com/11273/mooc-work-answer/releases/tag/${{ env.TAG_NAME }})" | |
| badge3="[](https://github.com/11273/mooc-work-answer/releases/tag/${{ env.TAG_NAME }})" | |
| header="## 🚀 版本更新 ${{ env.TAG_NAME }}" | |
| # 获取提交日志并格式化 - 使用更可靠的方法 | |
| if [ "${{ env.PREV_TAG }}" ]; then | |
| # 使用标签之间的提交范围,确保包含所有提交 | |
| log=$(git rev-list ${{ env.PREV_TAG }}..${{ env.TAG_NAME }} --pretty=format:"- %s" --no-merges | grep "^-" | head -20) | |
| # 如果上面的命令没有结果,回退到原方法 | |
| if [ -z "$log" ]; then | |
| log=$(git log ${{ env.PREV_TAG }}..HEAD --pretty=format:"- %s" --no-merges | head -20) | |
| fi | |
| else | |
| log=$(git log --pretty=format:"- %s" --no-merges | head -10) | |
| fi | |
| # 生成发布说明 | |
| platforms="### 📦 支持平台\n- 🪟 **Windows**: 支持 Windows 7/8/10/11 (x64)\n- 🍎 **macOS**: 支持 macOS 10.14+ (Intel & Apple Silicon)\n- 🐧 **Linux**: 支持主流 Linux 发行版 (x64)" | |
| changelog="${badge1} ${badge2} ${badge3}\n\n${header}\n\n### 📋 更新内容\n${log}\n\n${platforms}\n\n### 💾 下载说明\n- **Windows**: 直接下载 \`.exe\` 文件运行\n- **macOS**: 直接下载可执行文件,通过终端运行\n- **Linux**: 直接下载可执行文件运行\n\n### 🔧 使用方法\n1. 根据您的系统下载对应版本(无需解压)\n2. **Windows**: 双击运行 \`.exe\` 文件\n3. **macOS**: 打开终端,拖拽文件到终端窗口,然后按回车\n4. **Linux**: 在终端中运行 \`./filename\`\n5. 按照提示输入账号信息,选择需要的功能开始使用\n\n### 💡 macOS 使用提示\n- 下载后如果出现权限错误,先运行: \`chmod +x filename\`\n- 然后直接拖拽文件到终端窗口即可运行\n- 或者在终端中 cd 到文件所在目录,然后运行 \`./filename\`" | |
| echo -e "$changelog" > changelog.txt | |
| - name: 注入环境变量 (Spec文件) | |
| if: matrix.platform == 'windows' | |
| uses: NicoG60/simple-template-renderer@v1 | |
| with: | |
| input: StartWorkLite.spec | |
| env: | |
| PYINSTALL_KEY: ${{ secrets.PYINSTALL_KEY }} | |
| TAG_NAME: ${{ env.TAG_NAME }} | |
| - name: 注入环境变量 (Python文件) | |
| uses: NicoG60/simple-template-renderer@v1 | |
| with: | |
| input: StartWork.py | |
| env: | |
| TAG_NAME: ${{ env.TAG_NAME }} | |
| - name: ${{ matrix.icon }} 显示构建信息 (${{ matrix.name }}) | |
| shell: bash | |
| run: | | |
| echo "======================================" | |
| echo "${{ matrix.icon }} 构建信息 - ${{ matrix.name }}" | |
| echo "======================================" | |
| echo "平台: ${{ matrix.platform }}" | |
| echo "架构: ${{ matrix.arch }}" | |
| echo "运行器: ${{ matrix.os }}" | |
| echo "上一版本: ${{ env.PREV_TAG }}" | |
| echo "当前版本: ${{ env.TAG_NAME }}" | |
| echo "======================================" | |
| - name: 配置 Python 环境 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.8" | |
| - name: 安装系统依赖 (Linux) | |
| if: matrix.platform == 'linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential | |
| - name: 安装构建依赖 | |
| shell: bash | |
| run: | | |
| python -m pip install --upgrade pip | |
| # 使用更新的 PyInstaller 版本解决 macOS 代码签名问题 | |
| if [ "${{ matrix.platform }}" = "macos" ]; then | |
| pip install pyinstaller==5.13.2 | |
| else | |
| pip install pyinstaller==4.5 | |
| fi | |
| pip install wheel | |
| pip install tinyaes | |
| pip install -r requirements.txt | |
| - name: ${{ matrix.icon }} 构建可执行文件 (${{ matrix.name }}) | |
| shell: bash | |
| run: | | |
| echo "🔨 开始构建 ${{ matrix.name }} 可执行文件..." | |
| if [ "${{ matrix.platform }}" = "windows" ]; then | |
| pyinstaller StartWorkLite.spec | |
| else | |
| # Linux 构建 | |
| pyinstaller --onefile \ | |
| --name "MoocWorkAnswer-${{ env.TAG_NAME }}-lite-${{ matrix.platform }}" \ | |
| --distpath dist \ | |
| --workpath build \ | |
| --specpath . \ | |
| --console \ | |
| StartWork.py | |
| fi | |
| echo "✅ ${{ matrix.name }} 构建完成" | |
| - name: 验证构建结果 | |
| shell: bash | |
| run: | | |
| if ls dist/* 1> /dev/null 2>&1; then | |
| echo "✅ ${{ matrix.name }} 构建文件生成成功" | |
| ls -la dist/ | |
| else | |
| echo "❌ ${{ matrix.name }} 构建文件生成失败" | |
| exit 1 | |
| fi | |
| - name: 重命名输出文件并设置权限 | |
| shell: bash | |
| run: | | |
| cd dist | |
| for file in *; do | |
| if [ -f "$file" ]; then | |
| # 获取文件扩展名 | |
| if [ "${{ matrix.platform }}" = "windows" ]; then | |
| ext=".exe" | |
| else | |
| ext="" | |
| fi | |
| # 统一文件名格式 | |
| new_name="MoocWorkAnswer-${{ env.TAG_NAME }}-lite-${{ matrix.platform }}${ext}" | |
| # 检查文件名是否已经是目标名称 | |
| if [ "$file" != "$new_name" ]; then | |
| mv "$file" "$new_name" | |
| echo "✅ 文件重命名: $file -> $new_name" | |
| else | |
| echo "ℹ️ 文件名已正确,跳过重命名: $file" | |
| fi | |
| # 为 macOS 和 Linux 设置执行权限和文件属性 | |
| if [ "${{ matrix.platform }}" != "windows" ]; then | |
| chmod +x "$new_name" | |
| echo "✅ 已设置执行权限: $new_name" | |
| # macOS 特殊处理:设置文件类型 | |
| if [ "${{ matrix.platform }}" = "macos" ]; then | |
| # 确保文件被识别为 Unix 可执行文件 | |
| file "$new_name" | |
| ls -la "$new_name" | |
| fi | |
| fi | |
| fi | |
| done | |
| - name: 上传构建产物 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-${{ matrix.platform }}-${{ matrix.arch }} | |
| path: dist/* | |
| retention-days: 1 | |
| # 尝试保持文件权限 | |
| include-hidden-files: true | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| - name: 下载所有构建产物 | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: 整理发布文件 | |
| run: | | |
| mkdir -p release-files | |
| find artifacts -name "*" -type f -exec cp {} release-files/ \; | |
| # 确保 macOS 和 Linux 文件有执行权限 | |
| cd release-files | |
| for file in *; do | |
| if [[ "$file" != *.exe ]]; then | |
| chmod +x "$file" | |
| echo "✅ 设置执行权限: $file" | |
| # 检查 macOS 文件 | |
| if [[ "$file" == *"macos"* ]]; then | |
| echo "🍎 macOS 文件信息:" | |
| file "$file" || echo "file 命令不可用" | |
| ls -la "$file" | |
| fi | |
| fi | |
| done | |
| echo "📦 所有发布文件:" | |
| ls -la | |
| - name: 获取更新日志 | |
| run: | | |
| # 重新生成更新日志(因为需要在release job中使用) | |
| TAG_NAME=${{github.ref_name}} | |
| if git describe --tags --abbrev=0 HEAD^ 2>/dev/null; then | |
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD^) | |
| # 使用标签之间的提交范围,确保包含所有提交 | |
| log=$(git rev-list ${PREV_TAG}..${TAG_NAME} --pretty=format:"- %s" --no-merges | grep "^-" | head -20) | |
| # 如果上面的命令没有结果,回退到原方法 | |
| if [ -z "$log" ]; then | |
| log=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s" --no-merges | head -20) | |
| fi | |
| else | |
| log=$(git log --pretty=format:"- %s" --no-merges | head -10) | |
| fi | |
| # 生成唯一的访问统计ID(移除点和特殊字符) | |
| VIEW_COUNTER_ID=$(echo "11273-mooc-work-answer-${TAG_NAME}" | sed 's/[^a-zA-Z0-9-]/-/g') | |
| badge1="[](https://github.com/11273/mooc-work-answer/releases/tag/${TAG_NAME})" | |
| badge2="[](https://github.com/11273/mooc-work-answer/releases/tag/${TAG_NAME})" | |
| badge3="[](https://github.com/11273/mooc-work-answer/releases/tag/${TAG_NAME})" | |
| header="## 🚀 版本更新 ${TAG_NAME}" | |
| platforms="### 📦 支持平台\n- 🪟 **Windows**: 支持 Windows 7/8/10/11 (x64)\n- 🍎 **macOS**: 支持 macOS 10.14+ (Intel & Apple Silicon)\n- 🐧 **Linux**: 支持主流 Linux 发行版 (x64)" | |
| changelog="${badge1} ${badge2} ${badge3}\n\n${header}\n\n### 📋 更新内容\n${log}\n\n${platforms}\n\n### 💾 下载说明\n- **Windows**: 直接下载 \`.exe\` 文件运行\n- **macOS**: 直接下载可执行文件,通过终端运行\n- **Linux**: 直接下载可执行文件运行\n\n### 🔧 使用方法\n1. 根据您的系统下载对应版本(无需解压)\n2. **Windows**: 双击运行 \`.exe\` 文件\n3. **macOS**: 打开终端,拖拽文件到终端窗口,然后按回车\n4. **Linux**: 在终端中运行 \`./filename\`\n5. 按照提示输入账号信息,选择需要的功能开始使用\n\n### 💡 macOS 使用提示\n- 下载后如果出现权限错误,先运行: \`chmod +x filename\`\n- 然后直接拖拽文件到终端窗口即可运行\n- 或者在终端中 cd 到文件所在目录,然后运行 \`./filename\`" | |
| echo -e "$changelog" > changelog.txt | |
| - name: 🚀 创建多平台发布 | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: "🚀 Release ${{github.ref_name}}" | |
| body_path: changelog.txt | |
| files: | | |
| release-files/* | |
| draft: false | |
| prerelease: false | |
| make_latest: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # - name: 更新 README 发布链接 | |
| # run: | | |
| # echo "📝 更新 README.md 中的下载链接..." | |
| # # 更新 README.md 中的下载链接 | |
| # sed -i "s|https://github.com/11273/mooc-work-answer/releases/latest|${{ steps.create_release.outputs.url }}|g" README.md | |
| # # 检查是否有变更 | |
| # if git diff --quiet README.md; then | |
| # echo "ℹ️ README.md 无需更新" | |
| # else | |
| # echo "✅ README.md 已更新" | |
| # git config --global user.name "🤖 GitHub Actions" | |
| # git config --global user.email "actions@github.com" | |
| # git add README.md | |
| # git commit -m "📝 更新 README.md 发布链接至 ${{github.ref_name}}" | |
| # fi | |
| # - name: 推送更改到仓库 | |
| # if: success() | |
| # run: | | |
| # git config --global user.name "🤖 GitHub Actions" | |
| # git config --global user.email "actions@github.com" | |
| # # 先拉取远程更改避免冲突 | |
| # git pull origin main --rebase || true | |
| # # 如果有更改则推送 | |
| # if ! git diff --quiet HEAD~1 HEAD; then | |
| # git push https://${{ secrets.PAT_TOKEN }}@github.com/11273/mooc-work-answer.git main | |
| # echo "✅ 成功推送更改到仓库" | |
| # else | |
| # echo "ℹ️ 没有需要推送的更改" | |
| # fi |