6666 const difficulty = problemContent.match(/\*\*난이도\*\*:\s*([^\n*]+)/)?.[1]?.trim() || '';
6767 const link = problemContent.match(/\*\*링크\*\*:\s*([^\n*]+)/)?.[1]?.trim() || '';
6868
69- if (platform && problemNum && problemName) {
69+ if (platform && problemName) {
7070 problems.push({
7171 platform,
7272 problemNum,
@@ -89,20 +89,34 @@ jobs:
8989 return 'ETC';
9090 };
9191
92+ // 폴더명 생성 함수 (문제번호가 없거나 -면 플랫폼_문제제목 형태)
93+ const getFolderName = (problem) => {
94+ const prefix = getPlatformPrefix(problem.platform);
95+ const cleanName = problem.problemName.replace(/\s+/g, '');
96+ const hasValidNum = problem.problemNum && problem.problemNum !== '-' && problem.problemNum.trim() !== '';
97+
98+ if (hasValidNum) {
99+ return `${prefix}_${problem.problemNum}_${cleanName}`;
100+ } else {
101+ return `${prefix}_${cleanName}`;
102+ }
103+ };
104+
92105 // README.md 내용 생성
93106 let readmeContent = `# Week ${weekNumber} (${startDate} ~ ${endDate})\n\n`;
94107 readmeContent += `## 📝 이번 주 문제\n\n`;
95108
96109 const folderStructure = [];
97110
98111 problems.forEach((problem, index) => {
99- const prefix = getPlatformPrefix(problem.platform);
100- const folderName = `${prefix}_${problem.problemNum}_${problem.problemName.replace(/\s+/g, '')}`;
112+ const folderName = getFolderName(problem);
101113 folderStructure.push(folderName);
102114
103115 readmeContent += `### 문제 ${index + 1}: ${problem.problemName}\n`;
104116 readmeContent += `- **플랫폼**: ${problem.platform}\n`;
105- readmeContent += `- **문제 번호**: ${problem.problemNum}\n`;
117+ if (problem.problemNum && problem.problemNum !== '-' && problem.problemNum.trim() !== '') {
118+ readmeContent += `- **문제 번호**: ${problem.problemNum}\n`;
119+ }
106120 readmeContent += `- **난이도**: ${problem.difficulty}\n`;
107121 readmeContent += `- **링크**: ${problem.link.startsWith('http') ? `[문제 링크](${problem.link})` : problem.link}\n`;
108122 readmeContent += `\n`;
@@ -126,26 +140,39 @@ jobs:
126140
127141 // 출력 설정
128142 const fs = require('fs');
129- const path = `weekly/week${weekNumber}`;
143+ const basePath = `weekly/week${weekNumber}`;
130144
131145 core.setOutput('week_number', weekNumber);
132- core.setOutput('directory_path', path );
146+ core.setOutput('directory_path', basePath );
133147 core.setOutput('readme_content', readmeContent);
134148
135- // 파일 저장 (Node.js fs 사용)
136- if (!fs.existsSync(path )) {
137- fs.mkdirSync(path , { recursive: true });
149+ // 주차 디렉토리 생성
150+ if (!fs.existsSync(basePath )) {
151+ fs.mkdirSync(basePath , { recursive: true });
138152 }
139- fs.writeFileSync(`${path}/README.md`, readmeContent);
140153
141- console.log(`\n✅ Created ${path}/README.md`);
154+ // README.md 저장
155+ fs.writeFileSync(`${basePath}/README.md`, readmeContent);
156+ console.log(`\n✅ Created ${basePath}/README.md`);
157+
158+ // 각 문제별 디렉토리 생성 및 응원 파일 생성
159+ const cheerMessage = `# 이번 주도 파이팅!🔥`;
160+
161+ folderStructure.forEach((folder) => {
162+ const problemPath = `${basePath}/${folder}`;
163+ if (!fs.existsSync(problemPath)) {
164+ fs.mkdirSync(problemPath, { recursive: true });
165+ }
166+ fs.writeFileSync(`${problemPath}/.gitkeep`, cheerMessage);
167+ console.log(`✅ Created ${problemPath}/.gitkeep`);
168+ });
142169
143170 - name : Commit and push
144171 run : |
145172 git config --local user.email "action@github.com"
146173 git config --local user.name "GitHub Action"
147174 git add weekly/
148- git diff —staged —quiet || git commit -m "[Week${{ steps.create.outputs.week_number }}] 주차 디렉토리 및 README 생성
175+ git diff —staged —quiet || git commit -m "[Week${{ steps.create.outputs.week_number }}] 주차별 디렉토리 및 README 생성
149176
150177 🤖 Generated with GitHub Actions"
151178 git push
0 commit comments