Sync Notion Database #251
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: Sync Notion Database | |
| on: | |
| schedule: | |
| - cron: '0 17 * * *' # 9 AM PST / 17:00 UTC daily | |
| workflow_dispatch: | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - run: npm ci --legacy-peer-deps | |
| - name: Sync Notion → PGlite | |
| env: | |
| NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }} | |
| NOTION_DB_ID: ${{ secrets.NOTION_DB_ID }} | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| run: npm run sync | |
| - name: Commit PGlite DB | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config --global user.name "adit-bala" | |
| git config --global user.email "aditbala@berkeley.edu" | |
| git add db/notion.db.tar.gz | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "[automated] notion db sync" | |
| git push origin HEAD:${{ github.ref }} | |
| fi | |
| - name: Base64-encode DB | |
| run: | | |
| base64 -w0 db/notion.db.tar.gz > db.b64 | |
| DB64=$(cat db.b64) | |
| printf '%s' "$DB64" >"$GITHUB_WORKSPACE/encoded.txt" | |
| - name: Commit DB to frontend repo | |
| env: | |
| GH_TOKEN: ${{ secrets.FRONTEND_REPO_PAT }} | |
| run: | | |
| SHA=$(curl -s -H "Authorization: bearer $GH_TOKEN" \ | |
| https://api.github.com/repos/adit-bala/portfolio/contents/db/notion.db.tar.gz \ | |
| | jq -r .sha 2>/dev/null || echo "") | |
| # Build the JSON payload without putting large content on the command line | |
| if [ -n "$SHA" ]; then | |
| jq -n \ | |
| --arg message "[automated] notion db sync" \ | |
| --arg sha "$SHA" \ | |
| --rawfile content encoded.txt \ | |
| '{"message": $message, "content": $content, "sha": $sha}' > payload.json | |
| else | |
| jq -n \ | |
| --arg message "[automated] notion db sync" \ | |
| --rawfile content encoded.txt \ | |
| '{"message": $message, "content": $content}' > payload.json | |
| fi | |
| curl -X PUT -H "Authorization: bearer $GH_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| https://api.github.com/repos/adit-bala/portfolio/contents/db/notion.db.tar.gz \ | |
| -d @payload.json |