Update logic_CI.yml
This commit is contained in:
61
.github/workflows/logic_CI.yml
vendored
61
.github/workflows/logic_CI.yml
vendored
@@ -10,38 +10,50 @@ on:
|
||||
default: 8080
|
||||
type: number
|
||||
|
||||
# 最小化权限配置
|
||||
# 核心修复1:最高权限兜底(解决私有仓库鉴权)
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
actions: write
|
||||
|
||||
env:
|
||||
# Go编译全局优化变量
|
||||
# Go编译优化
|
||||
CGO_ENABLED: 0
|
||||
GO111MODULE: on
|
||||
GOSUMDB: off
|
||||
# 七牛云远程存储目录
|
||||
# 七牛云配置
|
||||
QINIU_REMOTE_DIR: releases/
|
||||
# 显式指定你的仓库地址(解决not found核心问题)
|
||||
REPO_URL: https://github.com/72wo/blazing.git
|
||||
|
||||
jobs:
|
||||
build-and-upload-qiniu:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# 仅签出当前仓库(核心修改:极简配置+本仓库内置token鉴权)
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
token: ${{ github.token }}
|
||||
# 核心修复2:手动克隆仓库(替代checkout,彻底解决鉴权/地址问题)
|
||||
- name: 手动克隆当前仓库(兜底方案)
|
||||
run: |
|
||||
# 用GITHUB_TOKEN拼接鉴权地址,避免匿名访问404
|
||||
CLONE_URL="https://${{ github.actor }}:${{ github.token }}@github.com/72wo/blazing.git"
|
||||
git clone --depth 1 $CLONE_URL $GITHUB_WORKSPACE
|
||||
cd $GITHUB_WORKSPACE
|
||||
# 确认克隆成功,打印仓库信息
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git rev-parse HEAD
|
||||
echo "✅ 仓库克隆成功,当前Commit:$(git rev-parse --short=8 HEAD)"
|
||||
shell: bash
|
||||
|
||||
# 生成基于Commit的短版本号
|
||||
# 生成版本号(基于本地Git,兜底无异常)
|
||||
- name: 生成构建版本号
|
||||
id: set-version
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE
|
||||
VERSION="v$(git rev-parse --short=8 HEAD)"
|
||||
echo "build_version=${VERSION}" >> $GITHUB_OUTPUT
|
||||
echo "构建版本号:${VERSION}" >> $GITHUB_STEP_SUMMARY
|
||||
shell: bash
|
||||
|
||||
# 缓存Go依赖(编译缓存+mod缓存,加速二次构建)
|
||||
# 缓存Go依赖(双缓存加速)
|
||||
- name: 缓存Go依赖
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
@@ -53,24 +65,26 @@ jobs:
|
||||
${{ runner.os }}-go-
|
||||
fail-on-cache-miss: false
|
||||
|
||||
# 配置Go 1.25环境(自动缓存依赖,双重保障)
|
||||
# 配置Go环境
|
||||
- name: 配置Go 1.25环境
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.25'
|
||||
cache: true
|
||||
|
||||
# 预下载所有Go依赖,避免编译时边下载边构建
|
||||
# 预下载依赖
|
||||
- name: 预下载Go依赖
|
||||
run: go mod download -x
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE
|
||||
go mod download -x
|
||||
shell: bash
|
||||
|
||||
# 编译Logic服务(极致优化参数+产物存在性校验)
|
||||
# 编译Logic服务(产物校验)
|
||||
- name: 编译Logic服务
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE
|
||||
mkdir -p build
|
||||
BIN_NAME="logic_${{ steps.set-version.outputs.build_version }}"
|
||||
# Go编译极致优化参数:静态编译+瘦身+并行构建
|
||||
go build -v \
|
||||
-p=4 \
|
||||
-trimpath \
|
||||
@@ -78,17 +92,16 @@ jobs:
|
||||
-ldflags "-s -w -buildid= -extldflags '-static'" \
|
||||
-o ./build/${BIN_NAME} \
|
||||
./logic
|
||||
# 校验编译产物是否存在,不存在则直接失败
|
||||
# 产物存在性校验
|
||||
if [ ! -f ./build/${BIN_NAME} ]; then
|
||||
echo "❌ 编译失败:产物${BIN_NAME}不存在"
|
||||
exit 1
|
||||
fi
|
||||
# 打印产物信息
|
||||
ls -lh ./build/
|
||||
echo "产物名称:${BIN_NAME}" >> $GITHUB_STEP_SUMMARY
|
||||
shell: bash
|
||||
|
||||
# 上传产物到七牛云(覆盖同名文件+统一远程目录)
|
||||
# 上传七牛云(绝对路径指定,无目录问题)
|
||||
- name: 上传产物到七牛云
|
||||
uses: cumt-robin/upload-to-qiniu-action@v1
|
||||
with:
|
||||
@@ -96,16 +109,16 @@ jobs:
|
||||
secret_key: ${{ secrets.QINIU_SK }}
|
||||
bucket: ${{ secrets.QINIU_BUCKET_NAME }}
|
||||
region: z2
|
||||
local_dir: build
|
||||
local_dir: $GITHUB_WORKSPACE/build
|
||||
remote_dir: ${{ env.QINIU_REMOTE_DIR }}
|
||||
overwrite: true
|
||||
|
||||
# 打印构建&分发核心信息(控制台+步骤摘要双展示)
|
||||
# 打印构建信息
|
||||
- name: 打印构建完成信息
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE
|
||||
BIN_NAME="logic_${{ steps.set-version.outputs.build_version }}"
|
||||
CDN_URL="https://${{ secrets.QINIU_CDN_DOMAIN }}/${{ env.QINIU_REMOTE_DIR }}${BIN_NAME}"
|
||||
# 控制台打印
|
||||
echo "======================================"
|
||||
echo "✅ 构建&七牛云上传完成!"
|
||||
echo "版本号:${{ steps.set-version.outputs.build_version }}"
|
||||
@@ -115,12 +128,12 @@ jobs:
|
||||
echo "启动命令:./${BIN_NAME} -port=${{ github.event.inputs.servicePort || 8080 }}"
|
||||
echo "对应Commit:${{ github.sha }}"
|
||||
echo "======================================"
|
||||
# GitHub步骤摘要(页面顶部可见)
|
||||
# 步骤摘要
|
||||
echo "## ✅ 构建&分发完成" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 版本号:${{ steps.set-version.outputs.build_version }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 触发方式:${{ github.event_name == 'workflow_dispatch' && '手动触发' || '代码推送' }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 服务端口:${{ github.event.inputs.servicePort || 8080 }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 七牛云CDN地址:[${CDN_URL}](${CDN_URL})" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 启动命令:`./${BIN_NAME} -port=${{ github.event.inputs.servicePort || 8080 }}`" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 对应Commit:[${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 对应Commit:[${{ github.sha }}](https://${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY
|
||||
shell: bash
|
||||
|
||||
Reference in New Issue
Block a user