diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b263e4a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,142 @@ +name: 构建多平台程序 (Go Server & Electron Client) + +on: + push: + branches: + - main + +jobs: + # 1. 构建 Go 服务端 + build-server: + name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }}) + runs-on: ubuntu-latest + strategy: + matrix: + include: + - goos: windows + goarch: amd64 + executable: ogame-server-win.exe + - goos: linux + goarch: amd64 + executable: ogame-server-linux + - goos: linux + goarch: arm64 + executable: ogame-server-linux-arm64 + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + with: + version: 8 + - name: Setup Node & Go + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + - uses: actions/setup-go@v5 + with: + go-version: '1.25' + + - name: Build Frontend & Server + run: | + pnpm install + pnpm run build + go mod tidy + GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go + + - name: Upload Server Binaries + uses: actions/upload-artifact@v4 + with: + name: server-${{ matrix.goos }}-${{ matrix.goarch }} + path: ${{ matrix.executable }} + + # 2. 构建 Electron 客户端 + build-electron: + name: Build Electron (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + platform: win + - os: macos-latest + platform: mac + - os: ubuntu-latest + platform: linux + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + with: + version: 8 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + + - name: Build Electron + run: | + pnpm install + pnpm run build + pnpm run build:electron --${{ matrix.platform }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # 【关键点】这里只上传安装包后缀,不上传文件夹 + - name: Upload Electron Installers + uses: actions/upload-artifact@v4 + with: + name: electron-${{ matrix.platform }} + path: | + pkg/*.exe + pkg/*.dmg + pkg/*.AppImage + + # 3. 发布 Release + release: + needs: [ build-server, build-electron ] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Get Version + id: get_version + run: echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + # 1. 下载时,不使用 merge-multiple,防止覆盖冲突 + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + path: ./raw-assets + + # 2. 核心步骤:手动移动文件到一个扁平目录,并强制重命名 + - name: Flatten and Rename Assets + run: | + mkdir -p ./final-release + + # 移动 Server 文件并确保名字唯一 + # 注意:根据你之前的附件,Artifact 名字是 server-windows-amd64 + cp ./raw-assets/server-windows-amd64/ogame-server-win.exe ./final-release/ogame-server-win.exe || cp ./raw-assets/server-windows-amd64/server-windows-amd64.exe ./final-release/ogame-server-win.exe || true + cp ./raw-assets/server-linux-amd64/ogame-server-linux ./final-release/ogame-server-linux || true + cp ./raw-assets/server-linux-arm64/ogame-server-linux-arm64 ./final-release/ogame-server-linux-arm64 || true + + # 移动 Electron 安装包 (排除 unpacked 目录) + find ./raw-assets/electron-* -type f \( -name "*.exe" -o -name "*.dmg" -o -name "*.AppImage" -o -name "*.zip" \) -exec cp {} ./final-release/ \; + + # 检查结果 + echo "Final assets to upload:" + ls -R ./final-release + + # 3. 一次性上传,禁止重复匹配 + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.get_version.outputs.VERSION }} + name: Release ${{ steps.get_version.outputs.VERSION }} + # 重点:只上传这个干净目录下的所有文件,不要再写具体的通配符防止重复 + files: ./final-release/* + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/ogame-vue-ts.yml b/.github/workflows/ogame-vue-ts.yml index 0b1876b..3aa3a4e 100644 --- a/.github/workflows/ogame-vue-ts.yml +++ b/.github/workflows/ogame-vue-ts.yml @@ -1,105 +1,59 @@ -name: 自动化创建Docker镜像 +name: Docker 多架构构建并发布 on: push: - branches: - - main + branches: [ main ] + tags: [ 'v*.*.*' ] # 打 tag 时也触发 + workflow_dispatch: + +permissions: + contents: read + packages: write jobs: - build-amd64: + build-and-push: runs-on: ubuntu-latest - permissions: - contents: read - packages: write steps: - - name: 检查代码 - uses: actions/checkout@v2 + - name: 检出代码 + uses: actions/checkout@v4 + with: + fetch-depth: 0 + # QEMU 用于支持多架构构建(必须) + - name: 设置 QEMU + uses: docker/setup-qemu-action@v3 + + # Buildx 是目前官方唯一推荐的多架构构建方式 + - name: 设置 Docker Buildx + uses: docker/setup-buildx-action@v3 + + # 登录 GHCR(始终执行) - name: 登录 GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} + password: ${{ secrets.GITHUB_TOKEN }} + # 登录 Docker Hub(只在用户名存在时执行) - name: 登录 Docker Hub - uses: docker/login-action@v2 + if: vars.DOCKERHUB_USERNAME != '' # 只检查 vars,忽略 secrets + uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} + username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: 构建并推送 amd64 Docker镜像 - uses: docker/build-push-action@v3 + # 真正一键构建 + 推送多架构镜像(amd64 + arm64) + - name: 构建并推送多架构镜像 + uses: docker/build-push-action@v6 with: context: . - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64 push: true tags: | - ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:amd64 - ${{ secrets.DOCKERHUB_USERNAME }}/ogame-vue-ts:amd64 - - build-arm64: - runs-on: ubuntu-22.04-arm - permissions: - contents: read - packages: write - steps: - - name: 检查代码 - uses: actions/checkout@v2 - - - name: 登录 GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} - - - name: 登录 Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: 构建并推送 arm64 Docker镜像 - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/arm64 - push: true - tags: | - ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:arm64 - ${{ secrets.DOCKERHUB_USERNAME }}/ogame-vue-ts:arm64 - - create-manifest: - needs: [build-amd64, build-arm64] - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: 登录 GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} - - - name: 登录 Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: 创建并推送多架构清单 - run: | - # GitHub Container Registry - docker manifest create ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:latest \ - ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:amd64 \ - ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:arm64 - docker manifest push ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:latest - - # Docker Hub - docker manifest create ${{ secrets.DOCKERHUB_USERNAME }}/ogame-vue-ts:latest \ - ${{ secrets.DOCKERHUB_USERNAME }}/ogame-vue-ts:amd64 \ - ${{ secrets.DOCKERHUB_USERNAME }}/ogame-vue-ts:arm64 - docker manifest push ${{ secrets.DOCKERHUB_USERNAME }}/ogame-vue-ts:latest \ No newline at end of file + ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:latest + ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:${{ github.sha }} + ${{ vars.DOCKERHUB_USERNAME != '' && format('docker.io/{0}/ogame-vue-ts:latest', vars.DOCKERHUB_USERNAME) || '' }} + ${{ vars.DOCKERHUB_USERNAME != '' && format('docker.io/{0}/ogame-vue-ts:{1}', vars.DOCKERHUB_USERNAME, github.sha) || '' }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.gitignore b/.gitignore index 73f996e..2b72b2c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ node_modules dist dist-ssr *.local +docs # Editor directories and files .claude/* diff --git a/Dockerfile b/Dockerfile index 6ec9e2a..b26bde7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,21 @@ -FROM node:latest +FROM node:latest AS builder RUN mkdir -p /workspace - WORKDIR /workspace - RUN npm config set registry https://registry.npmmirror.com - -RUN cd /workspace - RUN git clone https://github.com/setube/ogame-vue-ts.git - RUN mv ./ogame-vue-ts/* . ; rm -rf ./ogame-vue-ts/ -RUN npm install -g pnpm ; pnpm install ; npx vite build +RUN npm install -g pnpm ; pnpm install; +RUN pnpm build -CMD ["npx", "vite", "preview", "--host", "0.0.0.0", "--port", "25121"] \ No newline at end of file +# --- 第二阶段:Nginx --- +FROM nginx:alpine + +COPY nginx.conf /etc/nginx/conf.d/default.conf + +RUN rm -rf /usr/share/nginx/html/* +COPY --from=builder /workspace/docs /usr/share/nginx/html + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/README-EN.md b/README-EN.md index cf56e8b..64cb53b 100644 --- a/README-EN.md +++ b/README-EN.md @@ -9,6 +9,8 @@ [](https://vuejs.org/) [](https://www.typescriptlang.org/) [](https://vitejs.dev/) + [](https://golang.org/) + [简体中文](README.md) | English @@ -36,7 +38,7 @@ OGame Vue TS is a single-player, browser-based space strategy game inspired by t - **Frontend Framework:** [Vue 3](https://vuejs.org/) with Composition API (` - - - - - - - - - - - - - - - - -
- - - - - - -