Notion Sync #45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Notion Sync | |
| on: | |
| schedule: | |
| - cron: '0 1 * * *' # 매일 KST 10:00 (UTC 01:00) | |
| workflow_dispatch: | |
| inputs: | |
| fetch_mode: | |
| description: 'DAILY (어제 날짜만) 또는 ALL (전체)' | |
| required: false | |
| default: 'DAILY' | |
| type: choice | |
| options: | |
| - DAILY | |
| - ALL | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| env: | |
| NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }} | |
| FETCH_MODE: ${{ github.event.inputs.fetch_mode || 'DAILY' }} | |
| # 신규 시크릿명 우선, 구 이름 fallback | |
| _BLOG_DB: ${{ secrets.NOTION_BLOG || secrets.NOTION_DATABASE_ID }} | |
| _CONTRIBUTE_DB: ${{ secrets.NOTION_CONTRIBUTE || secrets.NOTION_CONTRIBUTE_DATABASE_ID }} | |
| _ABOUT_DB: ${{ secrets.NOTION_ABOUT }} | |
| _ARCHITECTURE_DB: ${{ secrets.NOTION_ARCHITECTURE }} | |
| _POC_DB: ${{ secrets.NOTION_POC }} | |
| _DOCS_DB: ${{ secrets.NOTION_DOCS }} | |
| _RELEASE_DB: ${{ secrets.NOTION_RELEASE }} | |
| _INSTALL_DB: ${{ secrets.NOTION_INSTALL }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: pip install requests | |
| - name: Sync all databases in parallel | |
| run: | | |
| pids=() | |
| if [ -n "$_BLOG_DB" ]; then | |
| NOTION_DATABASE_ID="$_BLOG_DB" python scripts/notion_to_blog.py & | |
| pids+=($!) | |
| fi | |
| if [ -n "$_CONTRIBUTE_DB" ]; then | |
| NOTION_DATABASE_ID="$_CONTRIBUTE_DB" SAVE_DIR=docs/contribute FETCH_MODE=ALL \ | |
| python scripts/notion_to_docs_generic.py & | |
| pids+=($!) | |
| fi | |
| if [ -n "$_ABOUT_DB" ]; then | |
| NOTION_DATABASE_ID="$_ABOUT_DB" SAVE_DIR=docs/about FETCH_MODE=ALL \ | |
| python scripts/notion_to_docs_generic.py & | |
| pids+=($!) | |
| fi | |
| if [ -n "$_ARCHITECTURE_DB" ]; then | |
| NOTION_DATABASE_ID="$_ARCHITECTURE_DB" SAVE_DIR=docs/architecture FETCH_MODE=ALL \ | |
| python scripts/notion_to_docs_generic.py & | |
| pids+=($!) | |
| fi | |
| if [ -n "$_POC_DB" ]; then | |
| NOTION_DATABASE_ID="$_POC_DB" SAVE_DIR=docs/poc FETCH_MODE=ALL \ | |
| python scripts/notion_to_docs_generic.py & | |
| pids+=($!) | |
| fi | |
| if [ -n "$_DOCS_DB" ]; then | |
| NOTION_DATABASE_ID="$_DOCS_DB" SAVE_DIR=docs/guide FETCH_MODE=ALL \ | |
| python scripts/notion_to_docs_generic.py & | |
| pids+=($!) | |
| fi | |
| if [ -n "$_RELEASE_DB" ]; then | |
| NOTION_DATABASE_ID="$_RELEASE_DB" SAVE_DIR=docs/release-notes FETCH_MODE=ALL \ | |
| python scripts/notion_to_docs_generic.py & | |
| pids+=($!) | |
| fi | |
| if [ -n "$_INSTALL_DB" ]; then | |
| NOTION_DATABASE_ID="$_INSTALL_DB" SAVE_DIR=docs/install FETCH_MODE=ALL \ | |
| python scripts/notion_to_docs_generic.py & | |
| pids+=($!) | |
| fi | |
| if [ ${#pids[@]} -eq 0 ]; then | |
| echo "동기화할 DB가 없습니다. GitHub Secrets에 NOTION_* 변수를 설정하세요." | |
| exit 0 | |
| fi | |
| failed=0 | |
| for pid in "${pids[@]}"; do | |
| wait "$pid" || { echo "ERROR: pid $pid failed"; failed=1; } | |
| done | |
| exit $failed | |
| - name: Commit and push if changed | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add docs/ static/img/ | |
| if ! git diff --staged --quiet; then | |
| git commit -m "chore: Notion 동기화 $(date +'%Y-%m-%d')" | |
| git pull --rebase origin main | |
| git push | |
| fi |