name: Build SilverBullet Plug

on:
  push:
    branches: [ main ]
  workflow_dispatch:

permissions:
  contents: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Deno
        uses: denoland/setup-deno@v2
        with:
          deno-version: v2.x

      - name: Build Plug
        run: |
          deno task build -- --no-check

      - name: Commit and push changes
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add icalendar.plug.js
          if git diff --quiet --staged; then
            echo "No changes to commit"
          else
            git commit -m "Build and update icalendar.plug.js [skip ci]"
            git push origin main
          fi
