Skip to content

Commit d6c16fb

Browse files
Copilotdannywillems
andcommitted
Remove legacy format support from CI script
Updated .github/scripts/check-ocaml-refs.sh to only support the new hyperlink format. Removed all legacy multi-line format parsing and validation code. Changes: - Removed legacy format detection (lines 69, 190-290, 333-350) - Simplified script from 367 to 243 lines - Updated header comment to reflect hyperlink-only support - Updated documentation to remove backward compatibility mention The script now exclusively validates: /// OCaml: <https://github.com/MinaProtocol/mina/blob/COMMIT/path#L1-L10> Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
1 parent 0d85410 commit d6c16fb

File tree

2 files changed

+8
-133
lines changed

2 files changed

+8
-133
lines changed

.github/scripts/check-ocaml-refs.sh

Lines changed: 6 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# Script to validate OCaml reference comments in Rust code
33
# Usage: ./.github/scripts/check-ocaml-refs.sh [--repo REPO_URL] [--branch BRANCH] [--update]
44
#
5-
# Supports two formats:
6-
# 1. New hyperlink format: /// OCaml: <https://github.com/MinaProtocol/mina/blob/COMMIT/path#L1-L10>
7-
# 2. Legacy multi-line format (deprecated): /// OCaml reference: path L:1-10
5+
# Supports hyperlink format: /// OCaml: <https://github.com/MinaProtocol/mina/blob/COMMIT/path#L1-L10>
86

97
set -euo pipefail
108

@@ -64,11 +62,9 @@ fi
6462

6563
echo "Current OCaml commit: ${CURRENT_COMMIT}"
6664

67-
# Find all Rust files with OCaml references (both formats)
65+
# Find all Rust files with OCaml references
6866
cd "${RUST_ROOT}"
69-
RUST_FILES_OLD=$(git grep -l -E "^/// OCaml reference:" "*.rs" "**/*.rs" 2>/dev/null || true)
70-
RUST_FILES_NEW=$(git grep -l -E "^/// OCaml: <https://github.com/MinaProtocol/mina/blob/" "*.rs" "**/*.rs" 2>/dev/null || true)
71-
RUST_FILES=$(echo -e "${RUST_FILES_OLD}\n${RUST_FILES_NEW}" | sort -u | grep -v '^$' || true)
67+
RUST_FILES=$(git grep -l -E "^/// OCaml: <https://github.com/MinaProtocol/mina/blob/" "*.rs" "**/*.rs" 2>/dev/null || true)
7268

7369
if [ -z "$RUST_FILES" ]; then
7470
echo "No OCaml references found in Rust code"
@@ -85,7 +81,7 @@ echo "========================"
8581

8682
# Process each file
8783
echo "$RUST_FILES" | while IFS= read -r rust_file; do
88-
# Process new hyperlink format: /// OCaml: <URL>
84+
# Process hyperlink format: /// OCaml: <URL>
8985
grep -n "^/// OCaml: <https://github.com/MinaProtocol/mina/blob/" "$rust_file" 2>/dev/null | while IFS=: read -r line_num line_content; do
9086
# Extract URL from angle brackets
9187
URL=$(echo "$line_content" | sed -n 's/.*<\(https:\/\/github\.com\/MinaProtocol\/mina\/blob\/[^>]*\)>.*/\1/p')
@@ -186,110 +182,6 @@ echo "$RUST_FILES" | while IFS= read -r rust_file; do
186182
fi
187183
fi
188184
done
189-
190-
# Process legacy multi-line format (for backward compatibility)
191-
awk '
192-
/^\/\/\/ OCaml reference:/ {
193-
line_num = NR
194-
ref = $0
195-
getline
196-
if ($0 ~ /^\/\/\/ Commit:/) {
197-
commit = $0
198-
getline
199-
if ($0 ~ /^\/\/\/ Last verified:/) {
200-
verified = $0
201-
print line_num "|" ref
202-
print commit
203-
print verified
204-
print "---"
205-
}
206-
}
207-
}
208-
' "$rust_file" | while IFS= read -r line; do
209-
if [[ "$line" == *"|/// OCaml reference:"* ]]; then
210-
# Extract file path and line range
211-
LINE_NUM=$(echo "$line" | cut -d'|' -f1)
212-
FULL_REF="${line#*|/// OCaml reference: }"
213-
OCAML_PATH="${FULL_REF%% L:*}"
214-
LINE_RANGE=$(echo "$FULL_REF" | grep -o 'L:[0-9-]*' | sed 's/L://' || echo "")
215-
216-
# Read next two lines
217-
read -r commit_line
218-
read -r _verified_line
219-
read -r _separator
220-
221-
COMMIT="${commit_line#/// Commit: }"
222-
223-
# Fetch the OCaml file from the current branch
224-
CURRENT_FILE="${TEMP_DIR}/current_legacy_${rust_file//\//_}_${OCAML_PATH//\//_}"
225-
CURRENT_URL="https://raw.githubusercontent.com/${GITHUB_OWNER}/${GITHUB_REPO}/${OCAML_BRANCH}/${OCAML_PATH}"
226-
227-
if ! curl -sf "$CURRENT_URL" -o "$CURRENT_FILE"; then
228-
echo "INVALID|${rust_file}|${OCAML_PATH}|FILE_NOT_FOUND|LEGACY_FORMAT" >> "$RESULTS_FILE"
229-
echo "❌ INVALID: ${rust_file}:${LINE_NUM} (LEGACY FORMAT)"
230-
echo " OCaml file not found: ${OCAML_PATH}"
231-
else
232-
# Validate line range if specified
233-
RANGE_VALID=true
234-
if [ -n "$LINE_RANGE" ]; then
235-
FILE_LINES=$(wc -l < "$CURRENT_FILE")
236-
END_LINE=$(echo "$LINE_RANGE" | cut -d'-' -f2)
237-
238-
if [ "$END_LINE" -gt "$FILE_LINES" ]; then
239-
echo "INVALID|${rust_file}|${OCAML_PATH}|LINE_RANGE_EXCEEDED|L:${LINE_RANGE}|${FILE_LINES}|LEGACY_FORMAT" >> "$RESULTS_FILE"
240-
echo "❌ INVALID: ${rust_file}:${LINE_NUM} (LEGACY FORMAT)"
241-
echo " Line range L:${LINE_RANGE} exceeds file length (${FILE_LINES} lines): ${OCAML_PATH}"
242-
RANGE_VALID=false
243-
fi
244-
fi
245-
246-
if [ "$RANGE_VALID" = "true" ]; then
247-
# Verify that the code at the referenced commit matches the current branch
248-
CODE_MATCHES=true
249-
if [ -n "$LINE_RANGE" ]; then
250-
START_LINE=$(echo "$LINE_RANGE" | cut -d'-' -f1)
251-
END_LINE=$(echo "$LINE_RANGE" | cut -d'-' -f2)
252-
253-
# Fetch the file from the referenced commit
254-
COMMIT_FILE="${TEMP_DIR}/commit_legacy_${rust_file//\//_}_${OCAML_PATH//\//_}"
255-
COMMIT_URL="https://raw.githubusercontent.com/${GITHUB_OWNER}/${GITHUB_REPO}/${COMMIT}/${OCAML_PATH}"
256-
257-
if ! curl -sf "$COMMIT_URL" -o "$COMMIT_FILE"; then
258-
echo "INVALID|${rust_file}|${OCAML_PATH}|COMMIT_NOT_FOUND|${COMMIT}|LEGACY_FORMAT" >> "$RESULTS_FILE"
259-
echo "❌ INVALID: ${rust_file}:${LINE_NUM} (LEGACY FORMAT)"
260-
echo " Referenced commit does not exist: ${COMMIT}"
261-
CODE_MATCHES=false
262-
else
263-
# Extract the specific line ranges from both files and compare
264-
CURRENT_LINES=$(sed -n "${START_LINE},${END_LINE}p" "$CURRENT_FILE")
265-
COMMIT_LINES=$(sed -n "${START_LINE},${END_LINE}p" "$COMMIT_FILE")
266-
267-
if [ "$CURRENT_LINES" != "$COMMIT_LINES" ]; then
268-
echo "INVALID|${rust_file}|${OCAML_PATH}|CODE_MISMATCH|${COMMIT}|LEGACY_FORMAT" >> "$RESULTS_FILE"
269-
echo "❌ INVALID: ${rust_file}:${LINE_NUM} (LEGACY FORMAT)"
270-
echo " Code at L:${LINE_RANGE} differs between commit ${COMMIT} and current branch"
271-
echo " Referenced: https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/blob/${COMMIT}/${OCAML_PATH}#L${START_LINE}-L${END_LINE}"
272-
echo " Current: https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/blob/${OCAML_BRANCH}/${OCAML_PATH}#L${START_LINE}-L${END_LINE}"
273-
CODE_MATCHES=false
274-
fi
275-
fi
276-
fi
277-
278-
if [ "$CODE_MATCHES" = "true" ]; then
279-
# Check if commit is stale
280-
if [ "$COMMIT" != "$CURRENT_COMMIT" ]; then
281-
echo "STALE|${rust_file}|${LINE_NUM}|${OCAML_PATH}|${COMMIT}|${LINE_RANGE}|LEGACY_FORMAT" >> "$RESULTS_FILE"
282-
echo "✓ VALID: ${rust_file}:${LINE_NUM} (LEGACY FORMAT) -> ${OCAML_PATH} L:${LINE_RANGE}"
283-
echo " ⚠ STALE COMMIT: ${COMMIT} (current: ${CURRENT_COMMIT})"
284-
else
285-
echo "VALID|${rust_file}|${LINE_NUM}|${OCAML_PATH}|${LINE_RANGE}|LEGACY_FORMAT" >> "$RESULTS_FILE"
286-
echo "✓ VALID: ${rust_file}:${LINE_NUM} (LEGACY FORMAT) -> ${OCAML_PATH} L:${LINE_RANGE}"
287-
fi
288-
fi
289-
fi
290-
fi
291-
fi
292-
done
293185
done
294186

295187
# Count results
@@ -310,8 +202,8 @@ if [ "$UPDATE_MODE" = "true" ] && [ "${STALE_COMMITS}" -gt 0 ]; then
310202
echo ""
311203
echo "Updating stale commit hashes..."
312204

313-
# Update new hyperlink format
314-
grep "^STALE|" "$RESULTS_FILE" | grep -v "LEGACY_FORMAT" | while IFS='|' read -r _status rust_file line_num ocaml_path old_commit line_range _rest; do
205+
# Update hyperlink format
206+
grep "^STALE|" "$RESULTS_FILE" | while IFS='|' read -r _status rust_file line_num ocaml_path old_commit line_range; do
315207
echo "Updating ${rust_file}:${line_num}..."
316208

317209
# Build new URL
@@ -330,22 +222,6 @@ if [ "$UPDATE_MODE" = "true" ] && [ "${STALE_COMMITS}" -gt 0 ]; then
330222
sed -i "${line_num}s/blob\/${OLD_COMMIT_ESCAPED}\//blob\/${CURRENT_COMMIT_ESCAPED}\//" "${RUST_ROOT}/${rust_file}"
331223
done
332224

333-
# Update legacy multi-line format (for backward compatibility during transition)
334-
grep "^STALE|" "$RESULTS_FILE" | grep "LEGACY_FORMAT" | while IFS='|' read -r _status rust_file line_num ocaml_path old_commit line_range _legacy; do
335-
echo "Updating legacy format in ${rust_file}:${line_num}..."
336-
337-
CURRENT_DATE=$(date +%Y-%m-%d)
338-
339-
# Find and replace the old commit with the new one
340-
sed -i.bak \
341-
-e "/^\/\/\/ OCaml reference: ${ocaml_path//\//\\/}/,/^\/\/\/ Last verified:/ {
342-
s/^\/\/\/ Commit: .*/\/\/\/ Commit: ${CURRENT_COMMIT}/
343-
s/^\/\/\/ Last verified: .*/\/\/\/ Last verified: ${CURRENT_DATE}/
344-
}" \
345-
"${RUST_ROOT}/${rust_file}"
346-
rm -f "${RUST_ROOT}/${rust_file}.bak"
347-
done
348-
349225
echo "Updated ${STALE_COMMITS} reference(s)"
350226
fi
351227

website/docs/developers/ocaml-reference-tracking.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ https://github.com/MinaProtocol/mina/blob/<commit-hash>/<path>#L<start>-L<end>
5757

5858
## Validation script
5959

60-
The `.github/scripts/check-ocaml-refs.sh` script validates all OCaml references.
61-
It supports both the new hyperlink format and the legacy multi-line format (for
62-
backward compatibility during the transition period).
60+
The `.github/scripts/check-ocaml-refs.sh` script validates all OCaml references
61+
in the hyperlink format.
6362

6463
```bash
6564
# Validate against compatible branch (default)

0 commit comments

Comments
 (0)