Skip to content

Learntosurf / 4월 3주차 / 3문제 #62

Learntosurf / 4월 3주차 / 3문제

Learntosurf / 4월 3주차 / 3문제 #62

name: Update Challenge Progress
on:
pull_request:
types:
- closed
jobs:
update_progress:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Configure Github User & Sync with main branch
run: |
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}"
git pull origin main --rebase
- name: Run extract_pr_data.py
working-directory: _MonthlyChallenges
run: python extract_pr_data.py
- name: Run update_scoreboard.py
working-directory: _MonthlyChallenges
run: python update_scoreboard.py
- name: Run update_dashboard.py
working-directory: _MonthlyChallenges
run: python update_dashboard.py
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study.git ${{ github.head_ref }}
- name: Commit updated files
run: |
cd _MonthlyChallenges
git add scoreboard.json DASHBOARD.md HISTORY.md
git commit -m "Update challenge progress dashboard" || echo "No changes to commit"
git push origin main
- name: Post PR Comment with progress
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
// DASHBOARD.md 파일에서 내용 읽어오기 (working-directory에 따라 경로 조정)
const dashboard = fs.readFileSync('_MonthlyChallenges/DASHBOARD.md', 'utf8');
// PR 이벤트에서 PR 번호 가져오기
const prNumber = context.payload.pull_request.number;
// GitHub REST API를 통해 코멘트 생성
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: dashboard
});
notify_discord:
needs: update_progress
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
- name: Send Dashboard to Discord
working-directory: _MonthlyChallenges
run: |
# DASHBOARD.md 파일을 안전하게 JSON 문자열로 이스케이프
DASHBOARD_CONTENT=$(jq -R -s '.' DASHBOARD.md)
echo "Dashboard content: $DASHBOARD_CONTENT"
# Discord 임베드 메시지 JSON 생성
EMBED_JSON=$(cat <<EOF
{
"content": "",
"embeds": [
{
"author": {
"name": "Allumbus🔥",
"url": "https://github.com/AlgorithmStudy-Allumbus",
"icon_url": "https://imgur.com/kKJg6v3.jpg"
},
"title": "**📊 챌린지 진행 상황**",
"url": "https://github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study/blob/main/_MonthlyChallenges/DASHBOARD.md",
"description": ${DASHBOARD_CONTENT},
"color": 15258703,
"footer": {
"text": "Updated on $(date '+%Y-%m-%d %H:%M:%S')"
}
}
]
}
EOF
)
echo "Embed JSON: $EMBED_JSON"
# Discord 웹훅 호출 (디버그를 위해 -v 옵션 사용)
curl -v -H "Content-Type: application/json" \
-X POST \
-d "$EMBED_JSON" \
"${{ secrets.DISCORD_WEBHOOK_URL }}"