Files
mce/scripts/ci.sh

48 lines
1.2 KiB
Bash
Executable File
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.

#!/bin/bash
# CI 流水线脚本
# 调用方式bash scripts/ci.sh [--strict]
# --strict 阻断模式lint 失败则 exit 1
# 默认 报告模式lint 只输出不阻断)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
export PATH="$HOME/go/bin:$PATH"
cd "$ROOT"
STRICT=false
if [[ "${1:-}" == "--strict" ]]; then
STRICT=true
fi
echo "========================================"
echo " CI Pipeline"
echo " Mode: $( $STRICT && echo 'STRICT' || echo 'REPORT' )"
echo "========================================"
# 1. 格式检查
echo ""
echo "==> 1/3 格式检查 (gofumpt + goimports)"
test -z "$(gofumpt -l internal/ cmd/)" || { echo "gofumpt: 以下文件格式不正确:"; gofumpt -l internal/ cmd/; exit 1; }
test -z "$(goimports -l internal/ cmd/)" || { echo "goimports: 以下文件 import 不规范:"; goimports -l internal/ cmd/; exit 1; }
# 2. 编译检查
echo ""
echo "==> 2/3 编译检查 (go build)"
go build ./...
# 3. 静态分析
echo ""
echo "==> 3/3 静态分析 (golangci-lint)"
if $STRICT; then
golangci-lint run ./...
else
golangci-lint run ./... || true
fi
echo ""
echo "========================================"
echo " CI Pipeline 完成"
echo "========================================"