Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9ed21bd4d | ||
|
|
323bf9bfdb | ||
|
|
507124d91c | ||
|
|
224f5bdd78 | ||
|
|
1ec372142c | ||
|
|
07ef51040a | ||
|
|
3f9fa1f9c9 |
@@ -2,6 +2,12 @@
|
||||
|
||||
Gitea Actions 公共 action 仓库。
|
||||
|
||||
> **维护模式**(2026-07-16 起):本仓库**独立发布**(自己打 tag:`v1.x.y`)。
|
||||
> `gitea_admin/docker-gitea` 仓库通过 **git submodule** 把本仓库作为 `ci-actions/`
|
||||
> 子目录引入,方便在 docker-gitea 仓库内查看/同步代码;
|
||||
> 但所有 action 改动与发版都**在本仓库**进行(commit + push + tag),业务仓库
|
||||
> workflow 的 `uses:` URL 仍指向本仓库 `http://gitea:3000/gitea_admin/ci-actions/<name>@<tag>`。
|
||||
|
||||
通过 `uses: gitea_admin/ci-actions/<name>@v1` 在业务 workflow 中复用,
|
||||
避免每个仓库重复实现。
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
# notify-all
|
||||
|
||||
Bark iOS push + SMTP email in **one step**. Designed for zero-config when paired with
|
||||
**org-level** (or instance-level) secrets on Gitea.
|
||||
|
||||
## Usage (极简 / recommended)
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "your build steps"
|
||||
|
||||
notify:
|
||||
needs: build
|
||||
if: always()
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: notify
|
||||
uses: http://gitea:3000/gitea_admin/ci-actions/notify-all@v1
|
||||
with:
|
||||
status: ${{ needs.build.result }}
|
||||
```
|
||||
|
||||
That's it — Bark 推送 + 邮件发送全自动,body/title/subject 自动从 `github.*` + `inputs.status` 拼,
|
||||
secret 走 org-level(gitea_admin org 已配)。
|
||||
|
||||
## 必传
|
||||
|
||||
| Input | 来源 | 说明 |
|
||||
|---|---|---|
|
||||
| `status` | caller → `${{ needs.build.result }}` | 唯一必传,用于拼 body / subject |
|
||||
|
||||
## 可选 inputs(全部有默认值)
|
||||
|
||||
| Input | Default | 说明 |
|
||||
|---|---|---|
|
||||
| `channels` | `both` | 通知通道:`both` / `bark` / `email` |
|
||||
| `title` | `[${{ github.repository }}] ${{ github.workflow }}` | Bark 推送标题 |
|
||||
| `email_subject` | `[gitea-ci] ${{ github.repository }} - ${{ inputs.status }}` | 邮件主题 |
|
||||
| `bark_device_key` | `${{ secrets.BARK_DEVICE_KEY }}` | Bark key(org secret) |
|
||||
| `bark_server` | `https://api.day.app` | Bark server(自建时改) |
|
||||
| `bark_group` | `gitea-ci` | Bark 分组 |
|
||||
| `bark_level` | `active` | active / timeSensitive / passive / default |
|
||||
| `smtp_host` | `smtp.163.com` | SMTP host |
|
||||
| `smtp_port` | `465` | SMTP SSL 端口 |
|
||||
| `smtp_user` | `${{ secrets.EMAIL_USER }}` | 发件邮箱(org secret) |
|
||||
| `smtp_pass` | `${{ secrets.EMAIL_SMTP_PASS }}` | SMTP 授权码(org secret) |
|
||||
| `to` | `${{ secrets.EMAIL_TO }}` | 收件邮箱(org secret) |
|
||||
|
||||
> body 不再是 input(v1.1.2 起),由 notify-all 自动拼(status / branch / commit / **sha 前 10 位** / actor / run)。如需自定义 body,绕开 notify-all 直接用 notify-bark + notify-email。
|
||||
|
||||
## 自动拼的 body 格式
|
||||
|
||||
```
|
||||
status: success
|
||||
branch: main
|
||||
commit: ci: any commit message
|
||||
sha: 29a4454e0 # ← 只取前 10 位
|
||||
actor: gitea_admin
|
||||
run: http://gitea:3000/gitea_admin/<repo>/actions/runs/<id>
|
||||
```
|
||||
|
||||
## 依赖的 org-level secret(gitea_admin org 已配)
|
||||
|
||||
- `BARK_DEVICE_KEY`
|
||||
- `EMAIL_USER`
|
||||
- `EMAIL_SMTP_PASS`
|
||||
- `EMAIL_TO`
|
||||
|
||||
业务 repo 不需要再配 secret。
|
||||
|
||||
## 选通道
|
||||
|
||||
```yaml
|
||||
- uses: http://gitea:3000/gitea_admin/ci-actions/notify-all@v1.2.0
|
||||
with:
|
||||
status: ${{ needs.build.result }}
|
||||
channels: email # 只发邮件(不推 Bark)
|
||||
```
|
||||
|
||||
可选值:`both`(默认)/ `bark` / `email`。
|
||||
|
||||
## 内部实现
|
||||
|
||||
`notify-all` 是 composite action,内部 chain 调 sibling action:
|
||||
- `uses: ./notify-bark`
|
||||
- `uses: ./notify-email`
|
||||
|
||||
v1.1.0 tag 下三个 action 自包含,runner 拉一次仓库就够。
|
||||
|
||||
## 失败处理
|
||||
|
||||
Bark / Email 任一失败 → `::warning::` 输出 → step 仍 Success → job 不阻塞。
|
||||
(继承自 `notify-bark` / `notify-email` 的 `curl --retry 2` + `if !` 包裹逻辑。)
|
||||
@@ -0,0 +1,118 @@
|
||||
name: 'Notify All'
|
||||
description: 'Bark push + email in one step. Zero-config when paired with org/instance-level secrets.'
|
||||
author: 'gitea_admin'
|
||||
|
||||
# v1.1.2 改动(2026-07-15):
|
||||
# - sha 字段截短到前 10 位(git short SHA 标准)
|
||||
# - 因为 input default 在 composite 开始时 evaluate,引用不到 steps.output,
|
||||
# 所以把 body 从 input default 移到 step with 里(直接用 ${{ steps.short_sha.outputs.value }})
|
||||
# - 删 body input —— 业务侧不能 override body;如要自定义可走 notify-bark/notify-email 直引
|
||||
|
||||
inputs:
|
||||
status:
|
||||
description: 'Build job status (caller passes ${{ needs.<job>.result }})'
|
||||
required: true
|
||||
channels:
|
||||
description: 'Notification channels: both (default) / bark / email'
|
||||
required: false
|
||||
default: 'both'
|
||||
title:
|
||||
description: 'Notification title'
|
||||
required: false
|
||||
default: "[${{ github.repository }}] ${{ github.workflow }}"
|
||||
email_subject:
|
||||
description: 'Email subject'
|
||||
required: false
|
||||
default: "[gitea-ci] ${{ github.repository }} - ${{ inputs.status }}"
|
||||
|
||||
# ----- Bark 配置(默认走 org secret) -----
|
||||
bark_device_key:
|
||||
description: 'Bark device key (org secret)'
|
||||
required: false
|
||||
default: ${{ secrets.BARK_DEVICE_KEY }}
|
||||
bark_server:
|
||||
description: 'Bark server URL'
|
||||
required: false
|
||||
default: 'https://api.day.app'
|
||||
bark_group:
|
||||
description: 'Bark group'
|
||||
required: false
|
||||
default: 'gitea-ci'
|
||||
bark_level:
|
||||
description: 'Bark level'
|
||||
required: false
|
||||
default: 'active'
|
||||
|
||||
# ----- Email 配置(默认走 org secret + smtp.163.com) -----
|
||||
smtp_host:
|
||||
description: 'SMTP host'
|
||||
required: false
|
||||
default: 'smtp.163.com'
|
||||
smtp_port:
|
||||
description: 'SMTP SSL port'
|
||||
required: false
|
||||
default: '465'
|
||||
smtp_user:
|
||||
description: 'SMTP user (org secret)'
|
||||
required: false
|
||||
default: ${{ secrets.EMAIL_USER }}
|
||||
smtp_pass:
|
||||
description: 'SMTP auth code (org secret)'
|
||||
required: false
|
||||
default: ${{ secrets.EMAIL_SMTP_PASS }}
|
||||
to:
|
||||
description: 'Recipient(s), comma separated'
|
||||
required: false
|
||||
default: ${{ secrets.EMAIL_TO }}
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
# 1. 算 short SHA(git 标准 10 位)。Gitea 表达式没 slice/substring 函数,必须用 shell
|
||||
- name: Compute short SHA
|
||||
id: short_sha
|
||||
shell: bash
|
||||
run: |
|
||||
SHA="${{ github.event.head_commit.id }}"
|
||||
SHORT="${SHA:0:10}"
|
||||
echo "value=${SHORT}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# 2. Push to Bark(链式调 sibling action,完整 URL 因为 act_runner 0.2.11 不支持 ./relative)
|
||||
# 默认走 bark + email (channels=both),可传 channels=bark 只推 bark / channels=email 只发邮件
|
||||
- name: Push to Bark
|
||||
if: ${{ inputs.channels != 'email' }}
|
||||
uses: http://gitea:3000/gitea_admin/ci-actions/notify-bark@v1.1.2
|
||||
with:
|
||||
device_key: ${{ inputs.bark_device_key }}
|
||||
server: ${{ inputs.bark_server }}
|
||||
title: ${{ inputs.title }}
|
||||
body: |
|
||||
status: ${{ inputs.status }}
|
||||
branch: ${{ github.ref_name }}
|
||||
commit: ${{ github.event.head_commit.message }}
|
||||
sha: ${{ steps.short_sha.outputs.value }}
|
||||
actor: ${{ github.actor }}
|
||||
run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
group: ${{ inputs.bark_group }}
|
||||
level: ${{ inputs.bark_level }}
|
||||
|
||||
# 3. Send email
|
||||
- name: Send email
|
||||
if: ${{ inputs.channels != 'bark' }}
|
||||
uses: http://gitea:3000/gitea_admin/ci-actions/notify-email@v1.1.2
|
||||
with:
|
||||
smtp_host: ${{ inputs.smtp_host }}
|
||||
smtp_port: ${{ inputs.smtp_port }}
|
||||
smtp_user: ${{ inputs.smtp_user }}
|
||||
smtp_pass: ${{ inputs.smtp_pass }}
|
||||
to: ${{ inputs.to }}
|
||||
subject: ${{ inputs.email_subject }}
|
||||
body: |
|
||||
repository: ${{ github.repository }}
|
||||
workflow: ${{ github.workflow }}
|
||||
status: ${{ inputs.status }}
|
||||
branch: ${{ github.ref_name }}
|
||||
commit: ${{ github.event.head_commit.message }}
|
||||
sha: ${{ steps.short_sha.outputs.value }}
|
||||
url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
actor: ${{ github.actor }}
|
||||
@@ -53,16 +53,20 @@ runs:
|
||||
RCPT_ARGS="$RCPT_ARGS --mail-rcpt $(printf '%s' "$addr" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
|
||||
done
|
||||
unset IFS
|
||||
|
||||
# 整封邮件拼好(headers + 空行 + body)从 stdin 给 curl --upload-file -
|
||||
# 避开 "-H + --upload-file -" 组合在 smtps:// 下不生效的 bug(curl 不会把 -H
|
||||
# 头部合并进 DATA 段,结果只发空 body)。v1.0.0 是这么写的,1.0.1 改成全量 stdin。
|
||||
# 同时给出一个明确的 Date 头部,避免 163 反垃圾系统把无 Date 的邮件归类。
|
||||
DATE_HDR=$(date -R)
|
||||
EMAIL=$(printf 'From: %s\nTo: %s\nSubject: %s\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nDate: %s\n\n%s' \
|
||||
"$FROM_ADDR" "$TO_ADDR" "$SUBJECT" "$DATE_HDR" "$BODY")
|
||||
# shellcheck disable=SC2086
|
||||
if ! printf '%s' "$BODY" | curl -fsS --ssl \
|
||||
if ! printf '%s' "$EMAIL" | 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)"
|
||||
|
||||
Reference in New Issue
Block a user