Skip to content

Commit 8b4cb31

Browse files
committed
refactor: split diff output into collapsible per-file sections
1 parent 5336245 commit 8b4cb31

File tree

2 files changed

+59
-35
lines changed

2 files changed

+59
-35
lines changed

.github/workflows/diff_headers.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,7 @@ jobs:
2121
- uses: actions/checkout@v3
2222

2323
- name: Diff headers
24-
id: diff
25-
run: |
26-
bash scripts/diff.sh ${{ inputs.base-version }} ${{ inputs.target-version }}
27-
shell: bash
28-
29-
- name: Upload diff artifact
30-
if: steps.diff.outputs.DIFF_TOO_LARGE == 'true'
31-
uses: actions/upload-artifact@v4
32-
with:
33-
name: diff-${{ inputs.base-version }}-${{ inputs.target-version }}
34-
path: ${{ steps.diff.outputs.DIFF_FILE }}
35-
retention-days: 7
24+
run: bash scripts/diff.sh ${{ inputs.base-version }} ${{ inputs.target-version }}
3625
- name: Notification
3726
run: |
3827
URL=https://github.com/AgoraIO-Extensions/terra_shared_configs/actions/runs/${{ github.run_id }}

scripts/diff.sh

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,64 @@ TARGET=$2
77
BASE_PATH=headers/${BASE}/include
88
TARGET_PATH=headers/${TARGET}/include
99

10-
RESULT=$(diff -u -b -r ${BASE_PATH} ${TARGET_PATH})
11-
12-
retVal=$?
13-
if [ $retVal -eq 1 ]; then
14-
SUMMARY="\`\`\`diff"$'\n'$'\n'"${RESULT}"$'\n'"\`\`\`"
15-
16-
# GitHub step summary has a 1024KB limit
17-
MAX_SIZE=$((1000 * 1024)) # 1000KB to leave some margin
18-
SUMMARY_SIZE=${#SUMMARY}
19-
20-
if [ $SUMMARY_SIZE -gt $MAX_SIZE ]; then
21-
# Save full diff to file for artifact upload
22-
DIFF_FILE="diff_${BASE}_${TARGET}.txt"
23-
echo "${RESULT}" > "${DIFF_FILE}"
24-
echo "DIFF_FILE=${DIFF_FILE}" >> $GITHUB_OUTPUT
25-
echo "DIFF_TOO_LARGE=true" >> $GITHUB_OUTPUT
26-
27-
SUMMARY="## Diff between ${BASE} and ${TARGET}"$'\n'$'\n'"⚠️ **Diff output is too large (${SUMMARY_SIZE} bytes > 1024KB limit)**"$'\n'$'\n'"The full diff has been uploaded as an artifact. Please download it from the Artifacts section at the bottom of this page."
28-
fi
10+
# Get list of changed files
11+
CHANGED_FILES=$(diff -rq -b ${BASE_PATH} ${TARGET_PATH} | grep -E "^Files|^Only" || true)
2912

30-
# Output the github action summary.
31-
echo "${SUMMARY}" >> $GITHUB_STEP_SUMMARY
32-
exit 0;
13+
if [ -z "$CHANGED_FILES" ]; then
14+
echo "No diff found between ${BASE} and ${TARGET} headers." >> $GITHUB_STEP_SUMMARY
15+
exit 0
3316
fi
3417

35-
echo "No diff found between ${BASE} and ${TARGET} headers." >> $GITHUB_STEP_SUMMARY
18+
# Header
19+
echo "## Diff between ${BASE} and ${TARGET}" >> $GITHUB_STEP_SUMMARY
20+
echo "" >> $GITHUB_STEP_SUMMARY
21+
22+
# Process each file that differs
23+
MAX_CHUNK_SIZE=$((200 * 1024)) # 200KB per file chunk to stay safe
24+
CURRENT_SIZE=0
25+
26+
# Find files that exist in both but differ
27+
diff -rq -b ${BASE_PATH} ${TARGET_PATH} 2>/dev/null | while read -r line; do
28+
if [[ "$line" == Files* ]]; then
29+
# Extract file paths: "Files path1 and path2 differ"
30+
FILE1=$(echo "$line" | awk '{print $2}')
31+
FILE2=$(echo "$line" | awk '{print $4}')
32+
FILENAME=$(basename "$FILE1")
33+
34+
FILE_DIFF=$(diff -u -b "$FILE1" "$FILE2" 2>/dev/null || true)
35+
FILE_DIFF_SIZE=${#FILE_DIFF}
36+
37+
# Check if adding this would exceed limit
38+
NEW_SIZE=$((CURRENT_SIZE + FILE_DIFF_SIZE + 100))
39+
40+
if [ $NEW_SIZE -gt $MAX_CHUNK_SIZE ]; then
41+
# Start a new summary section
42+
echo "" >> $GITHUB_STEP_SUMMARY
43+
echo "---" >> $GITHUB_STEP_SUMMARY
44+
echo "" >> $GITHUB_STEP_SUMMARY
45+
CURRENT_SIZE=0
46+
fi
47+
48+
echo "<details>" >> $GITHUB_STEP_SUMMARY
49+
echo "<summary>📄 ${FILENAME}</summary>" >> $GITHUB_STEP_SUMMARY
50+
echo "" >> $GITHUB_STEP_SUMMARY
51+
echo '```diff' >> $GITHUB_STEP_SUMMARY
52+
echo "$FILE_DIFF" >> $GITHUB_STEP_SUMMARY
53+
echo '```' >> $GITHUB_STEP_SUMMARY
54+
echo "</details>" >> $GITHUB_STEP_SUMMARY
55+
echo "" >> $GITHUB_STEP_SUMMARY
56+
57+
CURRENT_SIZE=$((CURRENT_SIZE + FILE_DIFF_SIZE + 100))
58+
59+
elif [[ "$line" == Only* ]]; then
60+
# Handle files only in one directory
61+
echo "<details>" >> $GITHUB_STEP_SUMMARY
62+
echo "<summary>🆕 ${line}</summary>" >> $GITHUB_STEP_SUMMARY
63+
echo "</details>" >> $GITHUB_STEP_SUMMARY
64+
echo "" >> $GITHUB_STEP_SUMMARY
65+
fi
66+
done
67+
68+
echo "" >> $GITHUB_STEP_SUMMARY
69+
echo "---" >> $GITHUB_STEP_SUMMARY
70+
echo "✅ Diff complete" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)