Skip to content

Commit 209c241

Browse files
committed
CI: Add commit hash link to test result comments
This displays git commit hash (short) with clickable link to GitHub commit in pull request test result comments for easier traceability.
1 parent 3a3de1c commit 209c241

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

.ci/ci-tools.sh

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ show_help() {
1111
Usage: $SCRIPT_NAME <command> [options]
1212
1313
Commands:
14-
collect-data <toolchain> <test_output> [functional_output]
14+
collect-data <toolchain> <commit_sha> <commit_short> <github_repo> <test_output> [functional_output]
1515
Extract and store test data from CI outputs
1616
1717
aggregate <results_dir> <output_file>
@@ -27,7 +27,7 @@ Commands:
2727
Print clean TOML report
2828
2929
Examples:
30-
$SCRIPT_NAME collect-data gnu "\$test_output" "\$functional_output"
30+
$SCRIPT_NAME collect-data gnu "\$COMMIT_SHA" "\$COMMIT_SHORT" "\$GITHUB_REPO" "\$test_output" "\$functional_output"
3131
$SCRIPT_NAME aggregate all-test-results test-summary.toml
3232
$SCRIPT_NAME format-comment test-summary.toml
3333
$SCRIPT_NAME post-comment test-summary.toml 123
@@ -38,8 +38,11 @@ EOF
3838
# Data collection function
3939
collect_data() {
4040
local toolchain=${1:-unknown}
41-
local test_output=${2:-}
42-
local functional_output=${3:-}
41+
local commit_sha=${2:-}
42+
local commit_short=${3:-}
43+
local github_repo=${4:-}
44+
local test_output=${5:-}
45+
local functional_output=${6:-}
4346

4447
if [ -z "$test_output" ]; then
4548
echo "Error: test_output required"
@@ -48,6 +51,9 @@ collect_data() {
4851

4952
mkdir -p test-results
5053
echo "$toolchain" > test-results/toolchain
54+
echo "$commit_sha" > test-results/commit_sha
55+
echo "$commit_short" > test-results/commit_short
56+
echo "$github_repo" > test-results/github_repo
5157

5258
# Extract app data
5359
echo "$test_output" | grep "APP_STATUS:" | sed 's/APP_STATUS://' > test-results/apps_data || touch test-results/apps_data
@@ -103,6 +109,7 @@ aggregate_results() {
103109
llvm_build="failed" llvm_crash="failed" llvm_functional="failed"
104110
overall="failed"
105111
apps_data="" functional_data="" functional_criteria_data=""
112+
commit_sha="" commit_short="" github_repo=""
106113

107114
# Process artifacts
108115
for artifact_dir in "$results_dir"/test-results-*; do
@@ -112,6 +119,13 @@ aggregate_results() {
112119
crash_exit=$(cat "$artifact_dir/crash_exit_code" 2> /dev/null || echo "1")
113120
functional_exit=$(cat "$artifact_dir/functional_exit_code" 2> /dev/null || echo "1")
114121

122+
# Read commit info from first artifact (same across all toolchains)
123+
if [ -z "$commit_sha" ]; then
124+
commit_sha=$(cat "$artifact_dir/commit_sha" 2> /dev/null || echo "")
125+
commit_short=$(cat "$artifact_dir/commit_short" 2> /dev/null || echo "")
126+
github_repo=$(cat "$artifact_dir/github_repo" 2> /dev/null || echo "")
127+
fi
128+
115129
build_status="passed"
116130
# Handle skipped tests
117131
if [ "$crash_exit" = "skipped" ]; then
@@ -174,6 +188,9 @@ aggregate_results() {
174188
[summary]
175189
status = "$overall"
176190
timestamp = "$(date -Iseconds)"
191+
commit_sha = "$commit_sha"
192+
commit_short = "$commit_short"
193+
github_repo = "$github_repo"
177194
178195
[info]
179196
architecture = "riscv32"
@@ -275,6 +292,9 @@ format_comment() {
275292
# Extract basic info
276293
overall_status=$(get_value "summary" "status" "$toml_file")
277294
timestamp=$(get_value "summary" "timestamp" "$toml_file")
295+
commit_sha=$(get_value "summary" "commit_sha" "$toml_file")
296+
commit_short=$(get_value "summary" "commit_short" "$toml_file")
297+
github_repo=$(get_value "summary" "github_repo" "$toml_file")
278298
gnu_build=$(get_value "gnu" "build" "$toml_file")
279299
gnu_crash=$(get_value "gnu" "crash" "$toml_file")
280300
gnu_functional=$(get_value "gnu" "functional" "$toml_file")
@@ -283,11 +303,21 @@ format_comment() {
283303
llvm_functional=$(get_value "llvm" "functional" "$toml_file")
284304

285305
# Generate comment
306+
# Build commit link if we have repo and SHA
307+
commit_info=""
308+
if [ -n "$github_repo" ] && [ -n "$commit_sha" ] && [ -n "$commit_short" ]; then
309+
commit_url="https://github.com/$github_repo/commit/$commit_sha"
310+
commit_info="**Commit:** [\`$commit_short\`]($commit_url)"
311+
else
312+
commit_info="**Commit:** (not available)"
313+
fi
314+
286315
cat << EOF
287316
## Linmo CI Test Results
288317
289318
**Overall Status:** $(get_symbol "$overall_status") $overall_status
290319
**Timestamp:** $timestamp
320+
$commit_info
291321
292322
### Toolchain Results
293323

.github/workflows/ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,17 @@ jobs:
136136
if: always()
137137
run: |
138138
set -euo pipefail
139+
COMMIT_SHA="${{ github.sha }}"
140+
COMMIT_SHORT=$(git rev-parse --short HEAD 2>/dev/null || echo "${{ github.sha }}" | cut -c1-7)
141+
GITHUB_REPO="${{ github.repository }}"
142+
139143
if [ "${{ matrix.toolchain }}" = "llvm" ]; then
140144
# LLVM: Build-only validation, skip tests
141145
mkdir -p test-results
142146
echo "${{ matrix.toolchain }}" > test-results/toolchain
147+
echo "$COMMIT_SHA" > test-results/commit_sha
148+
echo "$COMMIT_SHORT" > test-results/commit_short
149+
echo "$GITHUB_REPO" > test-results/github_repo
143150
echo "skipped" > test-results/crash_exit_code
144151
echo "skipped" > test-results/functional_exit_code
145152
@@ -163,7 +170,7 @@ jobs:
163170
echo "LLVM toolchain: Build validation only (tests skipped)"
164171
else
165172
# GNU: Full test suite
166-
.ci/ci-tools.sh collect-data "${{ matrix.toolchain }}" "${{ steps.test.outputs.TEST_OUTPUT }}" "${{ steps.functional_test.outputs.FUNCTIONAL_TEST_OUTPUT }}"
173+
.ci/ci-tools.sh collect-data "${{ matrix.toolchain }}" "$COMMIT_SHA" "$COMMIT_SHORT" "$GITHUB_REPO" "${{ steps.test.outputs.TEST_OUTPUT }}" "${{ steps.functional_test.outputs.FUNCTIONAL_TEST_OUTPUT }}"
167174
fi
168175
169176
- name: Upload Test Results

0 commit comments

Comments
 (0)