-
Notifications
You must be signed in to change notification settings - Fork 0
fix(workflow): use jq to properly handle newlines in Feishu notification #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough将 centralized-release 工作流中 Feishu 通知从多步骤、基于输出的构建改为单步骤在 runner 端用环境变量与运行时变量生成结构化 JSON(通过 jq),并用单次 curl 提交到 Feishu webhook;同时调整仓库列表解析与日期/干跑标识处理。 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant GH as "GitHub Actions Runner"
participant Script as "notify Feishu shell script (jq)"
participant Feishu as "Feishu Webhook API"
GH->>Script: 读取环境输入 (WEBHOOK_URL, ACTOR, RUN_URL, RELEASE_DATE, REPO_LINES...)
Script->>Script: 解析 REPO_LINES,提取 repo/version/changelog_path,计算 DISPLAY_DATE、DRY_RUN_TAG
Script->>Script: 使用 jq 组装结构化 JSON payload (title, color, info, repos)
Script->>Feishu: POST JSON payload -> WEBHOOK_URL (curl)
Feishu-->>Script: 返回响应 (success/failure)
Script-->>GH: 根据响应设置退出状态
Estimated code review effort🎯 3 (中等复杂度) | ⏱️ ~20 分钟 Possibly related PRs
Suggested reviewers
概览此PR重构了 Feishu 通知流程,将其从多步骤、输出驱动的方式改为单步骤服务器端 JSON 负载构造。通过引入环境变量和运行时状态变量,并采用 jq 动态生成通知 payload,简化了通知逻辑。 变更清单
估算代码审查工作量🎯 3 (中等复杂度) | ⏱️ ~20 分钟 可能相关的 PR
建议审阅人
兔子之歌
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
The merge-base changed after approval.
0ec4daa to
c4811d7
Compare
Replace manual string escaping with jq for JSON construction. This fixes the issue where \n was displayed as literal text instead of being parsed as newlines in the Feishu card. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
c4811d7 to
b87d5bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.github/workflows/centralized-release.yml:
- Around line 264-266: The curl invocation that posts to $WEBHOOK_URL with -d
"$JSON_PAYLOAD" should treat HTTP 4xx/5xx as failures; update the curl command
(the existing curl -X POST "$WEBHOOK_URL" -H "Content-Type: application/json" -d
"$JSON_PAYLOAD") to include --fail (and optionally --show-error) and ensure the
step fails on a non‑zero exit (e.g., let the CI shell propagate curl's exit code
or add an explicit check) so the workflow errors when the notification request
fails.
| curl -X POST "$WEBHOOK_URL" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$JSON_PAYLOAD" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check curl version and --fail-with-body support
echo "=== Curl version ==="
curl --version | head -1
echo ""
echo "=== Checking for --fail-with-body flag ==="
curl --help | grep -i "fail-with-body" || echo "Flag not found"
echo ""
echo "=== Checking for --fail flag ==="
curl --help | grep -i "^[[:space:]]*--fail" | head -5Repository: wuji-technology/.github
Length of output: 383
🏁 Script executed:
# Read the workflow file to understand context
cat -n .github/workflows/centralized-release.yml | sed -n '260,270p'Repository: wuji-technology/.github
Length of output: 287
🏁 Script executed:
# Check broader context around the webhook call
cat -n .github/workflows/centralized-release.yml | sed -n '250,275p'Repository: wuji-technology/.github
Length of output: 974
🏁 Script executed:
#!/bin/bash
# Try to use --fail-with-body flag directly to verify it exists
echo "=== Testing --fail-with-body flag ==="
curl --help 2>&1 | wc -l
echo "Help output line count above"
# Try with a different approach - check man page or curl documentation
echo ""
echo "=== Checking curl documentation for --fail ==="
curl --help 2>&1 | grep -A2 -E "\-\-fail" | head -20
# Let's also check what happens with curl on 4xx/5xx responses
echo ""
echo "=== Testing curl default behavior on HTTP errors ==="
# Using httpbin.org's status endpoint (returns specific status codes)
# This shows that curl returns 0 even on 404
(curl -s -w "Exit code would be: %{http_code}\n" "https://httpbin.org/status/404" 2>&1 || echo "Curl exited with code: $?") | head -5Repository: wuji-technology/.github
Length of output: 456
🏁 Script executed:
# Check if --fail-with-body is documented in curl man pages or online docs
# For curl 7.88.1 specifically
echo "=== Checking curl version history for --fail-with-body ==="
curl --version | head -1
# According to curl changelog, --fail-with-body was added in 7.76.0
# Our version 7.88.1 should support it
# Let's verify by checking actual curl behavior
echo ""
echo "=== Try using --fail flag with older curl syntax ==="
curl --help 2>&1 | grep -E "^\s+--fail" -A 1Repository: wuji-technology/.github
Length of output: 382
建议添加 curl 失败条件,确保通知失败时工作流正确报错。
当前 curl 对 4xx/5xx 仍返回 0,导致通知发送失败但工作流显示成功。可以使用 --fail 标志让 curl 在 HTTP 错误时立即失败。
🔧 建议调整
- curl -X POST "$WEBHOOK_URL" \
- -H "Content-Type: application/json" \
- -d "$JSON_PAYLOAD"
+ curl --fail -X POST "$WEBHOOK_URL" \
+ -H "Content-Type: application/json" \
+ -d "$JSON_PAYLOAD"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| curl -X POST "$WEBHOOK_URL" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$JSON_PAYLOAD" | |
| curl --fail -X POST "$WEBHOOK_URL" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$JSON_PAYLOAD" |
🤖 Prompt for AI Agents
In @.github/workflows/centralized-release.yml around lines 264 - 266, The curl
invocation that posts to $WEBHOOK_URL with -d "$JSON_PAYLOAD" should treat HTTP
4xx/5xx as failures; update the curl command (the existing curl -X POST
"$WEBHOOK_URL" -H "Content-Type: application/json" -d "$JSON_PAYLOAD") to
include --fail (and optionally --show-error) and ensure the step fails on a
non‑zero exit (e.g., let the CI shell propagate curl's exit code or add an
explicit check) so the workflow errors when the notification request fails.
Summary
\n显示为字面文本而非换行的问题Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.