refactor(.woodpecker): 优化工作流配置简化CI/CD流程

- 移除默认代码克隆配置,改用skip_clone: true
- 将prepare步骤改为手动git clone方式,支持SSH密钥认证
- 简化Go环境准备流程,移除依赖缓存步骤
- 调整步骤命名规范,统一使用驼峰命名
- 更新依赖关系引用,修正build_logic依赖名称
```
This commit is contained in:
昔念
2026-01-27 00:44:48 +08:00
parent a194d912b5
commit 2920f8dcc2

View File

@@ -1,20 +1,10 @@
# 触发条件仅pushmanual手动触发分支限定main
when:
event:
- push
- manual
- event: push
- event: manual
branch: main
# 代码克隆配置保留SSH拉取+标签/LFS支持
clone:
git:
image: woodpeckerci/plugin-git
settings:
use-ssh: true
ssh-key-private:
from_secret: WOODPECKER_SSH_KEY
tags: true # 支持标签拉取适配版本号生成不用可删
lfs: true # 支持LFS项目无LFS可删
skip_clone: true
# 全局配置变量替换占位符即可使用
variables:
@@ -25,27 +15,30 @@ variables:
# 流水线核心步骤仅保留编译+部署流程
steps:
# 1. Go依赖缓存加速构建可选保留
- name: cache-go-mod
image: woodpeckerci/plugin-cache
settings:
mount:
- ~/go/pkg/mod
- ~/.cache/go-build
key: ${CI_OS}-go-${CI_COMMIT_SHA:0:8}
restore_keys:
- ${CI_OS}-go-
prepare:
image: debian:bookworm
secrets: [WOODPECKER_SSH_KEY]
commands:
- apt update
- apt install ca-certificates curl git -y
- mkdir -p /root/.ssh
- echo "$WOODPECKER_SSH_KEY" > /root/.ssh/id_ed25519
- chmod 600 /root/.ssh/id_ed25519
- ssh-keyscan codeberg.org >> /root/.ssh/known_hosts
- git init
- git remote add origin $CI_REPO_CLONE_SSH_URL
- git config core.sshCommand 'ssh -i /root/.ssh/id_ed25519'
- git fetch && git checkout $CI_REPO_DEFAULT_BRANCH
- git submodule update --init --recursive
# 2. 初始化Go环境 & 预下载依赖
- name: prepare-go
prepare-go:
image: golang:1.25
commands:
- go version
- go mod download -x
- go mod verify # 验证依赖完整性可选保留
- go mod verify
# 3. 生成构建版本号优先Tag无Tag则用8位短SHA
- name: set-version
set-version:
image: golang:1.25
commands:
- |
@@ -57,8 +50,7 @@ steps:
echo "BUILD_VERSION=${VERSION}" >> $CI_ENV_FILE
echo "✅ 生成版本号:${VERSION}"
# 4. 直接编译Go服务核心步骤无测试前置
- name: build-logic
build_logic:
image: golang:1.25
environment:
CGO_ENABLED: 0
@@ -82,17 +74,15 @@ steps:
exit 1
fi
- ls -lh ./build/
- ./build/${BIN_NAME} -v || true # 验证程序可执行
- ./build/${BIN_NAME} -v || true
- echo "✅ Go服务编译完成"
# 5. 拉取JSON & 解析部署配置
- name: fetch-deploy-config
fetch-deploy-config:
image: alpine:latest
commands:
- apk add --no-cache curl jq
- echo "🔧 拉取部署配置:${JSON_CONFIG_URL}"
- |
# 3次重试机制避免网络波动
for i in 1 2 3; do
curl -sSL --connect-timeout 10 ${JSON_CONFIG_URL} -o /tmp/deploy-config.json && break
echo "⚠️ 第${i}次拉取失败,重试中..."
@@ -116,7 +106,6 @@ steps:
REMOTE_ONLINE_IDS=$(jq -r '.online_id' /tmp/deploy-config.json)
fi
- |
# 配置非空检查
if [ -z "$REMOTE_HOSTS" ] || [ -z "$REMOTE_USERS" ]; then
echo "❌ 解析配置失败:服务器/用户名为空"
cat /tmp/deploy-config.json
@@ -128,8 +117,7 @@ steps:
- echo "REMOTE_PASSWORDS=${REMOTE_PASSWORDS}" >> $CI_ENV_FILE
- echo "REMOTE_ONLINE_IDS=${REMOTE_ONLINE_IDS}" >> $CI_ENV_FILE
# 6. SCP推送产物到远程服务器
- name: scp-exe-to-servers
scp-exe-to-servers:
image: appleboy/drone-scp:1.6.2
settings:
host: ${REMOTE_HOSTS}
@@ -141,11 +129,10 @@ steps:
skip_verify: true
timeout: 30s
depends_on:
- build-logic
- build_logic
- fetch-deploy-config
# 7. 远程部署安装Screen + 启动程序
- name: deploy-to-servers
deploy-to-servers:
image: appleboy/drone-ssh:1.7.0
settings:
host: ${REMOTE_HOSTS}
@@ -155,7 +142,6 @@ steps:
timeout: 60s
script:
- |
# 检查/安装Screen兼容多包管理器
if command -v screen &> /dev/null; then
echo "✅ Screen已安装"
else
@@ -189,8 +175,7 @@ steps:
depends_on:
- scp-exe-to-servers
# 8. 打印部署完成汇总
- name: print-deploy-info
print-deploy-info:
image: alpine:latest
commands:
- echo "======================================"