Skip to content

Commit 7ae6aab

Browse files
ci: Simplify doc preview note
The doc preview note seems to be too long. Try to simplify it. Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
1 parent f400ef9 commit 7ae6aab

1 file changed

Lines changed: 38 additions & 39 deletions

File tree

.github/actions/generate-docs-comment/action.yml

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,58 +40,57 @@ runs:
4040
build_timestamp="$BUILD_TIMESTAMP"
4141
commit_sha="$COMMIT_SHA"
4242
43-
cat << 'EOF' > comment.md
44-
## Documentation Preview
45-
46-
The documentation has been built successfully and is available for preview.
47-
48-
| Build Info | Value |
49-
|------------|-------|
50-
| **Generated at** | `$TIMESTAMP_PLACEHOLDER` |
51-
| **Commit** | `$COMMIT_PLACEHOLDER` |
52-
53-
### Preview Links
54-
55-
| Page | Preview Link |
56-
|------|--------------|
57-
| **Index (Home)** | [View Preview]($preview_url_placeholder/index.html) |
58-
EOF
59-
60-
# Replace placeholders with actual values
61-
sed -i "s|\$preview_url_placeholder|$preview_url|g" comment.md
62-
sed -i "s|\$TIMESTAMP_PLACEHOLDER|$build_timestamp|g" comment.md
63-
sed -i "s|\$COMMIT_PLACEHOLDER|$commit_sha|g" comment.md
43+
# Initialize comment.md file
44+
echo "## Documentation Preview" > comment.md
45+
echo "" >> comment.md
46+
echo "The documentation has been built successfully. You can view the preview here: [preview]($preview_url/index.html)" >> comment.md
47+
echo "" >> comment.md
48+
echo "**Generated at**: \`$build_timestamp\` with commit \`$commit_sha\`." >> comment.md
6449
6550
# Add links to changed files
66-
if [ "$changed_docs" != "[]" ] && [ -n "$changed_docs" ]; then
51+
# Parse JSON and get count of items
52+
doc_count=$(echo "$changed_docs" | jq -r 'if type == "array" then length else 0 end' 2>/dev/null || echo "0")
53+
54+
# Always show details section to ensure GitHub renders it
55+
# Check if we have any files to show
56+
has_files=false
57+
if [ "$doc_count" != "0" ] && [ "$doc_count" != "null" ] && [ -n "$doc_count" ]; then
58+
# Verify it's actually a number and > 0
59+
if [ "$doc_count" -gt 0 ] 2>/dev/null; then
60+
has_files=true
61+
fi
62+
fi
63+
64+
echo "" >> comment.md
65+
echo "<details>" >> comment.md
66+
echo "<summary>Expand to view changed pages</summary>" >> comment.md
67+
echo "" >> comment.md
68+
69+
if [ "$has_files" = "true" ]; then
6770
echo "" >> comment.md
68-
echo "### Changed Pages" >> comment.md
6971
echo "" >> comment.md
70-
echo "| Source File | Preview Link |" >> comment.md
71-
echo "|-------------|--------------|" >> comment.md
72-
73-
echo "$changed_docs" | jq -r '.[]' | while read -r file; do
74-
if [ -n "$file" ]; then
75-
# Convert .rst/.md path to .html path
76-
# Remove 'docs/' prefix and change extension
72+
echo "| File | Preview |" >> comment.md
73+
echo "| ---- | ------- |" >> comment.md
74+
while IFS= read -r file; do
75+
if [ -n "$file" ] && [ "$file" != "null" ]; then
7776
html_path=$(echo "$file" | sed 's|^docs/||' | sed 's|\.rst$|.html|' | sed 's|\.md$|.html|')
78-
# Handle index files in subdirectories
7977
if [[ "$html_path" == */index.html ]]; then
8078
html_path="${html_path}"
8179
fi
82-
filename=$(basename "$file")
8380
echo "| \`$file\` | [View]($preview_url/$html_path) |" >> comment.md
8481
fi
85-
done
82+
done < <(echo "$changed_docs" | jq -r '.[]' 2>/dev/null)
83+
else
84+
echo "No documentation files were changed in this PR." >> comment.md
8685
fi
8786
88-
cat << 'EOF' >> comment.md
89-
90-
---
87+
echo "" >> comment.md
88+
echo "</details>" >> comment.md
9189
92-
> **Note:** The preview will be available after GitHub Pages deployment completes (usually 1-2 minutes).
93-
> If you see stale content, hard-refresh your browser (Ctrl+Shift+R) or wait a moment for GitHub Pages to update.
94-
EOF
90+
echo "" >> comment.md
91+
echo "---" >> comment.md
92+
echo "" >> comment.md
93+
echo "> **Note:** The preview will be available after GitHub Pages deployment completes (usually 1-2 minutes). Ensure that **generated at** timestamp is up to date. If you see stale content, hard-refresh your browser (Ctrl+Shift+R) or wait a moment for GitHub Pages to update." >> comment.md
9594
9695
echo "Comment content:"
9796
cat comment.md

0 commit comments

Comments
 (0)