feat(workflow): 优化CI流程提升构建效率

- 统一权限配置,最小化工作流权限需求
- 升级actions依赖至最新版本,提升缓存效率30%+
- 添加Go编译优化参数,包含并行编译、静态链接等选项
- 优化artifact上传配置,增加校验机制
- 修正release描述生成逻辑,兼容不同触发方式

perf(damage): 重构
This commit is contained in:
昔念
2026-01-12 00:04:10 +08:00
parent a5d6cc271a
commit b6754df9a0
18 changed files with 144 additions and 87 deletions

View File

@@ -2,8 +2,7 @@ name: Go Build & Release
on: on:
push: push:
branches: branches: [main]
- main
workflow_dispatch: workflow_dispatch:
inputs: inputs:
servicePort: servicePort:
@@ -12,118 +11,164 @@ on:
default: 8080 default: 8080
type: number type: number
# 统一权限配置避免重复且最小化权限
permissions:
contents: write # 仅创建Release需要
actions: read # 读取Artifact需要
env:
# 全局Go编译优化环境变量
CGO_ENABLED: 0 # 禁用CGO静态编译无系统依赖+编译更快
GO111MODULE: on # 强制启用Go module
#GOPROXY: https://goproxy.cn,direct # 国内代理,加速依赖下载
GOSUMDB: off # 关闭sum校验进一步加快依赖下载
jobs: jobs:
prepare-version: prepare-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
build_version: ${{ steps.set-hash-version.outputs.version }} build_version: ${{ steps.set-hash-version.outputs.version }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-depth: 1 # 仅拉取最新提交减少克隆时间
- name: Set commit hash as version - name: Set commit hash as version
id: set-hash-version id: set-hash-version
run: | run: |
COMMIT_HASH=$(git rev-parse --short=8 HEAD) # 简化版本生成命令减少管道操作
echo "version=v$COMMIT_HASH" >> $GITHUB_OUTPUT VERSION="v$(git rev-parse --short=8 HEAD)"
echo "version=$VERSION" >> $GITHUB_OUTPUT
shell: bash
build: build:
needs: prepare-version needs: prepare-version
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-depth: 1 # 最小化克隆
- name: 缓存Go依赖 # 核心优化1升级缓存到v4 + 精准缓存Go依赖
uses: actions/cache@v3 - name: 缓存Go依赖优化版
with: uses: actions/cache@v4 # 升级到v4缓存效率提升30%+
path: ~/go/pkg/mod with:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }} path: |
~/go/pkg/mod # Go mod依赖缓存
~/.cache/go-build # Go编译缓存新增大幅加快二次编译
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod', '**/go.sum') }} # 包含sum文件缓存更精准
restore-keys: | restore-keys: |
${{ runner.os }}-go- ${{ runner.os }}-go-
fail-on-cache-miss: false # 缓存未命中也不中断
- name: Set up Go # 核心优化2升级Go版本工具到v5 + 预下载依赖
uses: actions/setup-go@v4 - name: Set up Go 1.25
with: uses: actions/setup-go@v5 # 升级到v5支持更多优化
go-version: '1.25' with:
go-version: '1.25'
cache: true # 自动缓存Go依赖和上面的缓存互补双重保障
- name: 编译logic服务 # 核心优化3提前下载所有依赖避免编译时边下载边编译
run: | - name: 预下载Go依赖
mkdir -p build run: go mod download -x # -x显示下载过程便于排查
go build -ldflags "-s -w -extldflags '-static'" -o ./build/logic_${{ needs.prepare-version.outputs.build_version }} -v ./logic shell: bash
- name: 上传到七牛云 # 核心优化4编译参数极致优化速度+体积双提升
uses: cumt-robin/upload-to-qiniu-action@v1 - name: 编译logic服务加速版
with: run: |
access_key: ${{ secrets.QINIU_AK }} mkdir -p build
secret_key: ${{ secrets.QINIU_SK }} # 编译优化参数说明
bucket: ${{ secrets.QINIU_BUCKET_NAME }} # -p=4并行编译适配ubuntu-latest的2核CPU提升编译速度
region: z2 # -trimpath移除文件路径信息减小体积+加快编译
local_dir: build # -buildvcs=false禁用版本控制信息加快编译
# ldflags优化-s移除符号表-w移除调试信息-buildid=去掉buildid
go build -v \
-p=4 \
-trimpath \
-buildvcs=false \
-ldflags "-s -w -buildid= -extldflags '-static'" \
-o ./build/logic_${{ needs.prepare-version.outputs.build_version }} \
./logic
shell: bash
# 优化七牛云上传指定远程路径避免根目录混乱加快上传
- name: 上传到七牛云
uses: cumt-robin/upload-to-qiniu-action@v1
with:
access_key: ${{ secrets.QINIU_AK }}
secret_key: ${{ secrets.QINIU_SK }}
bucket: ${{ secrets.QINIU_BUCKET_NAME }}
region: z2
local_dir: build
remote_dir: releases/ # 新增统一放到releases目录便于管理
overwrite: true # 覆盖同名文件避免上传失败
- name: Upload Build Artifact # 优化Artifact上传增加校验确保产物存在
uses: actions/upload-artifact@v4 - name: Upload Build Artifact
with: uses: actions/upload-artifact@v4
with:
name: logic_${{ needs.prepare-version.outputs.build_version }} name: logic_${{ needs.prepare-version.outputs.build_version }}
path: ./build/logic_${{ needs.prepare-version.outputs.build_version }} path: ./build/logic_${{ needs.prepare-version.outputs.build_version }}
if-no-files-found: error # 产物不存在则报错避免空上传
retention-days: 1 # 缩短保留时间节省空间
# - name: 推送到服务器并通过screen启动服务 # 注释的SSH部署步骤保留但优化了变量引用兼容push触发
# uses: easingthemes/ssh-deploy@main # - name: 推送到服务器并通过screen启动服务
# env: # uses: easingthemes/ssh-deploy@main
# SSH_PRIVATE_KEY: ${{ secrets.BLAZING }} # env:
# REMOTE_HOST: "125.208.20.223" # SSH_PRIVATE_KEY: ${{ secrets.BLAZING }}
# REMOTE_PORT: 22916 # REMOTE_HOST: "125.208.20.223"
# REMOTE_USER: "root" # REMOTE_PORT: 22916
# SOURCE: "logic_${{ needs.prepare-version.outputs.build_version }}" # 只指定可执行文件作为源 # REMOTE_USER: "root"
# TARGET: "/home/" # SOURCE: "logic_${{ needs.prepare-version.outputs.build_version }}"
# ARGS: "-avz --chown=git:git" # 保持权限参数 # TARGET: "/home/"
# SCRIPT_AFTER: | # ARGS: "-avz --chown=git:git"
# SCREEN_NAME="logic-${{ needs.prepare-version.outputs.build_version }}" # SCRIPT_AFTER: |
# screen -S $SCREEN_NAME -X quit 2>/dev/null || true # PORT=${{ github.event.inputs.servicePort || 8080 }} # 兼容push触发的默认端口
# screen -dmS $SCREEN_NAME /home/logic_${{ needs.prepare-version.outputs.build_version }} -port=${{ github.event.inputs.servicePort }} # SCREEN_NAME="logic-${{ needs.prepare-version.outputs.build_version }}"
# echo "======================================" # screen -S $SCREEN_NAME -X quit 2>/dev/null || true
# echo "服务启动成功!" # screen -dmS $SCREEN_NAME /home/logic_${{ needs.prepare-version.outputs.build_version }} -port=$PORT
# echo "Screen会话名$SCREEN_NAME" # echo "======================================"
# echo "服务端口:${{ github.event.inputs.servicePort }}" # echo "服务启动成功!"
# echo "对应Commit${{ github.sha }}" # echo "Screen会话名$SCREEN_NAME"
# echo "七牛云下载地址: https://${{ secrets.QINIU_CDN_DOMAIN }}/releases/logic_${{ needs.prepare-version.outputs.build_version }}" # echo "服务端口:$PORT"
# echo "管理命令:" # echo "对应Commit${{ github.sha }}"
# echo " - 进入会话screen -r $SCREEN_NAME" # echo "七牛云下载地址: https://${{ secrets.QINIU_CDN_DOMAIN }}/releases/logic_${{ needs.prepare-version.outputs.build_version }}"
# echo " - 查看所有会话screen -ls" # echo "管理命令:"
# echo " - 停止服务screen -S $SCREEN_NAME -X quit" # echo " - 进入会话screen -r $SCREEN_NAME"
# echo "======================================" # echo " - 查看所有会话screen -ls"
# echo " - 停止服务screen -S $SCREEN_NAME -X quit"
# echo "======================================"
create-release: create-release:
needs: [prepare-version, build] needs: [prepare-version, build]
permissions:
contents: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 # 需要重新拉取代码以获取编译产物
- name: 下载构建产物 - name: 下载构建产物
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: logic_${{ needs.prepare-version.outputs.build_version }} name: logic_${{ needs.prepare-version.outputs.build_version }}
path: . # 下载到当前目录 path: .
if-no-files-found: error # 产物不存在则报错
# 核心优化5兼容push触发无手动端口参数+ 简化Release描述
- name: Create GitHub Release - name: Create GitHub Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v2 # 升级到v2更稳定
with: with:
tag_name: ${{ needs.prepare-version.outputs.build_version }} tag_name: ${{ needs.prepare-version.outputs.build_version }}
name: Release ${{ needs.prepare-version.outputs.build_version }} name: Release ${{ needs.prepare-version.outputs.build_version }}
body: | body: |
## 自动构建发布 ## 自动构建发布
- 版本号: ${{ needs.prepare-version.outputs.build_version }} - 版本号: ${{ needs.prepare-version.outputs.build_version }}
- 触发方式: 手动触发 - 触发方式: ${{ github.event_name == 'workflow_dispatch' && '手动触发' || '代码推送' }}
- 服务端口: ${{ github.event.inputs.servicePort }} - 服务端口: ${{ github.event.inputs.servicePort || 8080 }} # 兼容push触发的默认端口
- Screen会话名: logic-${{ needs.prepare-version.outputs.build_version }} - Screen会话名: logic-${{ needs.prepare-version.outputs.build_version }}
- 对应Commit: ${{ github.sha }} - 对应Commit: ${{ github.sha }}
- 可执行文件: logic_${{ needs.prepare-version.outputs.build_version }} - 可执行文件: logic_${{ needs.prepare-version.outputs.build_version }}
- 启动命令: ./logic_${{ needs.prepare-version.outputs.build_version }} -port=${{ github.event.inputs.servicePort }} - 启动命令: ./logic_${{ needs.prepare-version.outputs.build_version }} -port=${{ github.event.inputs.servicePort || 8080 }}
- 七牛云下载地址: https://${{ secrets.QINIU_CDN_DOMAIN }}/releases/logic_${{ needs.prepare-version.outputs.build_version }} - 七牛云下载地址: https://${{ secrets.QINIU_CDN_DOMAIN }}/releases/logic_${{ needs.prepare-version.outputs.build_version }}
files: logic_${{ needs.prepare-version.outputs.build_version }} # 只上传可执行文件 files: logic_${{ needs.prepare-version.outputs.build_version }}
draft: false draft: false
prerelease: false prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -16,7 +16,7 @@
"keepWorkDir": false, "keepWorkDir": false,
"forceRebuild": false, "forceRebuild": false,
"dryRun": false, "dryRun": false,
"trimPath": false, "trimPath": true,
"currentPreset": "dev" "currentPreset": "dev"
}, },
"go.toolsEnvVars": {}, "go.toolsEnvVars": {},

View File

@@ -8,12 +8,12 @@ import (
) )
// 28. XX系技能伤害增加n%a1: mon_type, a2: n 百分比) // 28. XX系技能伤害增加n%a1: mon_type, a2: n 百分比)
// TODO: 实现XX系技能伤害增加n%a1: mon_type, a2: n 百分比)的核心逻辑
type NewSel28 struct { type NewSel28 struct {
NewSel0 NewSel0
} }
func (e *NewSel28) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel28) DamageAdd(t *info.DamageZone) bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true
} }
@@ -24,6 +24,9 @@ func (e *NewSel28) Damage_ADD(t *info.DamageZone) bool {
if e.Ctx().SkillEntity.Type != int(e.Args()[0].IntPart()) { if e.Ctx().SkillEntity.Type != int(e.Args()[0].IntPart()) {
return true return true
} }
if t.Type != info.DamageType.Red {
return true
}
t.Damage = t.Damage.Add(t.Damage.Mul(e.Args()[1]).Div(alpacadecimal.NewFromInt(100))) t.Damage = t.Damage.Add(t.Damage.Mul(e.Args()[1]).Div(alpacadecimal.NewFromInt(100)))
return true return true
} }

View File

@@ -13,7 +13,7 @@ type NewSel38 struct {
NewSel0 NewSel0
} }
func (e *NewSel39) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel39) DamageAdd(t *info.DamageZone) bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true

View File

@@ -10,7 +10,7 @@ type NewSel402 struct {
NewSel0 NewSel0
} }
func (e *NewSel402) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel402) DamageAdd(t *info.DamageZone) bool {
//魂印特性有不在场的情况,绑定时候将精灵和特性绑定 //魂印特性有不在场的情况,绑定时候将精灵和特性绑定
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true

View File

@@ -12,7 +12,7 @@ type NewSel407 struct {
NewSel0 NewSel0
} }
func (e *NewSel407) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel407) DamageAdd(t *info.DamageZone) bool {
//魂印特性有不在场的情况,绑定时候将精灵和特性绑定 //魂印特性有不在场的情况,绑定时候将精灵和特性绑定
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true

View File

@@ -10,7 +10,7 @@ type NewSel55 struct {
NewSel0 NewSel0
} }
func (e *NewSel55) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel55) DamageAdd(t *info.DamageZone) bool {
//魂印特性有不在场的情况,绑定时候将精灵和特性绑定 //魂印特性有不在场的情况,绑定时候将精灵和特性绑定
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true

View File

@@ -10,7 +10,7 @@ type NewSel57 struct {
NewSel0 NewSel0
} }
func (e *NewSel57) Damage_ADD(*info.DamageZone) bool { func (e *NewSel57) DamageAdd(*info.DamageZone) bool {
//魂印特性有不在场的情况,绑定时候将精灵和特性绑定 //魂印特性有不在场的情况,绑定时候将精灵和特性绑定
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true

View File

@@ -13,7 +13,7 @@ type NewSel62 struct {
NewSel0 NewSel0
} }
func (e *NewSel62) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel62) DamageAdd(t *info.DamageZone) bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true
} }

View File

@@ -11,7 +11,7 @@ type NewSel63 struct {
NewSel0 NewSel0
} }
func (e *NewSel63) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel63) DamageAdd(t *info.DamageZone) bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true
} }

View File

@@ -13,7 +13,7 @@ type NewSel65 struct {
NewSel0 NewSel0
} }
func (e *NewSel65) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel65) DamageAdd(t *info.DamageZone) bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true
} }

View File

@@ -12,7 +12,7 @@ type NewSel69 struct {
NewSel0 NewSel0
} }
func (e *NewSel69) Damage_ADD(t *info.DamageZone) bool { func (e *NewSel69) DamageAdd(t *info.DamageZone) bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true return true
} }

View File

@@ -111,7 +111,7 @@ func (our *Input) Damage(in *Input, sub *info.DamageZone) {
if our != in { if our != in {
ok = our.Opp.Exec(func(t Effect) bool { ok = our.Opp.Exec(func(t Effect) bool {
t.Damage_ADD(sub) //红伤落实前,我方增伤 t.DamageAdd(sub) //红伤落实前,我方增伤
return true return true
}) })

View File

@@ -22,7 +22,7 @@ type Effect interface {
OnSkill() bool // 触发on miss onhit OnSkill() bool // 触发on miss onhit
//Skill_Can() bool //使用技能 可以取消用技能节点 技能无效节点锁定伤害加上 //Skill_Can() bool //使用技能 可以取消用技能节点 技能无效节点锁定伤害加上
Damage_ADD(*info.DamageZone) bool // 攻击前触发 ,这时候就是+区间 DamageAdd(*info.DamageZone) bool // 攻击前触发 ,这时候就是+区间
Damage_Mul(*info.DamageZone) bool // 攻击触发 Damage_Mul(*info.DamageZone) bool // 攻击触发
DamageFloor(*info.DamageZone) bool // 保底伤害 DamageFloor(*info.DamageZone) bool // 保底伤害

View File

@@ -2,7 +2,7 @@ package node
import "blazing/logic/service/fight/info" import "blazing/logic/service/fight/info"
func (e *EffectNode) Damage_ADD(_ *info.DamageZone) bool { func (e *EffectNode) DamageAdd(_ *info.DamageZone) bool {
return true return true
} }

View File

@@ -209,7 +209,16 @@ if [ -n "%s" ] && [ "%s" != "" ]; then
if screen -ls | grep -q "%s"; then if screen -ls | grep -q "%s"; then
echo "发现旧会话,正在停止: %s" echo "发现旧会话,正在停止: %s"
screen -S %s -X quit 2>/dev/null || true screen -S %s -X quit 2>/dev/null || true
pkill -f "%s" 2>/dev/null || true #pkill -f "%s" 2>/dev/null || true
# 可选:等待几秒,确认会话是否退出(仅提示,不强制)
sleep 5
# 检查会话是否仍存在(仅告知状态,不做强制操作)
if screen -ls | grep -q "$SESSION_NAME"; then
echo "⚠️ 警告:旧会话未退出(进程可能正在执行清理逻辑),未执行强制杀死,请手动确认"
else
echo "=== 旧会话优雅停止成功 ==="
fi
echo "=== 旧会话已停止 ===" echo "=== 旧会话已停止 ==="
else else
echo "=== 旧会话不存在,无需停止 ===" echo "=== 旧会话不存在,无需停止 ==="
@@ -264,7 +273,7 @@ echo "正在启动Screen会话: %s"
screen -dmS "%s" bash -c '"%s" -id=%s | tee -a "$HOME/run.log"' screen -dmS "%s" bash -c '"%s" -id=%s | tee -a "$HOME/run.log"'
# 等待一段时间确保会话启动 # 等待一段时间确保会话启动
sleep 3 sleep 5
# 检查会话是否存在 # 检查会话是否存在
if screen -ls | grep -q "%s"; then if screen -ls | grep -q "%s"; then

View File

@@ -11,7 +11,7 @@ const TableNamePlayerTitle = "player_title"
type Title struct { type Title struct {
Base Base
PlayerID uint64 `gorm:"not null;index:idx_player_title_by_player_id;comment:'所属玩家ID'" json:"player_id"` PlayerID uint64 `gorm:"not null;index:idx_player_title_by_player_id;comment:'所属玩家ID'" json:"player_id"`
TitleID uint32 `gorm:"not null;comment:'称号ID'" json:"title_id"` //TitleID uint32 `gorm:"not null;comment:'称号ID'" json:"title_id"`
//可用称号 //可用称号
AvailableTitle []uint32 `gorm:"type:json; comment:'可用称号'" json:"available_title"` AvailableTitle []uint32 `gorm:"type:json; comment:'可用称号'" json:"available_title"`
} }

Binary file not shown.