Vault backup: 2023-10-24 22:21:55 #101
This file contains 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: Copy to Quartz clone | |
on: | |
push: | |
branches: | |
- main # or your default branch | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout obsidian-vault | |
uses: actions/checkout@v3 | |
with: | |
path: obsidian-vault | |
- name: Checkout obsidian-quartz | |
uses: actions/checkout@v3 | |
with: | |
repository: wongd-hub/obsidian-quartz | |
path: obsidian-quartz | |
token: ${{ secrets.REPO_ACCESS_TOKEN }} | |
- name: Clear obsidian-quartz content folder | |
run: rm -rf obsidian-quartz/content/* | |
- name: Copy obsidian-vault contents to obsidian-quartz/content | |
run: | | |
cp -R obsidian-vault/. obsidian-quartz/content/ | |
rm -rf .github .trash .gitignore README.md | |
- name: Add front-matter to each .md file | |
run: | | |
cd obsidian-quartz/content | |
find . -name "*.md" -exec sh -c 'if [ "$(head -n 1 "$1")" != "---" ]; then echo "---\ntitle: \"$(basename "${1%.*}")\"\n---\n$(cat "$1")" > "$1"; fi' _ {} \; | |
- name: Commit and push to obsidian-quartz if there's a change | |
run: | | |
cd obsidian-quartz | |
git config --global user.email "actions@github.com" | |
git config --global user.name "GitHub Action" | |
git remote set-url origin https://${{ secrets.REPO_ACCESS_TOKEN }}@github.com/wongd-hub/obsidian-quartz.git | |
git add . | |
if git diff --quiet HEAD; then | |
echo "No changes detected. Nothing to commit." | |
exit 0 | |
fi | |
git commit -m "Sync obsidian-vault to obsidian-quartz" | |
git push | |