diff --git a/tools/ci/check_article_details.sh b/tools/ci/check_article_details.sh index 69b15b905..cda3776bb 100644 --- a/tools/ci/check_article_details.sh +++ b/tools/ci/check_article_details.sh @@ -467,6 +467,42 @@ validate_added_articles() { return 1 } +find_trailing_spaces() { + echo + echo "Looking for trailing whitespaces..." + + local job_error=0 + + while IFS= read -r file; do + # Skip empty lines + [[ -z "$file" ]] && continue + + # Check if file exists + if [[ ! -f "$file" ]]; then + echo "Warning: File not found: $file" + continue + fi + + # Count lines with trailing spaces + count=$(grep -c '[[:blank:]]$' "$file") + + # Report only if there are trailing spaces + if [[ "$count" -gt 0 ]] 2>/dev/null; then + job_error=1 + echo + echo "❌ Lines end with extra spaces or tabs." + echo " Remove trailing whitespaces from (use
where needed):" + echo " $file -- $count line(s) in total." + fi + done < "$TEMP_DIR/index-added.txt" + + if [ "$job_error" -eq 0 ]; then + return 0 + fi + + return 1 +} + ############################################################################### # FEATURE ASSET VALIDATION @@ -565,7 +601,59 @@ validate_author_presence() { # UPDATED ARTICLES VALIDATION ############################################################################### -validate_updated_articles() { +collect_updated_articles_body_only() { + local base_ref="$1" + local output_file="${3:-$TEMP_DIR/index-updated-body.txt}" + + > "$output_file" # Clear output file + + while IFS= read -r file; do + # Skip empty lines + [[ -z "$file" ]] && continue + + # Get the diff for this specific file + local diff_output + diff_output=$(git diff -U0 "$base_ref"...HEAD -- "$file") + + # Flag to track if we found changes in frontmatter + local has_frontmatter_changes=false + + # Parse the diff output looking for change hunks + while IFS= read -r line; do + # Look for hunk headers like @@ -1,5 +1,5 @@ + if [[ "$line" =~ ^@@\ -([0-9]+) ]]; then + local start_line="${BASH_REMATCH[1]}" + + # Get the frontmatter end line from the original file + local frontmatter_end + frontmatter_end=$(git show "$base_ref:$file" | awk ' + BEGIN { count=0 } + /^---$/ { count++; if(count==2) { print NR; exit } } + ') + + # If we couldn't find frontmatter end, assume no frontmatter + [[ -z "$frontmatter_end" ]] && frontmatter_end=0 + + # If this hunk starts within the frontmatter section (line 1 to frontmatter_end) + if [[ $start_line -le $frontmatter_end ]]; then + has_frontmatter_changes=true + break + fi + fi + done <<< "$diff_output" + + # If no frontmatter changes detected, add to output + if [[ "$has_frontmatter_changes" == false ]]; then + echo "$file" >> "$output_file" + fi + done < "$TEMP_DIR/index-updated.txt" + + echo + echo "List of updated articles with body-only changes:" + cat "$output_file" +} + +validate_updated_articles_lastmod() { echo echo "Validating updated articles..." @@ -582,6 +670,9 @@ validate_updated_articles() { LASTMOD_DATE=$(awk '/^lastmod:/ { gsub(/["'\'']/, "", $2); print $2 }' "$index_file") ARTICLE_DATE_ONLY="${ARTICLE_DATE:0:10}" + local FILE_MOD_DATE + FILE_MOD_DATE=$(stat -c '%y' "$index_file" 2>/dev/null | cut -d' ' -f1 || stat -f '%Sm' -t '%Y-%m-%d' "$index_file") + echo echo "Article: $index_file" @@ -612,12 +703,24 @@ validate_updated_articles() { fi fi + if [ "$article_error" -eq 0 ] && [ -n "$FILE_MOD_DATE" ]; then + # Calculate days difference (allowing up to 3 days lag) + local days_diff + days_diff=$(( ( $(date -d "$FILE_MOD_DATE" +%s 2>/dev/null || date -j -f "%Y-%m-%d" "$FILE_MOD_DATE" +%s) - $(date -d "$LASTMOD_DATE" +%s 2>/dev/null || date -j -f "%Y-%m-%d" "$LASTMOD_DATE" +%s) ) / 86400 )) + + if [ "$days_diff" -gt 3 ]; then + echo "❌ lastmod is outdated: $LASTMOD_DATE (file modified: $FILE_MOD_DATE)." + echo " Update lastmod to reflect the recent changes (within 3 days of modification)." + article_error=1 + fi + fi + if [ "$article_error" -eq 0 ]; then echo "lastmod date validated successfully." else job_error=1 fi - done < "$TEMP_DIR/index-updated.txt" + done < "$TEMP_DIR/index-updated-body.txt" if [ "$job_error" -eq 0 ]; then return 0 @@ -715,6 +818,7 @@ banner "🔎 Checking added files..." if [[ -s "$TEMP_DIR/index-added.txt" ]]; then extract_added_metadata || overall_error=1 validate_added_articles || overall_error=1 + find_trailing_spaces || overall_error=1 validate_author_presence || overall_error=1 validate_feature_assets || overall_error=1 else @@ -724,7 +828,8 @@ fi banner "🔎 Checking updated files..." if [[ -s "$TEMP_DIR/index-updated.txt" ]]; then - validate_updated_articles || overall_error=1 + collect_updated_articles_body_only "$BASE_REF" + validate_updated_articles_lastmod || overall_error=1 fi if [[ -s "$TEMP_DIR/folders-renamed.txt" ]]; then