name: Publish Markdown Files
env:
  BLOG_REPO: matthewwong525/linked-blog-starter
  PUBLISH_DIR: publish
on:
  push:
    branches: [main]
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v3
      with:
        path: temp_md
    - name: Checkout linked blog starter repo
      uses: actions/checkout@v3
      with:
        path: temp_blog
        repository: ${{ env.BLOG_REPO }}
    - name: Install Rust / cargo
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
    - name: Install and run obsidian-export
      run: |
        cargo install obsidian-export
        rm -rf temp_blog/common_md && mkdir temp_blog/common_md
        ~/.cargo/bin/obsidian-export ./temp_md/${{ env.PUBLISH_DIR }} temp_blog/common_md
    - name: Move blog dir to currDir
      run: |
        cp -r temp_blog/. .
        rm -rf temp_blog
        rm -rf temp_md
    - name: Deploy Vercel
      uses: amondnet/vercel-action@v20
      with:
        # TODO: Update Github Secrets with values
        vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
        vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}  # Required
        vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} # Required 
        vercel-args: '--prod' #Optional
