-
Notifications
You must be signed in to change notification settings - Fork 66.8k
52 lines (47 loc) · 2.15 KB
/
pr-summary.yml
File metadata and controls
52 lines (47 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: PR summary
on:
pull_request: { types: [opened, synchronize, reopened, ready_for_review] }
permissions: { contents: read, pull-requests: write }
concurrency: { group: pr-summary-${{ github.ref }}, cancel-in-progress: true }
jobs:
summary:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: Write step summary
shell: bash
run: |
base="${{ github.base_ref }}"; head="${{ github.sha }}"
# Ensure local knowledge of the base ref; fetch if missing (tolerate failures)
if ! git rev-parse --verify "origin/$base" >/dev/null 2>&1; then
git fetch --no-tags --depth=1 origin "$base" || echo "WARN: could not fetch origin/$base" >&2
fi
changed_count=0
docs_count=0
file_list=""
if git rev-parse --verify "origin/$base" >/dev/null 2>&1; then
base_commit="$(git rev-parse "origin/$base" 2>/dev/null || echo "")"
if [ -n "$base_commit" ]; then
# Use diff-tree for robust listing between base and head
file_list="$(git diff-tree --no-commit-id --name-only -r "$base_commit" "$head" 2>/dev/null || echo "")"
else
echo "WARN: empty base commit for origin/$base" >&2
fi
else
echo "WARN: origin/$base not available; counts default to 0" >&2
fi
if [ -n "$file_list" ]; then
changed_count="$(printf "%s\n" "$file_list" | sed '/^$/d' | wc -l | tr -d ' ')"
docs_count="$(printf "%s\n" "$file_list" | grep -E '^content/.*\.md$' | wc -l | tr -d ' ' || true)"
fi
{
echo "## Pull request summary"
echo "- Changed files: $changed_count"
echo "- Docs content markdown files (regex ^content/.*\\.md$): $docs_count"
} >> "$GITHUB_STEP_SUMMARY"
- name: Comment on PR (non-forks)
if: ${{ github.event.pull_request.head.repo.fork == false }}
env: { GH_TOKEN: ${{ github.token }} }
run: gh pr comment ${{ github.event.pull_request.number }} --body-file "$GITHUB_STEP_SUMMARY"