返回 DeepSeek-Reasonix
check-docs-impact.sh
根目录 / scripts / check-docs-impact.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 body="${DOCS_IMPACT_PR_BODY:-${PR_BODY:-}}"
5 if [ -n "${DOCS_IMPACT_PR_BODY_FILE:-}" ]; then
6 body="$(<"$DOCS_IMPACT_PR_BODY_FILE")"
7 fi
8
9 changed_input=""
10 if [ "$#" -gt 0 ]; then
11 changed_input="$(printf '%s\n' "$@")"
12 elif [ -n "${DOCS_IMPACT_CHANGED_FILES_FILE:-}" ]; then
13 changed_input="$(<"$DOCS_IMPACT_CHANGED_FILES_FILE")"
14 elif [ -n "${DOCS_IMPACT_CHANGED_FILES:-}" ]; then
15 changed_input="$DOCS_IMPACT_CHANGED_FILES"
16 else
17 base="${DOCS_IMPACT_BASE_SHA:-${BASE_SHA:-}}"
18 head="${DOCS_IMPACT_HEAD_SHA:-${HEAD_SHA:-HEAD}}"
19 if [ -z "$base" ]; then
20 base="$(git merge-base origin/main-v2 "$head" 2>/dev/null || git merge-base main-v2 "$head")"
21 fi
22 diff_base="$base"
23 if merge_base="$(git merge-base "$base" "$head" 2>/dev/null)"; then
24 diff_base="$merge_base"
25 fi
26 changed_input="$(git diff --name-only "$diff_base" "$head")"
27 fi
28
29 user_visible=()
30 docs_changed=()
31 while IFS= read -r file; do
32 [ -z "$file" ] && continue
33 case "$file" in
34 docs/*.md) docs_changed+=("$file") ;;
35 esac
36 case "$file" in
37 *_test.go|*.test.*|*.spec.*|*/__tests__/*|*/go.mod|*/go.sum|go.mod|go.sum|*/pnpm-lock.yaml|*/package-lock.json)
38 continue
39 ;;
40 esac
41 case "$file" in
42 cmd/reasonix/*|\
43 desktop/*|\
44 internal/agent/*|\
45 internal/boot/*|\
46 internal/cli/*|\
47 internal/config/*|\
48 internal/control/*|\
49 internal/history/*|\
50 internal/memory/*|\
51 internal/permission/*|\
52 internal/plugin/*|\
53 internal/productdocs/*|\
54 internal/provider/*|\
55 internal/recovery/*|\
56 internal/remote/*|\
57 internal/sandbox/*|\
58 internal/serve/*|\
59 internal/skill/*|\
60 internal/tool/*|\
61 npm/*|\
62 .goreleaser.yaml|\
63 scripts/desktop-build.sh)
64 user_visible+=("$file")
65 ;;
66 esac
67 done <<< "$changed_input"
68
69 if [ "${#user_visible[@]}" -eq 0 ]; then
70 echo "No user-visible product files changed; documentation impact check skipped."
71 exit 0
72 fi
73
74 line="$(printf '%s\n' "$body" | grep -Eim1 '^[[:space:]>#*_-]*Documentation-impact[[:space:]]*:' || true)"
75 value="${line#*:}"
76 value="${value#"${value%%[![:space:]]*}"}"
77 lower="$(printf '%s' "$value" | tr '[:upper:]' '[:lower:]')"
78
79 fail() {
80 echo "Documentation impact check failed: $1" >&2
81 echo "User-visible files:" >&2
82 printf ' - %s\n' "${user_visible[@]}" >&2
83 if [ "${#docs_changed[@]}" -gt 0 ]; then
84 echo "Embedded documentation files:" >&2
85 printf ' - %s\n' "${docs_changed[@]}" >&2
86 fi
87 echo "Required PR field:" >&2
88 echo " Documentation-impact: updated - <what changed>" >&2
89 echo " Documentation-impact: none - <why existing docs remain correct>" >&2
90 exit 1
91 }
92
93 [ -n "$line" ] || fail "missing Documentation-impact field"
94 if [ "${#docs_changed[@]}" -gt 0 ]; then
95 [[ "$lower" =~ ^updated[[:space:]]*[-:][[:space:]]*.+$ ]] || fail "docs/*.md changed, so Documentation-impact must explain what was updated"
96 else
97 [[ "$lower" =~ ^none[[:space:]]*[-:][[:space:]]*.+$ ]] || fail "no docs/*.md changed, so Documentation-impact must explain why none is required"
98 fi
99
100 echo "Documentation impact check passed: $value"
101
101 lines BASH