Skip to content

Commit f7e8e86

Browse files
committed
Update pr-summary.yml with new content
1 parent 5aff31b commit f7e8e86

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

.github/workflows/pr-summary.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,42 @@ jobs:
1111
- uses: actions/checkout@v4
1212
with: { fetch-depth: 0 }
1313
- name: Write step summary
14+
shell: bash
1415
run: |
1516
base="${{ github.base_ref }}"; head="${{ github.sha }}"
16-
echo "## Pull request summary" >> "$GITHUB_STEP_SUMMARY"
17-
echo "- Changed files: $(git diff-tree --no-commit-id --name-only -r $head ^origin/$base | wc -l)" >> "$GITHUB_STEP_SUMMARY"
18-
echo "- Docs files: $(git diff-tree --no-commit-id --name-only -r $head ^origin/$base | grep -E '(^content/|\\.md$)' | wc -l)" >> "$GITHUB_STEP_SUMMARY"
17+
18+
# Ensure local knowledge of the base ref; fetch if missing (tolerate failures)
19+
if ! git rev-parse --verify "origin/$base" >/dev/null 2>&1; then
20+
git fetch --no-tags --depth=1 origin "$base" || echo "WARN: could not fetch origin/$base" >&2
21+
fi
22+
23+
changed_count=0
24+
docs_count=0
25+
file_list=""
26+
27+
if git rev-parse --verify "origin/$base" >/dev/null 2>&1; then
28+
base_commit="$(git rev-parse "origin/$base" 2>/dev/null || echo "")"
29+
if [ -n "$base_commit" ]; then
30+
# Use diff-tree for robust listing between base and head
31+
file_list="$(git diff-tree --no-commit-id --name-only -r "$base_commit" "$head" 2>/dev/null || echo "")"
32+
else
33+
echo "WARN: empty base commit for origin/$base" >&2
34+
fi
35+
else
36+
echo "WARN: origin/$base not available; counts default to 0" >&2
37+
fi
38+
39+
if [ -n "$file_list" ]; then
40+
changed_count="$(printf "%s\n" "$file_list" | sed '/^$/d' | wc -l | tr -d ' ')"
41+
docs_count="$(printf "%s\n" "$file_list" | grep -E '^content/.*\.md$' | wc -l | tr -d ' ' || true)"
42+
fi
43+
44+
{
45+
echo "## Pull request summary"
46+
echo "- Changed files: $changed_count"
47+
echo "- Docs content markdown files (regex ^content/.*\\.md$): $docs_count"
48+
} >> "$GITHUB_STEP_SUMMARY"
1949
- name: Comment on PR (non-forks)
2050
if: ${{ github.event.pull_request.head.repo.fork == false }}
2151
env: { GH_TOKEN: ${{ github.token }} }
22-
run: gh pr comment ${{ github.event.pull_request.number }} --body-file "$GITHUB_STEP_SUMMARY"
52+
run: gh pr comment ${{ github.event.pull_request.number }} --body-file "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)