|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ["v*"] |
| 7 | + pull_request: |
| 8 | + |
| 9 | +# 同一分支的新推送取消还在跑的旧流水线(tag 推送各占一个 group,互不影响) |
| 10 | +concurrency: |
| 11 | + group: ci-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + # ---------- ① 测试 + 前端构建 + 部署包(每次推送/PR 都跑) ---------- |
| 19 | + test-and-build: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: "3.13" # 对齐 pve02 线上版本 |
| 27 | + |
| 28 | + - name: 后端单元测试 |
| 29 | + run: | |
| 30 | + pip install -r app/requirements.txt |
| 31 | + python -m unittest discover -s app/tests -t . -v |
| 32 | +
|
| 33 | + - uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version: 22 |
| 36 | + cache: npm |
| 37 | + cache-dependency-path: frontend/package-lock.json |
| 38 | + |
| 39 | + - name: 前端构建(含 vue-tsc 全量类型检查) |
| 40 | + working-directory: frontend |
| 41 | + run: | |
| 42 | + npm ci |
| 43 | + npm run build |
| 44 | +
|
| 45 | + - name: 确认前端产物就位 |
| 46 | + run: test -f app/static/index.html |
| 47 | + |
| 48 | + # 成员路径必须是 app/...(对齐 DEPLOY.md 坑①),排除运行时数据 |
| 49 | + - name: 打部署包 |
| 50 | + run: > |
| 51 | + tar czf gpu-fan-console-app.tgz |
| 52 | + --exclude='__pycache__' --exclude='*.pyc' --exclude='app/data' |
| 53 | + -C . app |
| 54 | +
|
| 55 | + - uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: gpu-fan-console-app |
| 58 | + path: gpu-fan-console-app.tgz |
| 59 | + |
| 60 | + # ---------- ② 控制台双平台可执行(PR 不跑,省 Windows 时长) ---------- |
| 61 | + build-console: |
| 62 | + if: github.event_name != 'pull_request' |
| 63 | + needs: test-and-build |
| 64 | + timeout-minutes: 30 |
| 65 | + strategy: |
| 66 | + fail-fast: false |
| 67 | + matrix: |
| 68 | + include: |
| 69 | + - os: ubuntu-latest |
| 70 | + - os: windows-latest |
| 71 | + runs-on: ${{ matrix.os }} |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + |
| 75 | + # 前端产物在 ubuntu 上构建,这里从部署包里解开复用(静态资源与平台无关) |
| 76 | + - uses: actions/download-artifact@v4 |
| 77 | + with: |
| 78 | + name: gpu-fan-console-app |
| 79 | + - run: tar xzf gpu-fan-console-app.tgz |
| 80 | + |
| 81 | + - uses: actions/setup-python@v5 |
| 82 | + with: |
| 83 | + python-version: "3.13" |
| 84 | + |
| 85 | + - name: 构建控制台可执行 |
| 86 | + run: | |
| 87 | + pip install -r app/requirements.txt pyinstaller |
| 88 | + python packaging/build_console.py |
| 89 | +
|
| 90 | + - name: 打包分发(Windows → zip / Linux → tar.gz) |
| 91 | + shell: bash |
| 92 | + run: | |
| 93 | + cd dist |
| 94 | + if [ "$RUNNER_OS" = "Windows" ]; then |
| 95 | + tar -a -cf gpu-fan-console-windows-x64.zip gpu-fan-console |
| 96 | + else |
| 97 | + tar czf gpu-fan-console-linux-x64.tar.gz gpu-fan-console |
| 98 | + fi |
| 99 | +
|
| 100 | + - uses: actions/upload-artifact@v4 |
| 101 | + with: |
| 102 | + name: gpu-fan-console-${{ matrix.os }} |
| 103 | + path: dist/gpu-fan-console-* |
| 104 | + |
| 105 | + # ---------- ③ 旧版脚本单文件可执行(PR 不跑) ---------- |
| 106 | + build-legacy: |
| 107 | + if: github.event_name != 'pull_request' |
| 108 | + timeout-minutes: 30 |
| 109 | + strategy: |
| 110 | + fail-fast: false |
| 111 | + matrix: |
| 112 | + include: |
| 113 | + - os: ubuntu-latest |
| 114 | + - os: windows-latest |
| 115 | + runs-on: ${{ matrix.os }} |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v4 |
| 118 | + |
| 119 | + - uses: actions/setup-python@v5 |
| 120 | + with: |
| 121 | + python-version: "3.13" |
| 122 | + |
| 123 | + - name: 构建旧脚本单文件可执行 |
| 124 | + run: | |
| 125 | + pip install pyinstaller |
| 126 | + python packaging/build_legacy.py |
| 127 | +
|
| 128 | + - name: 按平台重命名产物 |
| 129 | + shell: bash |
| 130 | + run: | |
| 131 | + cd dist |
| 132 | + for f in fancontroller fancontroller_once; do |
| 133 | + if [ "$RUNNER_OS" = "Windows" ]; then |
| 134 | + mv "$f.exe" "$f-windows-x64.exe" |
| 135 | + else |
| 136 | + mv "$f" "$f-linux-x64" |
| 137 | + fi |
| 138 | + done |
| 139 | +
|
| 140 | + - uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + name: legacy-${{ matrix.os }} |
| 143 | + path: dist/fancontroller* |
| 144 | + |
| 145 | + # ---------- ④ 打 tag(v*)自动发 Release ---------- |
| 146 | + release: |
| 147 | + if: startsWith(github.ref, 'refs/tags/v') |
| 148 | + needs: [test-and-build, build-console, build-legacy] |
| 149 | + runs-on: ubuntu-latest |
| 150 | + permissions: |
| 151 | + contents: write # 发 Release 需要 |
| 152 | + steps: |
| 153 | + - uses: actions/download-artifact@v4 |
| 154 | + with: |
| 155 | + path: artifacts |
| 156 | + merge-multiple: true |
| 157 | + |
| 158 | + - name: 创建 Release 并上传全部产物 |
| 159 | + env: |
| 160 | + GH_TOKEN: ${{ github.token }} |
| 161 | + run: | |
| 162 | + ls -l artifacts |
| 163 | + gh release create "$GITHUB_REF_NAME" artifacts/* \ |
| 164 | + --title "gpu-fan-console $GITHUB_REF_NAME" \ |
| 165 | + --generate-notes \ |
| 166 | + || gh release upload "$GITHUB_REF_NAME" artifacts/* --clobber |
0 commit comments