160 lines
5.1 KiB
Bash
Executable File
160 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Drama Ling 合規性檢查工具
|
||
# 用途:檢查是否有違反標準流程的檔案和行為
|
||
# 使用方法: ./check_compliance.sh
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||
REPORTS_DIR="$PROJECT_ROOT/reports"
|
||
|
||
# 顏色定義
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
RED='\033[0;31m'
|
||
NC='\033[0m'
|
||
|
||
echo -e "${BLUE}🔍 Drama Ling 合規性檢查${NC}"
|
||
echo "=================================="
|
||
|
||
# 檢查1: 尋找可能手動創建的報告檔案
|
||
echo -e "${BLUE}檢查1: 尋找不符合命名規範的報告檔案${NC}"
|
||
suspicious_reports=()
|
||
|
||
if [ -d "$REPORTS_DIR" ]; then
|
||
# 檢查是否有 2024 年份的檔案(應該都是 2025)
|
||
while IFS= read -r -d '' file; do
|
||
if [[ "$file" == *"2024"* ]]; then
|
||
suspicious_reports+=("$file")
|
||
fi
|
||
done < <(find "$REPORTS_DIR" -name "*.md" -print0 2>/dev/null)
|
||
|
||
# 檢查是否有不符合日期格式的檔案
|
||
while IFS= read -r -d '' file; do
|
||
filename=$(basename "$file")
|
||
if [[ ! "$filename" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}_ ]]; then
|
||
suspicious_reports+=("$file")
|
||
fi
|
||
done < <(find "$REPORTS_DIR" -name "*.md" -not -name "*template*" -print0 2>/dev/null)
|
||
fi
|
||
|
||
if [ ${#suspicious_reports[@]} -eq 0 ]; then
|
||
echo -e "${GREEN}✅ 所有報告檔案都符合命名規範${NC}"
|
||
else
|
||
echo -e "${RED}❌ 發現 ${#suspicious_reports[@]} 個可能有問題的檔案:${NC}"
|
||
for file in "${suspicious_reports[@]}"; do
|
||
echo " - $file"
|
||
done
|
||
fi
|
||
|
||
echo ""
|
||
|
||
# 檢查2: 驗證報告檔案的日期一致性
|
||
echo -e "${BLUE}檢查2: 驗證報告檔案的日期一致性${NC}"
|
||
current_date=$(date +"%Y-%m-%d")
|
||
date_inconsistencies=()
|
||
|
||
if [ -d "$REPORTS_DIR" ]; then
|
||
while IFS= read -r -d '' file; do
|
||
if [[ "$file" == *"analysis"* ]] || [[ "$file" == *"decision"* ]]; then
|
||
# 提取檔名中的日期
|
||
filename=$(basename "$file")
|
||
file_date=$(echo "$filename" | grep -o '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}')
|
||
|
||
if [ -n "$file_date" ]; then
|
||
# 檢查檔案內容中的日期
|
||
if grep -q "分析日期.*$file_date" "$file" 2>/dev/null; then
|
||
continue
|
||
else
|
||
date_inconsistencies+=("$file (檔名日期: $file_date)")
|
||
fi
|
||
fi
|
||
fi
|
||
done < <(find "$REPORTS_DIR" -name "*.md" -not -name "*template*" -print0 2>/dev/null)
|
||
fi
|
||
|
||
if [ ${#date_inconsistencies[@]} -eq 0 ]; then
|
||
echo -e "${GREEN}✅ 所有報告的日期都一致${NC}"
|
||
else
|
||
echo -e "${RED}❌ 發現 ${#date_inconsistencies[@]} 個日期不一致的檔案:${NC}"
|
||
for file in "${date_inconsistencies[@]}"; do
|
||
echo " - $file"
|
||
done
|
||
fi
|
||
|
||
echo ""
|
||
|
||
# 檢查3: 檢查是否有未使用工具創建的檔案
|
||
echo -e "${BLUE}檢查3: 檢查檔案創建方式${NC}"
|
||
manually_created=()
|
||
|
||
if [ -d "$REPORTS_DIR" ]; then
|
||
while IFS= read -r -d '' file; do
|
||
if [[ "$file" == *"analysis"* ]] || [[ "$file" == *"decision"* ]]; then
|
||
# 檢查是否包含工具創建的標誌
|
||
if ! grep -q "報告產生.*工具" "$file" 2>/dev/null; then
|
||
manually_created+=("$file")
|
||
fi
|
||
fi
|
||
done < <(find "$REPORTS_DIR" -name "*.md" -not -name "*template*" -print0 2>/dev/null)
|
||
fi
|
||
|
||
if [ ${#manually_created[@]} -eq 0 ]; then
|
||
echo -e "${GREEN}✅ 所有報告都是通過工具創建${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠️ 發現 ${#manually_created[@]} 個可能手動創建的檔案:${NC}"
|
||
for file in "${manually_created[@]}"; do
|
||
echo " - $file"
|
||
done
|
||
fi
|
||
|
||
echo ""
|
||
|
||
# 檢查4: 檢查 ISSUES.md 的格式一致性
|
||
echo -e "${BLUE}檢查4: 檢查 ISSUES.md 格式一致性${NC}"
|
||
issues_file="$PROJECT_ROOT/ISSUES.md"
|
||
|
||
if [ -f "$issues_file" ]; then
|
||
# 檢查日期格式
|
||
inconsistent_dates=$(grep -n "完成日期.*2024" "$issues_file" | wc -l)
|
||
if [ "$inconsistent_dates" -eq 0 ]; then
|
||
echo -e "${GREEN}✅ ISSUES.md 中的日期格式正確${NC}"
|
||
else
|
||
echo -e "${RED}❌ ISSUES.md 中發現 $inconsistent_dates 個 2024 年的日期${NC}"
|
||
fi
|
||
else
|
||
echo -e "${RED}❌ 找不到 ISSUES.md 檔案${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
|
||
# 總結
|
||
echo -e "${BLUE}📊 檢查總結${NC}"
|
||
echo "=================================="
|
||
total_issues=$((${#suspicious_reports[@]} + ${#date_inconsistencies[@]} + ${#manually_created[@]}))
|
||
|
||
if [ "$total_issues" -eq 0 ]; then
|
||
echo -e "${GREEN}🎉 恭喜!所有檢查都通過,系統符合標準規範${NC}"
|
||
exit 0
|
||
else
|
||
echo -e "${YELLOW}⚠️ 發現 $total_issues 個潛在問題${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}建議修正措施:${NC}"
|
||
|
||
if [ ${#suspicious_reports[@]} -gt 0 ]; then
|
||
echo "1. 重新命名不符合規範的報告檔案"
|
||
fi
|
||
|
||
if [ ${#date_inconsistencies[@]} -gt 0 ]; then
|
||
echo "2. 修正檔案內容中的日期不一致問題"
|
||
fi
|
||
|
||
if [ ${#manually_created[@]} -gt 0 ]; then
|
||
echo "3. 考慮使用標準工具重新創建手動建立的檔案"
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${YELLOW}💡 提醒:請查看 CLAUDE.md 了解正確的工作流程${NC}"
|
||
exit 1
|
||
fi |