name: release

on:
  push:
    tags:
      - "*"
  workflow_dispatch:
    inputs:
      version:
        description: 'Version Number'
        required: true
        type: string

jobs:
  publish_obsidian_plugin:
    name: 💎 Publish Obsidian Plugin
    runs-on: ubuntu-latest
    permissions:
      contents: write
    defaults:
      run:
        shell: bash
        working-directory: src/interface/obsidian
    steps:
      - uses: actions/checkout@v3

      - name: Install Node
        uses: actions/setup-node@v3
        with:
          node-version: "lts/*"

      - name: ⚙️ Build Obsidian Plugin
        run: |
          yarn
          yarn run build --if-present

      - name: ⏫ Upload Obsidian Plugin main.js
        uses: actions/upload-artifact@v3
        with:
          if-no-files-found: error
          name: main.js
          path: src/interface/obsidian/main.js

      - name: ⏫ Upload Obsidian Plugin manifest.json
        uses: actions/upload-artifact@v3
        with:
          if-no-files-found: error
          name: manifest.json
          path: src/interface/obsidian/manifest.json

      - name: ⏫ Upload Obsidian Plugin styles.css
        uses: actions/upload-artifact@v3
        with:
          if-no-files-found: error
          name: styles.css
          path: src/interface/obsidian/styles.css

      - name: 🌈 Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          generate_release_notes: true
          files: |
            src/interface/obsidian/main.js
            src/interface/obsidian/manifest.json
            src/interface/obsidian/styles.css