Files
GameServerManager/.github/workflows/build.yml

250 lines
8.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Build Package
# 添加权限配置
permissions:
contents: write
packages: write
actions: read
on:
workflow_dispatch:
inputs:
build_linux:
description: "构建Linux版本"
required: false
type: boolean
default: true
build_windows:
description: "构建Windows版本"
required: false
type: boolean
default: true
build_docker:
description: "构建Docker镜像"
required: false
type: boolean
default: false
build_docker_arm:
description: "构建ARM64 Docker镜像"
required: false
type: boolean
default: false
push:
tags:
- 'v*'
release:
types: [published]
jobs:
resolve_version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
is_stable: ${{ steps.version.outputs.is_stable }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '22.16.0'
- name: Resolve build version
id: version
run: node scripts/resolve-build-version.js
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}
build_linux:
needs: resolve_version
if: github.event.inputs.build_linux == 'true' || github.event_name == 'push' || github.event_name == 'release'
runs-on: ubuntu-latest
strategy:
matrix:
include:
- arch: x64
package_command: npm run package:linux:x64
artifact_name: gsm3-management-panel-linux-x64-build
- arch: arm64
package_command: npm run package:linux:arm64
artifact_name: gsm3-management-panel-linux-arm64-build
steps:
- uses: actions/checkout@v4
- name: Setup Node.js for build
uses: actions/setup-node@v4
with:
node-version: '22.16.0'
cache: 'npm'
- name: Install dependencies
run: |
npm install
cd client && npm install
cd ../server && npm install
- name: Build Linux ${{ matrix.arch }} package
run: ${{ matrix.package_command }}
env:
CI: true
NODE_ENV: production
APP_VERSION: ${{ needs.resolve_version.outputs.version }}
VITE_APP_VERSION: ${{ needs.resolve_version.outputs.version }}
- name: Upload Linux ${{ matrix.arch }} artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: dist/package/
retention-days: 30
build_windows:
needs: resolve_version
if: github.event.inputs.build_windows == 'true' || github.event_name == 'push' || github.event_name == 'release'
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.16.0'
cache: 'npm'
- name: Install dependencies
run: |
npm install
cd client
npm install
cd ..
cd server
npm install
cd ..
- name: Build package
run: npm run package:windows
env:
CI: true
NODE_ENV: production
APP_VERSION: ${{ needs.resolve_version.outputs.version }}
VITE_APP_VERSION: ${{ needs.resolve_version.outputs.version }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: gsm3-management-panel-windows-build
path: dist/package/
retention-days: 30
build_docker:
needs: resolve_version
if: github.event.inputs.build_docker == 'true' || github.event_name == 'push' || github.event_name == 'release'
runs-on: ubuntu-latest
steps:
# 第一步:检出代码
- name: 拉取仓库代码
uses: actions/checkout@v4
# 第二步:设置构建环境
- name: 配置QEMU模拟器
uses: docker/setup-qemu-action@v2
- name: 配置Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
# 第三步:登录所有镜像仓库
- name: 登录Docker仓库
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 第四步:构建并推送多架构镜像(带缓存功能)
- name: 缓存并构建推送DockerHub多架构镜像
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
xiaozhu674/gameservermanager:${{ needs.resolve_version.outputs.version }}
${{ needs.resolve_version.outputs.is_stable == 'true' && 'xiaozhu674/gameservermanager:latest' || '' }}
build-args: |
APP_VERSION=${{ needs.resolve_version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
build_docker_arm:
needs: resolve_version
if: github.event.inputs.build_docker_arm == 'true'
runs-on: ubuntu-latest
steps:
# 第一步:检出代码
- name: 拉取仓库代码
uses: actions/checkout@v4
# 第二步:设置构建环境
- name: 配置QEMU模拟器
uses: docker/setup-qemu-action@v2
- name: 配置Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
# 第三步登录Docker仓库
- name: 登录Docker仓库
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 第四步构建并推送ARM64镜像
- name: 构建并推送ARM64镜像
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/arm64
push: true
tags: |
xiaozhu674/gameservermanager:${{ needs.resolve_version.outputs.version }}-arm64-beta
build-args: |
APP_VERSION=${{ needs.resolve_version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
# 创建发布版本(仅在推送标签时触发)
create_release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [resolve_version, build_linux, build_windows]
runs-on: ubuntu-latest
steps:
- name: Download Linux x64 artifact
uses: actions/download-artifact@v4
with:
name: gsm3-management-panel-linux-x64-build
path: linux-x64-build/
- name: Download Linux arm64 artifact
uses: actions/download-artifact@v4
with:
name: gsm3-management-panel-linux-arm64-build
path: linux-arm64-build/
- name: Download Windows artifact
uses: actions/download-artifact@v4
with:
name: gsm3-management-panel-windows-build
path: windows-build/
- name: Create platform archives
run: |
tar -czf gsm3-management-panel-linux-x64-v${{ needs.resolve_version.outputs.version }}.tar.gz -C linux-x64-build .
tar -czf gsm3-management-panel-linux-arm64-v${{ needs.resolve_version.outputs.version }}.tar.gz -C linux-arm64-build .
cd windows-build
zip -r ../gsm3-management-panel-windows-v${{ needs.resolve_version.outputs.version }}.zip .
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
gsm3-management-panel-linux-x64-v${{ needs.resolve_version.outputs.version }}.tar.gz
gsm3-management-panel-linux-arm64-v${{ needs.resolve_version.outputs.version }}.tar.gz
gsm3-management-panel-windows-v${{ needs.resolve_version.outputs.version }}.zip
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}