mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 06:33:37 +08:00
60 lines
1.2 KiB
Bash
60 lines
1.2 KiB
Bash
#!/bin/bash
|
||
set -euo pipefail
|
||
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m'
|
||
|
||
log_info() {
|
||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||
}
|
||
|
||
log_success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
log_warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
log_error() {
|
||
echo -e "${RED}❌ $1${NC}"
|
||
}
|
||
|
||
main() {
|
||
if ! command -v git >/dev/null 2>&1; then
|
||
log_error "未检测到 git 命令"
|
||
exit 1
|
||
else
|
||
log_info "已检测到 git: $(git --version)"
|
||
fi
|
||
|
||
local name="${GIT_USER_NAME:-}"
|
||
local email="${GIT_USER_EMAIL:-}"
|
||
|
||
if [[ -z "$name" && -z "$email" ]]; then
|
||
log_warning "未提供 Git 用户名和邮箱,跳过配置"
|
||
return 0
|
||
fi
|
||
|
||
if [[ -n "$name" ]]; then
|
||
git config --global user.name "$name"
|
||
log_success "已配置 Git 用户名: $name"
|
||
else
|
||
log_warning "未提供 Git 用户名"
|
||
fi
|
||
|
||
if [[ -n "$email" ]]; then
|
||
git config --global user.email "$email"
|
||
log_success "已配置 Git 邮箱: $email"
|
||
else
|
||
log_warning "未提供 Git 邮箱"
|
||
fi
|
||
}
|
||
|
||
trap 'log_error "Git 配置失败,退出码: $?"' ERR
|
||
|
||
main "$@"
|