@@ -17,11 +17,41 @@ EXIT_CODE=0
1717TOTAL_REFS=0
1818VALID_REFS=0
1919INVALID_REFS=0
20+ COMMENT_FILE=" "
21+ ERRORS_COLLECTED=" "
22+
23+ # Parse arguments
24+ while [[ $# -gt 0 ]]; do
25+ case $1 in
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
2036
2137echo " Verifying code references in documentation..."
2238echo " Repository root: ${REPO_ROOT} "
39+ if [[ -n " ${COMMENT_FILE} " ]]; then
40+ echo " PR comment mode: will write to ${COMMENT_FILE} "
41+ fi
2342echo " "
2443
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+
2555# Find all markdown files with CODE_REFERENCE comments
2656while IFS= read -r doc_file; do
2757 # Extract CODE_REFERENCE comments from this file
@@ -41,11 +71,16 @@ while IFS= read -r doc_file; do
4171
4272 TOTAL_REFS= $(( TOTAL_REFS + 1 ))
4373
74+ # Get relative path for documentation file
75+ doc_file_rel= " ${doc_file# " ${REPO_ROOT} " / } "
76+
4477 # Check if the source file exists
4578 source_file= " ${REPO_ROOT} /${file_path} "
4679 if [[ ! -f " $source_file " ]]; then
4780 echo -e " ${RED} ✗${NC} Invalid reference in ${doc_file} :${line_num} "
4881 echo " File not found: ${file_path} "
82+ add_error " - **${doc_file_rel} :${line_num} ** - File not found:
83+ \` ${file_path} \` "
4984 INVALID_REFS=$(( INVALID_REFS + 1 ))
5085 EXIT_CODE=1
5186 continue
@@ -57,6 +92,9 @@ while IFS= read -r doc_file; do
5792 echo -e " ${RED} ✗${NC} Invalid reference in ${doc_file} :${line_num} "
5893 echo " Line range L${start_line} -L${end_line} exceeds file length (${total_lines} lines)"
5994 echo " File: ${file_path} "
95+ add_error " - **${doc_file_rel} :${line_num} ** - Line range
96+ L${start_line} -L${end_line} exceeds file length (${total_lines} lines) in
97+ \` ${file_path} \` "
6098 INVALID_REFS=$(( INVALID_REFS + 1 ))
6199 EXIT_CODE=1
62100 continue
@@ -102,25 +140,35 @@ while IFS= read -r doc_file; do
102140 echo " ${file_path} #L${start_line} -L${end_line} "
103141 echo " Local code differs from GitHub (${branch} )"
104142 echo " This may indicate uncommitted changes or branch divergence"
143+ add_error " - **${doc_file_rel} :${line_num} ** - Code reference to
144+ \` ${file_path} #L${start_line} -L${end_line} \` differs from GitHub
145+ (\` ${branch} \` branch). The referenced code may have been modified locally
146+ but not yet merged to \` ${branch} \` ."
105147 INVALID_REFS=$(( INVALID_REFS + 1 ))
106148 EXIT_CODE=1
107149 fi
108150 else
109151 echo -e " ${YELLOW} ⚠${NC} Could not parse GitHub URL in ${doc_file} :${line_num} "
110152 echo " URL: ${github_url} "
153+ add_error " - **${doc_file_rel} :${line_num} ** - Could not parse GitHub URL:
154+ \` ${github_url} \` "
111155 INVALID_REFS= $(( INVALID_REFS + 1 ))
112156 EXIT_CODE= 1
113157 fi
114158 else
115159 echo -e " ${YELLOW} ⚠${NC} Mismatched line range in ${doc_file} :${line_num} "
116160 echo " CODE_REFERENCE comment specifies: L${start_line} -L${end_line} "
117161 echo " But GitHub URL has different line range"
162+ add_error " - **${doc_file_rel} :${line_num} ** - CODE_REFERENCE comment specifies
163+ L${start_line} -L${end_line} but GitHub URL has different line range"
118164 INVALID_REFS= $(( INVALID_REFS + 1 ))
119165 EXIT_CODE= 1
120166 fi
121167 else
122168 echo -e " ${YELLOW} ⚠${NC} No GitHub URL found for reference in ${doc_file} :${line_num} "
123169 echo " Expected rust reference block with GitHub URL"
170+ add_error " - **${doc_file_rel} :${line_num} ** - No GitHub URL found for reference
171+ (expected rust reference block with GitHub URL)"
124172 INVALID_REFS= $(( INVALID_REFS + 1 ))
125173 EXIT_CODE= 1
126174 fi
@@ -145,6 +193,43 @@ if [[ $EXIT_CODE -eq 0 ]]; then
145193 echo -e " ${GREEN} ✓ All code references are valid!${NC} "
146194else
147195 echo -e " ${RED} ✗ Some code references are invalid. Please update the documentation.${NC} "
196+
197+ # If in PR comment mode, write the comment to file
198+ if [[ -n " ${COMMENT_FILE} " ]]; then
199+ cat > " ${COMMENT_FILE} " << EOF
200+ ## ⚠️ Code Reference Verification Failed
201+
202+ The documentation contains code references that do not match the current
203+ state of the codebase on the \` develop\` branch.
204+
205+ ### Issues Found
206+
207+ ${ERRORS_COLLECTED}
208+
209+ ### Action Required
210+
211+ **The code referenced in the documentation must be merged to \` develop\`
212+ before documentation can be added.**
213+
214+ Please follow this workflow:
215+ 1. Merge the code changes to \` develop\` first (this PR or a separate code
216+ PR)
217+ 2. Wait for the code PR to be merged
218+ 3. Create a follow-up PR with the documentation updates that reference the
219+ merged code
220+ 4. The verification will pass once the code is available on \` develop\`
221+
222+ See the [documentation guidelines](https://github.com/o1-labs/mina-rust/blob/develop/website/docs/developers/documentation-guidelines.md)
223+ for more information about the two-PR workflow.
224+ EOF
225+ echo " "
226+ echo " PR comment written to: ${COMMENT_FILE} "
227+ fi
148228fi
149229
150- exit $EXIT_CODE
230+ # In PR comment mode, don't fail the workflow - just post the comment
231+ if [[ -n " ${COMMENT_FILE} " ]]; then
232+ exit 0
233+ else
234+ exit $EXIT_CODE
235+ fi
0 commit comments