From b60ce37ab753cad7f06b47a6a3b84633337143db Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 8 Jul 2026 18:12:06 +0800 Subject: [PATCH] ci(actions): notify flow completion --- .gitea/workflows/docker-image.yml | 3 +- docs/backend/notify.md | 8 +++ scripts/ci/notify-actions.sh | 105 +++++++++++++++++++----------- 3 files changed, 75 insertions(+), 41 deletions(-) create mode 100644 docs/backend/notify.md diff --git a/.gitea/workflows/docker-image.yml b/.gitea/workflows/docker-image.yml index 8f1dbb91..28d4d0b8 100644 --- a/.gitea/workflows/docker-image.yml +++ b/.gitea/workflows/docker-image.yml @@ -230,7 +230,6 @@ jobs: if: always() env: ACTION_JOB_STATUS: ${{ job.status }} - ACTION_NOTIFY_PROVIDER: ${{ secrets.ACTION_NOTIFY_PROVIDER }} - ACTION_NOTIFY_WEBHOOK_URL: ${{ secrets.ACTION_NOTIFY_WEBHOOK_URL }} + FLOW_NOTIFY_BASE_URL: ${{ secrets.FLOW_NOTIFY_BASE_URL }} run: | bash scripts/ci/notify-actions.sh diff --git a/docs/backend/notify.md b/docs/backend/notify.md new file mode 100644 index 00000000..60a53da2 --- /dev/null +++ b/docs/backend/notify.md @@ -0,0 +1,8 @@ +curl -X POST https://flow.banlv-ai.com/requirements/REQ-XXXXXXXX/development-complete \ + -H "Content-Type: application/json" \ + -d '{ + "operator": "gitea", + "result": "ready_for_test", + "summary": "Gitea 内容操作已完成:这里写他完成了什么、提交/分支/链接", + "source": "gitea" + }' \ No newline at end of file diff --git a/scripts/ci/notify-actions.sh b/scripts/ci/notify-actions.sh index c53f5692..5e7fb8a8 100644 --- a/scripts/ci/notify-actions.sh +++ b/scripts/ci/notify-actions.sh @@ -5,22 +5,37 @@ warn() { printf 'Notification warning: %s\n' "$*" >&2 } -provider="$(printf '%s' "${ACTION_NOTIFY_PROVIDER:-}" | tr '[:upper:]' '[:lower:]')" -webhook_url="${ACTION_NOTIFY_WEBHOOK_URL:-}" +resolve_commit_message() { + if [ -n "${ACTION_NOTIFY_COMMIT_MESSAGE:-}" ]; then + printf '%s\n' "$ACTION_NOTIFY_COMMIT_MESSAGE" + return 0 + fi -if [ -z "$provider" ] || [ -z "$webhook_url" ]; then - echo "Action notification secrets are not configured, skip notification." - exit 0 -fi + if command -v git >/dev/null 2>&1; then + git log -1 --pretty=%B 2>/dev/null || true + fi +} -case "$provider" in - feishu | dingtalk) - ;; - *) - warn "unsupported ACTION_NOTIFY_PROVIDER: $provider" - exit 0 - ;; -esac +extract_requirement_id() { + printf '%s\n' "$1" | grep -Eo 'REQ-[A-Za-z0-9_-]+' | head -n 1 || true +} + +normalize_job_result() { + case "$1" in + success) + printf 'ready_for_test' + ;; + cancelled | canceled) + printf 'cancelled' + ;; + failure | failed) + printf 'failed' + ;; + *) + printf 'failed' + ;; + esac +} branch_name="${BRANCH_NAME:-${GITHUB_REF_NAME:-}}" if [ -z "$branch_name" ] && [ -n "${GITHUB_REF:-}" ]; then @@ -38,11 +53,23 @@ if [ -z "$short_sha" ]; then short_sha="unknown" fi +commit_message="$(resolve_commit_message)" +requirement_id="$(extract_requirement_id "$commit_message")" +if [ -z "$requirement_id" ]; then + warn "no REQ-* requirement id found in latest commit message, skip flow notification" + exit 0 +fi + +base_url="${FLOW_NOTIFY_BASE_URL:-https://flow.banlv-ai.com}" +base_url="${base_url%/}" +notify_url="$base_url/requirements/$requirement_id/development-complete" + deploy_env="${DEPLOY_ENV:-unknown}" image_tag="${IMAGE_VERSION_TAG:-unknown}" job_status="${ACTION_JOB_STATUS:-unknown}" workflow_name="${GITHUB_WORKFLOW:-Docker Image}" repository="${GITHUB_REPOSITORY:-cozsweet-frontend-nextjs}" +result="$(normalize_job_result "$job_status")" run_url="" if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then @@ -52,9 +79,11 @@ if [ -z "$run_url" ]; then run_url="${GITHUB_SERVER_URL:-unknown}" fi -export ACTION_NOTIFY_PROVIDER="$provider" -export ACTION_NOTIFY_MESSAGE="$(cat </dev/null; then - warn "failed to send $provider notification" +if [ "${FLOW_NOTIFY_DRY_RUN:-}" = "1" ]; then + printf 'Flow notification dry run URL: %s\n' "$notify_url" + printf 'Flow notification dry run payload: %s\n' "$payload" exit 0 fi -echo "Sent $provider action notification." +if ! curl -fsS \ + -X POST "$notify_url" \ + -H "Content-Type: application/json" \ + -d "$payload" >/dev/null; then + warn "failed to send flow notification for $requirement_id" + exit 0 +fi + +echo "Sent flow notification for $requirement_id."