71 lines
2.1 KiB
YAML
71 lines
2.1 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: |
|
||
# 验证SMTP参数是否正确(调试用,可删除)
|
||
echo "SMTP服务器: $SMTP_SERVER"
|
||
echo "SMTP端口: $SMTP_PORT"
|
||
echo "发件人: $EMAIL_USER"
|
||
|
||
# 检查URL格式是否正确(调试用,可删除)
|
||
smtp_url="smtps://$SMTP_SERVER:$SMTP_PORT"
|
||
echo "SMTP URL: $smtp_url"
|
||
|
||
# 中文主题Base64编码
|
||
base64_subject=$(echo -n "推送仓库成功" | base64)
|
||
|
||
# 构建邮件内容
|
||
email_content=$(cat <<EOF
|
||
From: "$EMAIL_USER" <$EMAIL_USER>
|
||
To: $TO_EMAIL
|
||
Subject: =?UTF-8?B?$base64_subject?=
|
||
Content-Type: text/plain; charset=UTF-8
|
||
|
||
通知:有新的内容已推送到仓库「toutoukan」的main分支
|
||
推送时间: $(date +"%Y-%m-%d %H:%M:%S")
|
||
EOF
|
||
)
|
||
|
||
# 发送邮件(修复URL格式)
|
||
curl -v \
|
||
--connect-timeout 10 \
|
||
--max-time 20 \
|
||
--mail-from "$EMAIL_USER" \
|
||
--mail-rcpt "$TO_EMAIL" \
|
||
--user "$EMAIL_USER:$EMAIL_PASS" \
|
||
"$smtp_url" \ # 使用预定义的URL变量,避免格式错误
|
||
-T <(echo -e "$email_content")
|
||
|
||
|