mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
ci(workflow): 添加多平台构建与发布工作流
- 新增 GitHub Actions 工作流文件 - 支持 Windows、Linux 和 macOS 平台构建 - 配置 Bun 环境并安装依赖 - 构建 Vue 前端资源 - 编译后端为可执行文件 - 打包静态资源与可执行程序 - 上传构建产物并创建 GitHub Release
This commit is contained in:
82
.github/workflows/build.yml
vendored
Normal file
82
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
name: 构建多平台可执行程序
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
tags:
|
||||||
|
- 'v*' # 当推送 v1.0.0 等标签时触发
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build for ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: windows-latest
|
||||||
|
artifact_name: ogame-windows
|
||||||
|
asset_name: ogame-windows.zip
|
||||||
|
executable: ogame.exe
|
||||||
|
- os: ubuntu-latest
|
||||||
|
artifact_name: ogame-linux
|
||||||
|
asset_name: ogame-linux.tar.gz
|
||||||
|
executable: ogame
|
||||||
|
- os: macos-latest
|
||||||
|
artifact_name: ogame-macos
|
||||||
|
asset_name: ogame-macos.tar.gz
|
||||||
|
executable: ogame
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: latest
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: bun install
|
||||||
|
|
||||||
|
# 1. Vue 构建流程
|
||||||
|
- name: Build Vue Frontend
|
||||||
|
run: bun run build # 假设你的 package.json 中 build 命令是 vite build 或 vue-cli-service build
|
||||||
|
|
||||||
|
# 2. Bun 编译后端
|
||||||
|
- name: Compile Executable
|
||||||
|
run: bun build ./server.js --compile --outfile ${{ matrix.executable }}
|
||||||
|
|
||||||
|
# 3. 打包静态资源与可执行程序 (关键步骤)
|
||||||
|
- name: Package Assets (Windows)
|
||||||
|
if: matrix.os == 'windows-latest'
|
||||||
|
run: Compress-Archive -Path "${{ matrix.executable }}", "dist" -DestinationPath "${{ matrix.asset_name }}"
|
||||||
|
|
||||||
|
- name: Package Assets (Linux/macOS)
|
||||||
|
if: matrix.os != 'windows-latest'
|
||||||
|
run: tar -czvf ${{ matrix.asset_name }} ${{ matrix.executable }} dist/
|
||||||
|
|
||||||
|
# 4. 上传到构建产物 (用于下一步 Release)
|
||||||
|
- name: Upload Artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ matrix.artifact_name }}
|
||||||
|
path: ${{ matrix.asset_name }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Download all artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
|
||||||
|
- name: Create GitHub Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
ogame-windows/ogame-windows.zip
|
||||||
|
ogame-linux/ogame-linux.tar.gz
|
||||||
|
ogame-macos/ogame-macos.tar.gz
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
44
server.js
Normal file
44
server.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const path = require('path');
|
||||||
|
const open = require('open'); // 需要安装: npm install open express
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const HOST = '0.0.0.0';
|
||||||
|
|
||||||
|
app.set('trust proxy', true);
|
||||||
|
// 指向 Vue 构建后的 dist 目录
|
||||||
|
app.use(express.static(path.join(process.cwd(), 'dist')));
|
||||||
|
|
||||||
|
const getLocalIp = () => {
|
||||||
|
const interfaces = os.networkInterfaces();
|
||||||
|
for (let devName in interfaces) {
|
||||||
|
let face = interfaces[devName];
|
||||||
|
for (let i = 0; i < face.length; i++) {
|
||||||
|
let alias = face[i];
|
||||||
|
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
|
||||||
|
return alias.address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'localhost';
|
||||||
|
}
|
||||||
|
const server = app.listen(0, HOST, async () => {
|
||||||
|
const { port } = server.address();
|
||||||
|
|
||||||
|
const url = `http://localhost:${port}`;
|
||||||
|
|
||||||
|
console.log('-----------------------------------');
|
||||||
|
console.log(`🚀 服务器已成功启动!`);
|
||||||
|
console.log(`🔗 本地地址: ${url}`);
|
||||||
|
console.log(`🌐 默认允许局域网访问:http://${getLocalIp()}:${port}`);
|
||||||
|
console.log('-----------------------------------');
|
||||||
|
console.log('提示: 关闭此控制台窗口将停止服务。');
|
||||||
|
|
||||||
|
// 3. 自动打开浏览器
|
||||||
|
try {
|
||||||
|
await open(url);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('无法自动打开浏览器:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user