Files
bl/.github/workflows/logic_CI.yml
2026-01-27 07:00:35 +00:00

122 lines
4.7 KiB
Go
Raw Permalink 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: Go Build & Release
on:
# push:
# branches: [main]
workflow_dispatch:
inputs:
servicePort:
description: '服务启动端口'
required: true
default: 8080
type: number
# 仅保留必要权限和你最初一致
permissions:
contents: read
actions: read
env:
# 完全还原你最初的环境变量
CGO_ENABLED: 0
GO111MODULE: on
GOSUMDB: off
QINIU_REMOTE_DIR: releases/
jobs:
build-and-upload-qiniu:
runs-on: ubuntu-latest
steps:
# 修复checkout还原你最初的极简配置+补全鉴权无任何多余配置
- uses: actions/checkout@v4
with:
fetch-depth: 1 # 和你最初一致仅拉取最新提交
token: ${{ github.token }} # 仅加这一行鉴权解决私有仓库克隆
# 生成版本号完全还原你最初的逻辑无cd无绝对路径
- name: 生成构建版本号
id: set-version
run: |
VERSION="v$(git rev-parse --short=8 HEAD)"
echo "build_version=${VERSION}" >> $GITHUB_OUTPUT
echo "构建版本号:${VERSION}" >> $GITHUB_STEP_SUMMARY
shell: bash
# 缓存Go依赖完全和你最初一致
- name: 缓存Go依赖
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod', '**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
fail-on-cache-miss: false
# 配置Go环境完全和你最初一致
- name: 配置Go 1.25环境
uses: actions/setup-go@v5
with:
go-version: '1.25'
cache: true
# 预下载依赖完全和你最初一致无cd
- name: 预下载Go依赖
run: go mod download -x
shell: bash
# 编译服务完全还原你最初的逻辑相对路径build无任何绝对路径
- name: 编译Logic服务
run: |
mkdir -p build
BIN_NAME="logic_${{ steps.set-version.outputs.build_version }}"
go build -v \
-p=4 \
-trimpath \
-buildvcs=false \
-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
# 核心修复七牛云上传改回你最初的相对路径build删除所有$GITHUB_WORKSPACE
- 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: ${{ env.QINIU_REMOTE_DIR }}
overwrite: true
# 打印信息完全还原你最初的逻辑无cd无绝对路径
- name: 打印构建完成信息
run: |
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 }}"
echo "触发方式:${{ github.event_name == 'workflow_dispatch' && '手动触发' || '代码推送' }}"
echo "服务端口:${{ github.event.inputs.servicePort || 8080 }}"
echo "七牛云CDN地址${CDN_URL}"
echo "启动命令:./${BIN_NAME} -port=${{ github.event.inputs.servicePort || 8080 }}"
echo "对应Commit${{ github.sha }}"
echo "======================================"
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
shell: bash