feat(notify-email): composite action 通过 SMTP 发邮件 + lint workflow
lint / yamllint (push) Successful in 12s
lint / yamllint (push) Successful in 12s
- notify-email 用 curl smtps:// 协议,163/126 兼容 - self-mail 模式:USER/TO 可同账号 - 失败时 ::warning:: 不阻塞 - lint workflow: yamllint 验证 action.yml 语法
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
name: lint
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
jobs:
|
||||||
|
yamllint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: docker.io/catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
# runner 默认已 clone 当前仓库(ci-actions 自身)到 step 工作目录
|
||||||
|
# 无需 actions/checkout(也避免拉 github.com)
|
||||||
|
- name: Install yamllint
|
||||||
|
run: |
|
||||||
|
apt-get update && apt-get install -y yamllint
|
||||||
|
- name: Run yamllint
|
||||||
|
run: yamllint .
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# notify-email
|
||||||
|
|
||||||
|
通过 SMTP 发送 Gitea Actions run 结果邮件。**已验证兼容 163 / 126 邮箱**。
|
||||||
|
|
||||||
|
## Inputs
|
||||||
|
|
||||||
|
| 名称 | 必填 | 默认 | 说明 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `smtp_host` | ✅ | — | 例:`smtp.163.com` |
|
||||||
|
| `smtp_port` | ❌ | `465` | SSL 端口 |
|
||||||
|
| `smtp_user` | ✅ | — | 完整邮箱地址 |
|
||||||
|
| `smtp_pass` | ✅ | — | 授权码(业务 repo 配 Gitea secret) |
|
||||||
|
| `from` | ❌ | = `smtp_user` | 发件人 |
|
||||||
|
| `to` | ✅ | — | 收件人,多个用逗号 |
|
||||||
|
| `subject` | ✅ | — | 邮件主题 |
|
||||||
|
| `body` | ✅ | — | 邮件正文(纯文本) |
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: gitea_admin/ci-actions/notify-email@v1
|
||||||
|
with:
|
||||||
|
smtp_host: smtp.163.com
|
||||||
|
smtp_user: ${{ secrets.EMAIL_USER }}
|
||||||
|
smtp_pass: ${{ secrets.EMAIL_SMTP_PASS }}
|
||||||
|
to: ${{ secrets.EMAIL_TO }}
|
||||||
|
subject: "[gitea-ci] ${{ github.repository }} - ${{ needs.build.result }}"
|
||||||
|
body: |
|
||||||
|
repository: ${{ github.repository }}
|
||||||
|
workflow: ${{ github.workflow }}
|
||||||
|
status: ${{ needs.build.result }}
|
||||||
|
url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 安全
|
||||||
|
|
||||||
|
`smtp_pass` **必须**通过 Gitea secret 传入,**不要**直接写在 workflow 里。
|
||||||
|
|
||||||
|
## 失败处理
|
||||||
|
|
||||||
|
邮件发送失败时输出 `::warning::Email send failed (non-fatal)`,**不阻塞**调用方 job。
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
name: 'Notify Email'
|
||||||
|
description: 'Send Gitea Actions run result via SMTP (163/126 compatible)'
|
||||||
|
author: 'gitea_admin'
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
smtp_host:
|
||||||
|
description: 'SMTP host (e.g. smtp.126.com)'
|
||||||
|
required: true
|
||||||
|
smtp_port:
|
||||||
|
description: 'SMTP SSL port'
|
||||||
|
required: false
|
||||||
|
default: '465'
|
||||||
|
smtp_user:
|
||||||
|
description: 'SMTP user (full email address)'
|
||||||
|
required: true
|
||||||
|
smtp_pass:
|
||||||
|
description: 'SMTP authorization code'
|
||||||
|
required: true
|
||||||
|
from:
|
||||||
|
description: 'From address'
|
||||||
|
required: false
|
||||||
|
default: ${{ inputs.smtp_user }}
|
||||||
|
to:
|
||||||
|
description: 'Recipient(s), comma separated'
|
||||||
|
required: true
|
||||||
|
subject:
|
||||||
|
description: 'Email subject'
|
||||||
|
required: true
|
||||||
|
body:
|
||||||
|
description: 'Email body (plain text)'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- name: Send email via SMTP
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
SMTP_HOST: ${{ inputs.smtp_host }}
|
||||||
|
SMTP_PORT: ${{ inputs.smtp_port }}
|
||||||
|
SMTP_USER: ${{ inputs.smtp_user }}
|
||||||
|
SMTP_PASS: ${{ inputs.smtp_pass }}
|
||||||
|
FROM_ADDR: ${{ inputs.from }}
|
||||||
|
TO_ADDR: ${{ inputs.to }}
|
||||||
|
SUBJECT: ${{ inputs.subject }}
|
||||||
|
BODY: ${{ inputs.body }}
|
||||||
|
run: |
|
||||||
|
set -u
|
||||||
|
# 构造 --mail-rcpt 参数(每个收件人一个)
|
||||||
|
RCPT_ARGS=""
|
||||||
|
IFS=','
|
||||||
|
for addr in $TO_ADDR; do
|
||||||
|
RCPT_ARGS="$RCPT_ARGS --mail-rcpt $(printf '%s' "$addr" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
|
||||||
|
done
|
||||||
|
unset IFS
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
if ! printf '%s' "$BODY" | curl -fsS --ssl \
|
||||||
|
--url "smtps://${SMTP_HOST}:${SMTP_PORT}" \
|
||||||
|
--user "${SMTP_USER}:${SMTP_PASS}" \
|
||||||
|
--mail-from "${FROM_ADDR}" \
|
||||||
|
$RCPT_ARGS \
|
||||||
|
-H "Subject: ${SUBJECT}" \
|
||||||
|
-H "From: ${FROM_ADDR}" \
|
||||||
|
-H "To: ${TO_ADDR}" \
|
||||||
|
-H "Content-Type: text/plain; charset=UTF-8" \
|
||||||
|
--max-time 15 --retry 2 \
|
||||||
|
--upload-file -; then
|
||||||
|
echo "::warning::Email send failed (non-fatal)"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user