name: Golang CI on: push: branches: ["main"] jobs: test-go: runs-on: centos-latest steps: - name: code-pull uses: actions/checkout@v4 - name: setup-goenv uses: actions/setup-go@v5 with: go-version: '1.24.7' - name: verify go mod run: go mod verify - name: go build run: go build -v ./... - name: go test run: go test -v ./... send-email: runs-on: ubuntu-latest steps: - name: install email tool run: | sudo apt update -y sudo apt install -y sendmail - name: send email env: SMTP_SERVER: ${{ secrets.SMTP_SERVER }} SMTP_PORT: ${{ secrets.SMTP_PORT }} EMAIL_USER: ${{ secrets.EMAIL_USER }} EMAIL_PASS: ${{ secrets.EMAIL_PASS }} TO_EMAIL: 1627832236@qq.com run: | smtp_url="smtps://${SMTP_SERVER}:${SMTP_PORT}" smtp_url=$(echo "$smtp_url" | tr -d '[:space:]') # 确保无空白字符 echo "最终SMTP URL: [$smtp_url]" # 应显示 [smtps://smtp.qq.com:465] # 2. 中文主题编码(保持兼容) base64_subject=$(echo -n "推送仓库成功" | base64 | tr -d '\n') # 3. 构建邮件内容(简化格式,与本地成功命令的结构匹配) email_content=$(cat <<-EOF From: ${EMAIL_USER} To: ${TO_EMAIL} Subject: =?UTF-8?B?${base64_subject}?= 通知:有新的内容已推送到仓库「toutoukan」的main分支! 推送时间: $(date +"%Y-%m-%d %H:%M:%S") 推送作者: $(git log -1 --pretty=format:'%an') 提交信息: $(git log -1 --pretty=format:'%s') EOF ) # 4. 发送邮件(严格匹配本地成功的curl参数) curl -v \ --tlsv1.2 \ # 强制TLS 1.2,与本地测试一致 --mail-from "$EMAIL_USER" \ --mail-rcpt "$TO_EMAIL" \ --user "$EMAIL_USER:$EMAIL_PASS" \ -T <(echo -e "$email_content") \ # 邮件内容位置与本地命令一致 "$smtp_url" # URL参数放在最后,与本地命令格式一致