Skip to content

Commit 78a20dc

Browse files
nishimotzclaude
andcommitted
Add automatic duplicate file detection and cleanup workflow
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 39f7021 commit 78a20dc

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Check and Resolve Duplicate Filenames
2+
3+
on:
4+
push:
5+
paths:
6+
- 'WAIC-TEST/HTML_見送り/**'
7+
- 'WAIC-TEST/HTML_未着手/**'
8+
pull_request:
9+
paths:
10+
- 'WAIC-TEST/HTML_見送り/**'
11+
- 'WAIC-TEST/HTML_未着手/**'
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
env:
19+
BRANCH_PREFIX: fix-duplicate-files
20+
21+
jobs:
22+
check-duplicates:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
duplicates_found: ${{ steps.check.outputs.duplicates_found }}
26+
duplicate_list: ${{ steps.check.outputs.duplicate_list }}
27+
files_to_delete: ${{ steps.check.outputs.files_to_delete }}
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Check for duplicate filenames
35+
id: check
36+
run: |
37+
echo "Checking for duplicate filenames between HTML_見送り and HTML_未着手 folders..."
38+
39+
# Get basenames from both directories
40+
dir1_files=$(find "WAIC-TEST/HTML_見送り" -name "*.md" -exec basename {} \; 2>/dev/null | sort)
41+
dir2_files=$(find "WAIC-TEST/HTML_未着手" -name "*.md" -exec basename {} \; 2>/dev/null | sort)
42+
43+
# Find duplicates
44+
duplicates=$(comm -12 <(echo "$dir1_files") <(echo "$dir2_files"))
45+
46+
if [ -n "$duplicates" ]; then
47+
echo "❌ Duplicate filenames found:"
48+
echo "$duplicates"
49+
echo ""
50+
echo "Files exist in both HTML_見送り and HTML_未着手:"
51+
52+
# Create detailed list for issue and files to delete
53+
issue_body=""
54+
files_to_delete=""
55+
for file in $duplicates; do
56+
echo " - $file"
57+
miokuri_path=$(find WAIC-TEST/HTML_見送り -name "$file" -exec echo {} \;)
58+
michakushu_path=$(find WAIC-TEST/HTML_未着手 -name "$file" -exec echo {} \;)
59+
echo " 📁 HTML_見送り/$miokuri_path"
60+
echo " 📁 HTML_未着手/$michakushu_path"
61+
issue_body="$issue_body- \`$file\`\n - 📁 \`$miokuri_path\`\n - 📁 \`$michakushu_path\`\n\n"
62+
files_to_delete="$files_to_delete$michakushu_path\n"
63+
done
64+
65+
echo "duplicates_found=true" >> $GITHUB_OUTPUT
66+
echo "duplicate_list<<EOF" >> $GITHUB_OUTPUT
67+
echo -e "$issue_body" >> $GITHUB_OUTPUT
68+
echo "EOF" >> $GITHUB_OUTPUT
69+
echo "files_to_delete<<EOF" >> $GITHUB_OUTPUT
70+
echo -e "$files_to_delete" >> $GITHUB_OUTPUT
71+
echo "EOF" >> $GITHUB_OUTPUT
72+
73+
# Don't fail, proceed to auto-fix
74+
else
75+
echo "✅ No duplicate filenames found between the two directories."
76+
echo "duplicates_found=false" >> $GITHUB_OUTPUT
77+
fi
78+
79+
auto-fix-duplicates:
80+
needs: check-duplicates
81+
if: needs.check-duplicates.outputs.duplicates_found == 'true'
82+
runs-on: ubuntu-latest
83+
steps:
84+
- name: Checkout repository
85+
uses: actions/checkout@v4
86+
with:
87+
token: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Delete duplicate files from HTML_未着手
90+
run: |
91+
echo "Deleting duplicate files from HTML_未着手 folder..."
92+
93+
# Delete files listed in files_to_delete
94+
echo -e "${{ needs.check-duplicates.outputs.files_to_delete }}" | while read -r file; do
95+
if [ -n "$file" ] && [ -f "$file" ]; then
96+
echo "Deleting: $file"
97+
rm "$file"
98+
fi
99+
done
100+
101+
- name: Create Pull Request for duplicate removal
102+
uses: peter-evans/create-pull-request@v7
103+
with:
104+
token: ${{ secrets.GITHUB_TOKEN }}
105+
commit-message: "🗑️ Remove duplicate files from HTML_未着手 folder [skip ci]"
106+
title: "🗑️ 重複ファイルの自動削除 (HTML_未着手)"
107+
body: |
108+
## 概要
109+
HTML_見送り と HTML_未着手 フォルダ間で重複するファイルを検出し、HTML_未着手 から自動削除しました。
110+
111+
## 削除されたファイル
112+
${{ needs.check-duplicates.outputs.duplicate_list }}
113+
114+
## 削除理由
115+
- ファイルが HTML_見送り フォルダに既に存在するため
116+
- 重複を避けるために HTML_未着手 から削除
117+
118+
## 確認事項
119+
- [ ] 削除されたファイルの内容が HTML_見送り のファイルと同一であることを確認
120+
- [ ] 削除により影響を受ける他のファイルがないことを確認
121+
122+
## 自動処理情報
123+
- **処理日時**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
124+
- **検出コミット**: ${{ github.sha }}
125+
- **ワークフロー**: ${{ github.workflow }}
126+
- **実行イベント**: ${{ github.event_name }}
127+
128+
> このPRはGitHub Actionsにより自動生成されました。マージ前に内容をご確認ください。
129+
branch: ${{ env.BRANCH_PREFIX }}-${{ github.run_number }}
130+
base: master
131+
delete-branch: true
132+

0 commit comments

Comments
 (0)