65 lines
2.4 KiB
YAML
65 lines
2.4 KiB
YAML
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: |
|
||
# 2. 修复邮件头格式:加编码、明确From为邮箱格式、Subject转义
|
||
email_content=$(cat <<EOF
|
||
From: "${EMAIL_USER}" <${EMAIL_USER}> # QQ要求From必须是“名称<邮箱>”格式
|
||
To: ${TO_EMAIL}
|
||
Subject: =?UTF-8?B?${base64_subject}?= # 解决中文主题乱码+协议错误
|
||
Content-Type: text/plain; charset=UTF-8 # 明确编码,避免特殊字符问题
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
通知:有新的内容已推送到仓库「toutoukan」的main分支!
|
||
仓库地址:https://github.com/mayimingperson/toutoukan # 替换为实际仓库地址
|
||
触发时间:$(date +"%Y-%m-%d %H:%M:%S") # 增加动态时间,便于排查
|
||
EOF
|
||
)
|
||
|
||
# 3. 中文主题转Base64(QQ邮箱要求,否则可能触发协议错误)
|
||
base64_subject=$(echo -n "推送仓库成功" | base64)
|
||
|
||
# 4. 修复curl命令:明确smtps协议、加超时重试、输出详细日志
|
||
curl -v \
|
||
--connect-timeout 10 \ # 超时时间,避免卡壳
|
||
--max-time 20 \ # 最大执行时间
|
||
--smtp-ssl \ # 强制启用SSL(适配QQ邮箱)
|
||
--mail-from "${EMAIL_USER}" \
|
||
--mail-rcpt "${TO_EMAIL}" \
|
||
--user "${EMAIL_USER}:${EMAIL_PASS}" \
|
||
"smtps://${SMTP_SERVER}:${SMTP_PORT}" \
|
||
-T <(echo -e "${email_content}") # -e 处理换行符,确保格式正确
|
||
|
||
|