@@ -11,12 +11,42 @@ jobs:
11
11
- uses : actions/checkout@v4
12
12
with : { fetch-depth: 0 }
13
13
- name : Write step summary
14
+ shell : bash
14
15
run : |
15
16
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"
19
49
- name : Comment on PR (non-forks)
20
50
if : ${{ github.event.pull_request.head.repo.fork == false }}
21
51
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