Skip to content

Commit a654538

Browse files
Copilotsupperthomas
andcommitted
Add immediate CI status comment via direct workflow integration
Co-authored-by: supperthomas <[email protected]>
1 parent 28e728b commit a654538

File tree

6 files changed

+195
-6
lines changed

6 files changed

+195
-6
lines changed

.github/workflows/README_CI_RESULTS.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,39 @@
22

33
## Overview / 概述
44

5-
This workflow automatically posts CI test results as comments on Pull Requests, making it easier for contributors and reviewers to see the status of all CI checks at a glance.
5+
This feature automatically posts CI test results as comments on Pull Requests, making it easier for contributors and reviewers to see the status of all CI checks at a glance.
66

7-
此工作流自动将 CI 测试结果作为评论发布到 Pull Request 中,使贡献者和审阅者更容易一目了然地看到所有 CI 检查的状态。
7+
此功能自动将 CI 测试结果作为评论发布到 Pull Request 中,使贡献者和审阅者更容易一目了然地看到所有 CI 检查的状态。
8+
9+
## Implementation / 实现方式
10+
11+
The feature uses **two complementary approaches** to ensure CI results are always visible:
12+
该功能使用**两种互补方法**来确保 CI 结果始终可见:
13+
14+
### 1. Direct Workflow Integration (Immediate) / 直接工作流集成(立即生效)
15+
16+
Each main CI workflow includes a `post-ci-status` job that:
17+
每个主要 CI 工作流都包含一个 `post-ci-status` 作业,它:
18+
19+
- ✅ Works immediately on PR branches (no merge required) / 立即在 PR 分支上生效(无需合并)
20+
- 📝 Updates a single comment with workflow status / 使用工作流状态更新单个评论
21+
- 🔄 Runs after each workflow completes / 在每个工作流完成后运行
22+
23+
**Modified Workflows:**
24+
- `bsp_buildings.yml`
25+
- `static_code_analysis.yml`
26+
- `format_check.yml`
27+
- `utest_auto_run.yml`
28+
29+
### 2. Workflow Run Trigger (After Merge) / 工作流运行触发器(合并后)
30+
31+
The `ci_results_comment.yml` workflow:
32+
`ci_results_comment.yml` 工作流:
33+
34+
- ⏰ Triggers when CI workflows complete / 在 CI 工作流完成时触发
35+
- 📊 Provides comprehensive summary of all workflows / 提供所有工作流的全面摘要
36+
- 🔍 Shows detailed job-level information / 显示详细的作业级信息
37+
- ⚠️ **Only works after merged to master** / **仅在合并到 master 后才有效**
838

939
## Features / 功能特性
1040

.github/workflows/bsp_buildings.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,17 @@ jobs:
288288
uses: actions/upload-artifact@main
289289
with:
290290
name: 00_all_bsp_output_${{ github.sha }}
291-
path: output/
291+
path: output/
292+
293+
# Post CI status to PR comment
294+
post-ci-status:
295+
needs: build
296+
if: always() && github.event_name == 'pull_request' && github.repository_owner == 'RT-Thread'
297+
uses: ./.github/workflows/post_ci_status.yml
298+
with:
299+
workflow_name: "RT-Thread BSP Static Build Check"
300+
workflow_status: ${{ needs.build.result }}
301+
pr_number: ${{ github.event.pull_request.number }}
302+
permissions:
303+
pull-requests: write
304+
issues: write

.github/workflows/format_check.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,17 @@ jobs:
2929
shell: bash
3030
run: |
3131
pip install click chardet PyYaml
32-
python tools/ci/file_check.py check 'https://github.com/RT-Thread/rt-thread' 'master'
32+
python tools/ci/file_check.py check 'https://github.com/RT-Thread/rt-thread' 'master'
33+
34+
# Post CI status to PR comment
35+
post-ci-status:
36+
needs: scancode_job
37+
if: always() && github.event_name == 'pull_request' && github.repository_owner == 'RT-Thread'
38+
uses: ./.github/workflows/post_ci_status.yml
39+
with:
40+
workflow_name: "Check File Format and License"
41+
workflow_status: ${{ needs.scancode_job.result }}
42+
pr_number: ${{ github.event.pull_request.number }}
43+
permissions:
44+
pull-requests: write
45+
issues: write
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#
2+
# Copyright (c) 2025, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Change Logs:
7+
# Date Author Notes
8+
# 2025-10-27 GitHub Copilot Reusable workflow to post CI status
9+
10+
name: Post CI Status Comment
11+
12+
on:
13+
workflow_call:
14+
inputs:
15+
workflow_name:
16+
description: 'Name of the workflow'
17+
required: true
18+
type: string
19+
workflow_status:
20+
description: 'Status of the workflow (success/failure)'
21+
required: true
22+
type: string
23+
pr_number:
24+
description: 'Pull request number'
25+
required: true
26+
type: number
27+
28+
permissions:
29+
pull-requests: write
30+
issues: write
31+
32+
jobs:
33+
post-comment:
34+
runs-on: ubuntu-22.04
35+
if: github.repository_owner == 'RT-Thread'
36+
steps:
37+
- name: Post or update CI status comment
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const prNumber = ${{ inputs.pr_number }};
42+
const workflowName = '${{ inputs.workflow_name }}';
43+
const workflowStatus = '${{ inputs.workflow_status }}';
44+
45+
// Status emoji mapping
46+
const statusEmoji = workflowStatus === 'success' ? '✅' : '❌';
47+
const timestamp = new Date().toISOString();
48+
49+
// Try to find existing comment
50+
const comments = await github.rest.issues.listComments({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
issue_number: prNumber
54+
});
55+
56+
const botComment = comments.data.find(comment =>
57+
comment.user.login === 'github-actions[bot]' &&
58+
comment.body.includes('<!-- CI Status Comment -->')
59+
);
60+
61+
// Get all workflow runs for this PR to build comprehensive status
62+
let allStatuses = {};
63+
64+
if (botComment) {
65+
// Parse existing statuses from comment
66+
const statusRegex = /- (✅|❌|🟡) \*\*(.+?)\*\*/g;
67+
let match;
68+
while ((match = statusRegex.exec(botComment.body)) !== null) {
69+
allStatuses[match[2]] = match[1];
70+
}
71+
}
72+
73+
// Update current workflow status
74+
allStatuses[workflowName] = statusEmoji;
75+
76+
// Build comment body
77+
let commentBody = '<!-- CI Status Comment -->\n';
78+
commentBody += '## 🤖 CI Test Results\n\n';
79+
commentBody += `**Last Updated:** ${timestamp}\n\n`;
80+
commentBody += '### Workflow Status:\n\n';
81+
82+
for (const [name, emoji] of Object.entries(allStatuses)) {
83+
commentBody += `- ${emoji} **${name}**\n`;
84+
}
85+
86+
commentBody += '\n---\n';
87+
commentBody += '✅ Success | ❌ Failure | 🟡 In Progress\n\n';
88+
commentBody += '*This comment is automatically updated as CI workflows complete.*\n';
89+
90+
if (botComment) {
91+
// Update existing comment
92+
await github.rest.issues.updateComment({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
comment_id: botComment.id,
96+
body: commentBody
97+
});
98+
console.log(`Updated comment ${botComment.id} on PR #${prNumber}`);
99+
} else {
100+
// Create new comment
101+
await github.rest.issues.createComment({
102+
owner: context.repo.owner,
103+
repo: context.repo.repo,
104+
issue_number: prNumber,
105+
body: commentBody
106+
});
107+
console.log(`Created new comment on PR #${prNumber}`);
108+
}

.github/workflows/static_code_analysis.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,17 @@ jobs:
5454
sudo make install FILESDIR=/usr/local/share/Cppcheck
5555
cppcheck --version
5656
cd ..
57-
python tools/ci/cpp_check.py check
57+
python tools/ci/cpp_check.py check
58+
59+
# Post CI status to PR comment
60+
post-ci-status:
61+
needs: scancode_job
62+
if: always() && github.event_name == 'pull_request' && github.repository_owner == 'RT-Thread'
63+
uses: ./.github/workflows/post_ci_status.yml
64+
with:
65+
workflow_name: "Static code analysis"
66+
workflow_status: ${{ needs.scancode_job.result }}
67+
pr_number: ${{ github.event.pull_request.number }}
68+
permissions:
69+
pull-requests: write
70+
issues: write

.github/workflows/utest_auto_run.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,16 @@ jobs:
297297
echo "=========================================================================================="
298298
break
299299
fi
300-
done
300+
done
301+
# Post CI status to PR comment
302+
post-ci-status:
303+
needs: test
304+
if: always() && github.event_name == 'pull_request' && github.repository_owner == 'RT-Thread'
305+
uses: ./.github/workflows/post_ci_status.yml
306+
with:
307+
workflow_name: "utest_auto_run"
308+
workflow_status: ${{ needs.test.result }}
309+
pr_number: ${{ github.event.pull_request.number }}
310+
permissions:
311+
pull-requests: write
312+
issues: write

0 commit comments

Comments
 (0)