mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
- 移除手动触发工作流配置 - 从 package.json 动态读取应用版本号 - 更新资源打包路径为 dist 目录 - 实现跨平台压缩命令统一处理 - 自动传递版本号至 Release 任务 - 启用自动生成 Release Notes 功能 - 确保构建产物正确上传与归档
96 lines
2.8 KiB
YAML
96 lines
2.8 KiB
YAML
name: 构建多平台可执行程序
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main # 监听 main 分支的推送,不再强制要求手动推送 Tag
|
|
|
|
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
|
|
|
|
# --- 关键步骤:读取 package.json 的版本号 ---
|
|
- name: Get version from package.json
|
|
id: get_version
|
|
shell: bash
|
|
run: |
|
|
VERSION=$(node -p "require('./package.json').version")
|
|
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
|
|
echo "Detected version: v$VERSION"
|
|
|
|
- name: Install Dependencies
|
|
run: bun install
|
|
|
|
- name: Build Vue Frontend
|
|
run: bun run build
|
|
|
|
- name: Compile Executable
|
|
run: bun build ./server.js --compile --outfile ${{ matrix.executable }}
|
|
|
|
- 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/
|
|
|
|
- name: Upload Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ matrix.artifact_name }}
|
|
path: ${{ matrix.asset_name }}
|
|
|
|
# 将版本号传递给 release 任务
|
|
outputs:
|
|
app_version: ${{ steps.get_version.outputs.VERSION }}
|
|
|
|
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:
|
|
# 使用从 build 任务传递过来的版本号
|
|
tag_name: ${{ needs.build.outputs.app_version }}
|
|
name: Release ${{ needs.build.outputs.app_version }}
|
|
draft: false
|
|
prerelease: false
|
|
# 自动创建 Tag (非常重要)
|
|
generate_release_notes: true
|
|
files: |
|
|
ogame-windows/ogame-windows.zip
|
|
ogame-linux/ogame-linux.tar.gz
|
|
ogame-macos/ogame-macos.tar.gz
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |