|
| 1 | +name: "Link Health Check" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + file_to_check: |
| 7 | + description: '검사할 파일' |
| 8 | + required: false |
| 9 | + default: 'README.md' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - 'README.md' |
| 13 | + - 'README_EN.md' |
| 14 | + - 'both' |
| 15 | + |
| 16 | + schedule: |
| 17 | + - cron: '0 9 * * 1' |
| 18 | + |
| 19 | + push: |
| 20 | + branches: [ main, master ] |
| 21 | + paths: |
| 22 | + - 'README.md' |
| 23 | + - 'README_EN.md' |
| 24 | + |
| 25 | +jobs: |
| 26 | + check_links: |
| 27 | + name: "API 링크 상태 검사" |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + strategy: |
| 31 | + matrix: |
| 32 | + python-version: [3.9] |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: 📁 체크아웃 |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: 🐍 Python 설정 |
| 39 | + uses: actions/setup-python@v4 |
| 40 | + with: |
| 41 | + python-version: ${{ matrix.python-version }} |
| 42 | + |
| 43 | + - name: 📦 의존성 설치 |
| 44 | + run: | |
| 45 | + python -m pip install --upgrade pip |
| 46 | + pip install aiohttp |
| 47 | +
|
| 48 | + - name: 🔍 README.md 링크 검사 |
| 49 | + id: check_readme |
| 50 | + if: github.event.inputs.file_to_check != 'README_EN.md' |
| 51 | + run: | |
| 52 | + echo "=== 한국어 README 검사 시작 ===" |
| 53 | + python scripts/link_health_check.py README.md --save-json --concurrent 25 |
| 54 | + continue-on-error: true |
| 55 | + |
| 56 | + - name: 🔍 README_EN.md 링크 검사 |
| 57 | + id: check_readme_en |
| 58 | + if: github.event.inputs.file_to_check == 'README_EN.md' || github.event.inputs.file_to_check == 'both' |
| 59 | + run: | |
| 60 | + echo "=== 영어 README 검사 시작 ===" |
| 61 | + python scripts/link_health_check.py README_EN.md --save-json --concurrent 25 |
| 62 | + mv link_health_report.json link_health_report_en.json |
| 63 | + continue-on-error: true |
| 64 | + |
| 65 | + - name: 📊 검사 결과 업로드 |
| 66 | + uses: actions/upload-artifact@v3 |
| 67 | + if: always() |
| 68 | + with: |
| 69 | + name: link-health-reports |
| 70 | + path: | |
| 71 | + link_health_report.json |
| 72 | + link_health_report_en.json |
| 73 | + retention-days: 30 |
| 74 | + |
| 75 | + - name: 🚨 깨진 링크 이슈 생성 |
| 76 | + if: failure() && github.event_name == 'schedule' |
| 77 | + uses: actions/github-script@v6 |
| 78 | + with: |
| 79 | + script: | |
| 80 | + const fs = require('fs'); |
| 81 | + |
| 82 | + let brokenLinks = []; |
| 83 | + let reportContent = ''; |
| 84 | + |
| 85 | + // 한국어 README 결과 확인 |
| 86 | + try { |
| 87 | + const koReport = JSON.parse(fs.readFileSync('link_health_report.json', 'utf8')); |
| 88 | + const koBroken = koReport.results.filter(link => !link.is_working); |
| 89 | + brokenLinks = brokenLinks.concat(koBroken.map(link => ({...link, file: 'README.md'}))); |
| 90 | + } catch (e) { |
| 91 | + console.log('한국어 리포트 파일을 찾을 수 없습니다.'); |
| 92 | + } |
| 93 | + |
| 94 | + // 영어 README 결과 확인 |
| 95 | + try { |
| 96 | + const enReport = JSON.parse(fs.readFileSync('link_health_report_en.json', 'utf8')); |
| 97 | + const enBroken = enReport.results.filter(link => !link.is_working); |
| 98 | + brokenLinks = brokenLinks.concat(enBroken.map(link => ({...link, file: 'README_EN.md'}))); |
| 99 | + } catch (e) { |
| 100 | + console.log('영어 리포트 파일을 찾을 수 없습니다.'); |
| 101 | + } |
| 102 | + |
| 103 | + if (brokenLinks.length > 0) { |
| 104 | + // 에러 타입별로 그룹화 |
| 105 | + const errorGroups = {}; |
| 106 | + brokenLinks.forEach(link => { |
| 107 | + const errorType = link.error_type; |
| 108 | + if (!errorGroups[errorType]) { |
| 109 | + errorGroups[errorType] = []; |
| 110 | + } |
| 111 | + errorGroups[errorType].push(link); |
| 112 | + }); |
| 113 | + |
| 114 | + let issueBody = `## 🚨 링크 부패 감지 알림\n\n`; |
| 115 | + issueBody += `**총 ${brokenLinks.length}개의 깨진 링크가 발견되었습니다.**\n\n`; |
| 116 | + |
| 117 | + // 에러 타입별 상세 내용 |
| 118 | + for (const [errorType, links] of Object.entries(errorGroups)) { |
| 119 | + issueBody += `### 📋 ${errorType} (${links.length}개)\n\n`; |
| 120 | + |
| 121 | + links.forEach(link => { |
| 122 | + issueBody += `- ❌ **[${link.api_name}](${link.url})**\n`; |
| 123 | + issueBody += ` - 📁 파일: ${link.file}\n`; |
| 124 | + issueBody += ` - 📂 카테고리: ${link.category}\n`; |
| 125 | + issueBody += ` - ⚠️ 오류: ${link.error_message}\n`; |
| 126 | + if (link.redirect_url) { |
| 127 | + issueBody += ` - 🔄 리다이렉트: ${link.redirect_url}\n`; |
| 128 | + } |
| 129 | + issueBody += `\n`; |
| 130 | + }); |
| 131 | + } |
| 132 | + |
| 133 | + issueBody += `\n### 🔧 수정 방법\n\n`; |
| 134 | + issueBody += `1. **서비스 상태 확인**: 해당 API 서비스가 종료되었는지 확인\n`; |
| 135 | + issueBody += `2. **URL 변경 확인**: 공식 문서에서 새로운 URL 확인\n`; |
| 136 | + issueBody += `3. **대체 서비스 조사**: 동일한 기능의 대체 API 조사\n`; |
| 137 | + issueBody += `4. **항목 제거**: 복구 불가능한 경우 해당 항목 제거\n\n`; |
| 138 | + issueBody += `---\n`; |
| 139 | + issueBody += `**자동 생성 시간**: ${new Date().toLocaleString('ko-KR', {timeZone: 'Asia/Seoul'})}\n`; |
| 140 | + issueBody += `**검사 주기**: 매주 월요일\n`; |
| 141 | +
|
| 142 | + // 이슈 생성 |
| 143 | + await github.rest.issues.create({ |
| 144 | + owner: context.repo.owner, |
| 145 | + repo: context.repo.repo, |
| 146 | + title: `🔗 주간 링크 상태 점검: ${brokenLinks.length}개 링크 수정 필요`, |
| 147 | + body: issueBody, |
| 148 | + labels: ['🐛 bug', '🔗 link-rot', '🔧 maintenance', '📋 weekly-check'] |
| 149 | + }); |
| 150 | + |
| 151 | + console.log(`이슈가 생성되었습니다: ${brokenLinks.length}개 깨진 링크`); |
| 152 | + } else { |
| 153 | + console.log('모든 링크가 정상적으로 작동합니다! 🎉'); |
| 154 | + } |
| 155 | +
|
| 156 | + - name: 💬 PR에 결과 댓글 작성 |
| 157 | + if: github.event_name == 'pull_request' && (failure() || success()) |
| 158 | + uses: actions/github-script@v6 |
| 159 | + with: |
| 160 | + script: | |
| 161 | + const fs = require('fs'); |
| 162 | + |
| 163 | + let allBroken = []; |
| 164 | + let totalLinks = 0; |
| 165 | + let workingLinks = 0; |
| 166 | + |
| 167 | + // 결과 파일들 읽기 |
| 168 | + try { |
| 169 | + const koReport = JSON.parse(fs.readFileSync('link_health_report.json', 'utf8')); |
| 170 | + totalLinks += koReport.total_links; |
| 171 | + workingLinks += koReport.working_links; |
| 172 | + const koBroken = koReport.results.filter(link => !link.is_working); |
| 173 | + allBroken = allBroken.concat(koBroken.map(link => ({...link, file: 'README.md'}))); |
| 174 | + } catch (e) {} |
| 175 | + |
| 176 | + try { |
| 177 | + const enReport = JSON.parse(fs.readFileSync('link_health_report_en.json', 'utf8')); |
| 178 | + totalLinks += enReport.total_links; |
| 179 | + workingLinks += enReport.working_links; |
| 180 | + const enBroken = enReport.results.filter(link => !link.is_working); |
| 181 | + allBroken = allBroken.concat(enBroken.map(link => ({...link, file: 'README_EN.md'}))); |
| 182 | + } catch (e) {} |
| 183 | + |
| 184 | + const successRate = totalLinks > 0 ? ((workingLinks / totalLinks) * 100).toFixed(1) : 0; |
| 185 | + |
| 186 | + let commentBody = `## 🔗 링크 상태 검사 결과\n\n`; |
| 187 | + |
| 188 | + if (allBroken.length === 0) { |
| 189 | + commentBody += `✅ **모든 링크가 정상적으로 작동합니다!**\n\n`; |
| 190 | + commentBody += `📊 **통계**: ${totalLinks}개 링크 중 ${workingLinks}개 정상 (${successRate}%)\n`; |
| 191 | + } else { |
| 192 | + commentBody += `⚠️ **일부 링크에 문제가 발견되었습니다.**\n\n`; |
| 193 | + commentBody += `📊 **통계**: ${totalLinks}개 링크 중 ${allBroken.length}개 문제 (성공률: ${successRate}%)\n\n`; |
| 194 | + commentBody += `### 🚨 문제가 있는 링크들:\n\n`; |
| 195 | + |
| 196 | + allBroken.slice(0, 10).forEach(link => { |
| 197 | + commentBody += `- ❌ **${link.api_name}** (${link.file})\n`; |
| 198 | + commentBody += ` - URL: ${link.url}\n`; |
| 199 | + commentBody += ` - 오류: ${link.error_message}\n\n`; |
| 200 | + }); |
| 201 | + |
| 202 | + if (allBroken.length > 10) { |
| 203 | + commentBody += `... 그리고 ${allBroken.length - 10}개 더\n\n`; |
| 204 | + } |
| 205 | + |
| 206 | + commentBody += `🔧 **수정 후 다시 검사를 받으시기 바랍니다.**\n`; |
| 207 | + } |
| 208 | + |
| 209 | + commentBody += `\n---\n 링크 상태 자동 검사`; |
| 210 | +
|
| 211 | + await github.rest.issues.createComment({ |
| 212 | + issue_number: context.issue.number, |
| 213 | + owner: context.repo.owner, |
| 214 | + repo: context.repo.repo, |
| 215 | + body: commentBody |
| 216 | + }); |
| 217 | + |
0 commit comments