更新UA #295
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: | |
| workflow_dispatch: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - 'src/module/**' | |
| - 'src/webui/**' | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| name: 构建 | |
| runs-on: ubuntu-latest | |
| outputs: | |
| commit_count: ${{ steps.get_version.outputs.commit_count }} | |
| steps: | |
| - name: 拉取代码 | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: 设置 Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: src/webui/package-lock.json | |
| - name: 设置 Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.x' | |
| - name: 安装 WebUI 依赖 | |
| working-directory: src/webui | |
| run: npm install | |
| - name: 更新 versionCode | |
| id: get_version | |
| run: | | |
| COMMIT_COUNT=$(git rev-list --count HEAD) | |
| sed -i "s/^versionCode=.*/versionCode=$COMMIT_COUNT/" src/module/module.prop | |
| echo "versionCode 已更新为: $COMMIT_COUNT" | |
| echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT | |
| - name: 构建 WebUI | |
| run: python src/webui/build_webui.py | |
| - name: 上传构建产物 | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: NetProxy-Module | |
| path: src/module/ | |
| notify: | |
| name: 发送通知 | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: always() | |
| steps: | |
| - name: 下载构建产物 | |
| if: ${{ needs.build.result == 'success' }} | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: NetProxy-Module | |
| path: src/module | |
| - name: 打包模块 | |
| if: ${{ needs.build.result == 'success' }} | |
| run: | | |
| COMMIT_COUNT=${{ needs.build.outputs.commit_count }} | |
| # 从 module.prop 读取 version | |
| VERSION=$(grep '^version=' src/module/module.prop | cut -d= -f2) | |
| ZIP_NAME="NetProxy_${VERSION}_${COMMIT_COUNT}.zip" | |
| echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV | |
| cd src/module | |
| zip -r "../../$ZIP_NAME" . | |
| cd .. | |
| - name: 发送模块到 Telegram | |
| if: ${{ needs.build.result == 'success' }} | |
| env: | |
| COMMIT_MSG: ${{ github.event.head_commit.message }} | |
| run: | | |
| CAPTION="模块构建成功通知 | |
| 文件: \`${{ env.ZIP_NAME }}\` | |
| 说明: | |
| \`\`\` | |
| $COMMIT_MSG | |
| \`\`\` | |
| [提交记录](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}) | |
| [构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
| curl -v -F "chat_id=${{ secrets.TG_CHAT_ID }}" \ | |
| -F "document=@${{ env.ZIP_NAME }}" \ | |
| -F "message_thread_id=2275" \ | |
| -F "parse_mode=Markdown" \ | |
| -F "caption=$CAPTION" \ | |
| https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendDocument | |
| - name: 失败通知 | |
| if: ${{ needs.build.result == 'failure' }} | |
| env: | |
| COMMIT_MSG: ${{ github.event.head_commit.message }} | |
| uses: cbrgm/telegram-github-action@v1 | |
| with: | |
| token: ${{ secrets.TG_BOT_TOKEN }} | |
| to: ${{ secrets.TG_CHAT_ID }} | |
| thread-id: 2275 | |
| parse-mode: markdown | |
| message: | | |
| 模块构建失败通知! | |
| 说明: | |
| \`\`\` | |
| $COMMIT_MSG | |
| \`\`\` | |
| [提交记录](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}) | |
| [构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
| - name: Release 发布通知 | |
| if: ${{ github.event_name == 'release' }} | |
| uses: cbrgm/telegram-github-action@v1 | |
| with: | |
| token: ${{ secrets.TG_BOT_TOKEN }} | |
| to: ${{ secrets.TG_CHAT_ID }} | |
| thread-id: 2343 | |
| parse-mode: markdown | |
| message: | | |
| 新版本发布通知! | |
| 版本: `${{ github.event.release.tag_name }}` | |
| [查看更新日志](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.event.release.tag_name }}) | |
| [下载模块](${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/NetProxy-Module.zip) |