Skip to content

Commit 3414681

Browse files
authored
Update test-doc-generator.yml
1 parent fbd33da commit 3414681

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

.github/workflows/test-doc-generator.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,57 @@ jobs:
6666
run: |
6767
echo "Identifying changes against branch: ${{ github.event.inputs.target_branch }}"
6868
# Read tracking files FROM THE CHECKED-OUT BRANCH
69-
PREV_HASHES=$(cat scripts/file_hashes.json)
70-
# Ensure processed_files.txt exists before sorting
71-
[ -f scripts/processed_files.txt ] || touch scripts/processed_files.txt
69+
PREV_HASHES_JSON_FILE="scripts/file_hashes.json"
70+
PROCESSED_FILES_LIST_FILE="scripts/processed_files.txt"
71+
72+
# Ensure tracking files exist
73+
[ -f "$PROCESSED_FILES_LIST_FILE" ] || touch "$PROCESSED_FILES_LIST_FILE"
74+
if ! [ -f "$PREV_HASHES_JSON_FILE" ]; then
75+
echo "{}" > "$PREV_HASHES_JSON_FILE"
76+
fi
77+
# Validate JSON structure
78+
if ! jq -e '.' "$PREV_HASHES_JSON_FILE" > /dev/null; then
79+
echo "Error: $PREV_HASHES_JSON_FILE is not valid JSON. Resetting to empty object."
80+
echo "{}" > "$PREV_HASHES_JSON_FILE"
81+
fi
82+
PREV_HASHES=$(cat "$PREV_HASHES_JSON_FILE")
7283
7384
# Find files present in latest_files.txt but not in processed_files.txt
74-
comm -23 <(sort latest_files.txt) <(sort scripts/processed_files.txt) > new_files.tmp || true
85+
comm -23 <(sort latest_files.txt) <(sort "$PROCESSED_FILES_LIST_FILE") > new_files.tmp || true
7586
echo "--- New Files ---"
7687
cat new_files.tmp
7788
echo "-----------------"
7889
7990
MODIFIED_FILES_LIST="modified_files.tmp"
8091
touch $MODIFIED_FILES_LIST
81-
echo "--- Checking for Modifications ---" >&2 # Debug output to stderr
92+
echo "--- Checking for Modifications (Enhanced Debug) ---" >&2 # Debug output to stderr
8293
while IFS=$'\t' read -r FILE_NAME FILE_SHA; do
8394
# Check if the file is listed in processed_files.txt (meaning it's not new)
84-
if grep -q -x -F "$FILE_NAME" scripts/processed_files.txt; then
95+
if grep -q -x -F "$FILE_NAME" "$PROCESSED_FILES_LIST_FILE"; then
96+
echo "DEBUG: Checking file found in processed list: '$FILE_NAME'" >&2
97+
# *** Corrected jq command to fetch previous SHA ***
8598
PREV_SHA=$(echo "$PREV_HASHES" | jq -r --arg file "$FILE_NAME" '.["$file"] // ""')
86-
echo "Checking: $FILE_NAME, Current SHA: $FILE_SHA, Previous SHA: $PREV_SHA" >&2
99+
echo "DEBUG: Current SHA from source: '$FILE_SHA'" >&2
100+
echo "DEBUG: Previous SHA from JSON : '$PREV_SHA'" >&2
101+
102+
# Check if PREV_SHA is not empty and differs from current FILE_SHA
87103
if [ -n "$PREV_SHA" ] && [ "$PREV_SHA" != "$FILE_SHA" ]; then
104+
echo "DEBUG: Comparison result: '$PREV_SHA' != '$FILE_SHA' is TRUE" >&2
88105
echo "$FILE_NAME" >> $MODIFIED_FILES_LIST
89106
echo " -> Marked as modified." >&2
107+
elif [ -n "$PREV_SHA" ] && [ "$PREV_SHA" == "$FILE_SHA" ]; then
108+
echo "DEBUG: Comparison result: '$PREV_SHA' == '$FILE_SHA' is TRUE" >&2
109+
echo " -> Not modified." >&2
110+
elif [ -z "$PREV_SHA" ]; then
111+
# If file is in processed_files.txt but NOT in file_hashes.json, treat as modified (edge case)
112+
echo "DEBUG: Previous SHA is EMPTY." >&2
113+
echo " -> Warning: File '$FILE_NAME' was processed but hash missing. Marking as modified." >&2
114+
echo "$FILE_NAME" >> $MODIFIED_FILES_LIST
115+
else
116+
echo "DEBUG: Unhandled comparison case for '$FILE_NAME'" >&2
90117
fi
118+
else
119+
echo "DEBUG: Skipping file not in processed list: '$FILE_NAME'" >&2
91120
fi
92121
done < latest_files_with_sha.txt
93122
echo "--- Modified Files ---"
@@ -284,4 +313,3 @@ jobs:
284313
# Optional: Add labels, assignees etc.
285314
# labels: automated-pr, documentation
286315
# assignees: your-github-username
287-

0 commit comments

Comments
 (0)