sync and rebuild #8828
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 and rebuild | |
| on: | |
| schedule: | |
| - cron: '0 * * * *' | |
| workflow_dispatch: | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout target repository (blog) | |
| uses: actions/checkout@v3 | |
| - name: Clone obsidian private repository | |
| run: | | |
| git clone --depth=1 --filter=blob:none --sparse "https://${{ secrets.OBSIDIAN_SYNC_TOKEN }}@github.com/chanshiyucx/obsidian.git" obsidian | |
| cd obsidian | |
| git sparse-checkout set Album Article Journal Snippet | |
| continue-on-error: false | |
| - name: Sync obsidian directories | |
| run: | | |
| rsync -av --delete obsidian/Album/ ./album/ | |
| rsync -av --delete obsidian/Article/ ./article/ | |
| rsync -av --delete obsidian/Journal/ ./journal/ | |
| rsync -av --delete obsidian/Snippet/ ./snippet/ | |
| find . -name "SUMMARY.md" -delete | |
| continue-on-error: false | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| git add . | |
| git diff --staged --quiet || echo "changes=true" >> $GITHUB_OUTPUT | |
| - name: Commit and push changes | |
| if: steps.check_changes.outputs.changes == 'true' | |
| run: | | |
| git config user.name "chanshiyu" | |
| git config user.email "[email protected]" | |
| git commit -m "Sync blog from obsidian repository" | |
| git push | |
| continue-on-error: false | |
| - name: Check for Markdown Changes | |
| id: check_md_changes | |
| if: steps.check_changes.outputs.changes == 'true' | |
| run: | | |
| git diff --name-status HEAD^ HEAD | grep '\.md$' && echo "has_md_changes=true" >> $GITHUB_OUTPUT || echo "No markdown changes detected" | |
| - name: Trigger Vercel Deploy | |
| if: steps.check_md_changes.outputs.has_md_changes == 'true' | |
| run: | | |
| curl -X POST -d {} "${{ secrets.VERCEL_DEPLOY_HOOK }}" |