name: "[Single] Create Updater"

on:
  workflow_dispatch:
    inputs:
      nightly:
        description: "Nightly"
        required: true
        type: boolean
        default: false
      release_body:
        description: "Release Body"
        required: false
        type: string
  workflow_call:
    inputs:
      nightly:
        description: "Nightly"
        required: true
        type: boolean
        default: false
      release_body:
        description: "Release Body"
        required: false
        type: string

jobs:
  updater:
    name: Update Updater
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
          # blocked by https://github.com/actions/checkout/issues/1467
      - name: Fetch git tags
        run: git fetch --tags
      - name: Install Node latest
        uses: actions/setup-node@v4
        with:
          node-version: latest

      - uses: pnpm/action-setup@v4
        name: Install pnpm
        with:
          run_install: false

      - name: Pnpm install
        run: pnpm i

      - name: Update Nightly Updater
        if: ${{ inputs.nightly == true }}
        run: pnpm updater:nightly
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Update Stable Updater
        if: ${{ inputs.nightly == false }}
        run: pnpm updater
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          RELEASE_BODY: ${{ inputs.release_body || github.event.release.body }}
