You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/scripts/verify-code-references.sh
+71-1Lines changed: 71 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -17,11 +17,41 @@ EXIT_CODE=0
17
17
TOTAL_REFS=0
18
18
VALID_REFS=0
19
19
INVALID_REFS=0
20
+
COMMENT_FILE=""
21
+
ERRORS_COLLECTED=""
22
+
23
+
# Parse arguments
24
+
while [[ $#-gt 0 ]];do
25
+
case$1in
26
+
--pr-comment)
27
+
COMMENT_FILE="$2"
28
+
shift 2
29
+
;;
30
+
*)
31
+
echo"Unknown option: $1"
32
+
exit 1
33
+
;;
34
+
esac
35
+
done
20
36
21
37
echo"Verifying code references in documentation..."
22
38
echo"Repository root: ${REPO_ROOT}"
39
+
if [[ -n"${COMMENT_FILE}" ]];then
40
+
echo"PR comment mode: will write to ${COMMENT_FILE}"
41
+
fi
23
42
echo""
24
43
44
+
# Function to add error to collection
45
+
add_error() {
46
+
local error_msg="$1"
47
+
if [[ -z"${ERRORS_COLLECTED}" ]];then
48
+
ERRORS_COLLECTED="${error_msg}"
49
+
else
50
+
ERRORS_COLLECTED="${ERRORS_COLLECTED}
51
+
${error_msg}"
52
+
fi
53
+
}
54
+
25
55
# Find all markdown files with CODE_REFERENCE comments
26
56
while IFS= read -r doc_file;do
27
57
# Extract CODE_REFERENCE comments from this file
@@ -41,11 +71,15 @@ while IFS= read -r doc_file; do
41
71
42
72
TOTAL_REFS=$((TOTAL_REFS +1))
43
73
74
+
# Get relative path for documentation file
75
+
doc_file_rel="${doc_file#"${REPO_ROOT}"/}"
76
+
44
77
# Check if the source file exists
45
78
source_file="${REPO_ROOT}/${file_path}"
46
79
if [[ !-f"$source_file" ]];then
47
80
echo -e "${RED}✗${NC} Invalid reference in ${doc_file}:${line_num}"
48
81
echo" File not found: ${file_path}"
82
+
add_error "- **${doc_file_rel}:${line_num}** - File not found: \`${file_path}\`"
49
83
INVALID_REFS=$((INVALID_REFS +1))
50
84
EXIT_CODE=1
51
85
continue
@@ -57,6 +91,7 @@ while IFS= read -r doc_file; do
57
91
echo -e "${RED}✗${NC} Invalid reference in ${doc_file}:${line_num}"
58
92
echo" Line range L${start_line}-L${end_line} exceeds file length (${total_lines} lines)"
59
93
echo" File: ${file_path}"
94
+
add_error "- **${doc_file_rel}:${line_num}** - Line range L${start_line}-L${end_line} exceeds file length (${total_lines} lines) in \`${file_path}\`"
60
95
INVALID_REFS=$((INVALID_REFS +1))
61
96
EXIT_CODE=1
62
97
continue
@@ -102,25 +137,29 @@ while IFS= read -r doc_file; do
102
137
echo"${file_path}#L${start_line}-L${end_line}"
103
138
echo" Local code differs from GitHub (${branch})"
104
139
echo" This may indicate uncommitted changes or branch divergence"
140
+
add_error "- **${doc_file_rel}:${line_num}** - Code reference to \`${file_path}#L${start_line}-L${end_line}\` differs from GitHub (\`${branch}\` branch). The referenced code may have been modified locally but not yet merged to \`${branch}\`."
105
141
INVALID_REFS=$((INVALID_REFS +1))
106
142
EXIT_CODE=1
107
143
fi
108
144
else
109
145
echo-e"${YELLOW}⚠${NC} Could not parse GitHub URL in ${doc_file}:${line_num}"
110
146
echo" URL: ${github_url}"
147
+
add_error "- **${doc_file_rel}:${line_num}** - Could not parse GitHub URL: \`${github_url}\`"
111
148
INVALID_REFS=$((INVALID_REFS +1))
112
149
EXIT_CODE=1
113
150
fi
114
151
else
115
152
echo-e"${YELLOW}⚠${NC} Mismatched line range in ${doc_file}:${line_num}"
add_error "- **${doc_file_rel}:${line_num}** - CODE_REFERENCE comment specifies L${start_line}-L${end_line} but GitHub URL has different line range"
118
156
INVALID_REFS=$((INVALID_REFS +1))
119
157
EXIT_CODE=1
120
158
fi
121
159
else
122
160
echo-e"${YELLOW}⚠${NC} No GitHub URL found for reference in ${doc_file}:${line_num}"
123
161
echo" Expected rust reference block with GitHub URL"
162
+
add_error "- **${doc_file_rel}:${line_num}** - No GitHub URL found for reference (expected rust reference block with GitHub URL)"
124
163
INVALID_REFS=$((INVALID_REFS +1))
125
164
EXIT_CODE=1
126
165
fi
@@ -145,6 +184,37 @@ if [[ $EXIT_CODE -eq 0 ]]; then
145
184
echo -e "${GREEN}✓ All code references are valid!${NC}"
146
185
else
147
186
echo -e "${RED}✗ Some code references are invalid. Please update the documentation.${NC}"
187
+
188
+
# If in PR comment mode, write the comment to file
189
+
if [[ -n"${COMMENT_FILE}" ]];then
190
+
cat >"${COMMENT_FILE}"<<EOF
191
+
## ⚠️ Code Reference Verification Failed
192
+
193
+
The documentation contains code references that do not match the current state of the codebase on the \`develop\` branch.
194
+
195
+
### Issues Found
196
+
197
+
${ERRORS_COLLECTED}
198
+
199
+
### Action Required
200
+
201
+
**The code referenced in the documentation must be merged to \`develop\` before documentation can be added/modified.**
202
+
203
+
Please follow this workflow:
204
+
1. Merge the code changes to \`develop\` first (this PR or a separate code PR)
205
+
2. Create a follow-up PR with the documentation updates that reference the merged code
206
+
3. The verification will pass once the code is available on \`develop\`
207
+
208
+
See the [documentation guidelines](https://o1-labs.github.io/mina-rust/developers/documentation-guidelines) for more information about the two-PR workflow.
209
+
EOF
210
+
echo""
211
+
echo"PR comment written to: ${COMMENT_FILE}"
212
+
fi
148
213
fi
149
214
150
-
exit$EXIT_CODE
215
+
# In PR comment mode, don't fail the workflow - just post the comment
0 commit comments