name: 📦️ Merge templates
on:
  workflow_call:
    inputs:
      godot-ref:
        description: A tag, branch or commit hash in the Godot repository.
        type: string
      limboai-ref:
        description: A tag, branch or commit hash in the LimboAI repository.
        type: string

  workflow_dispatch:
    inputs:
      godot-ref:
        description: A tag, branch or commit hash in the Godot repository.
        type: string
      limboai-ref:
        description: A tag, branch or commit hash in the LimboAI repository.
        type: string

jobs:
  merge-templates:
    runs-on: ubuntu-latest
    steps:
      - name: Clone Godot
        uses: actions/checkout@v4
        with:
          repository: godotengine/godot
          ref: ${{ inputs.godot-ref }}

      - name: Clone LimboAI module
        uses: actions/checkout@v4
        with:
          path: modules/limboai
          ref: ${{ inputs.limboai-ref }}

      # Inits GODOT_VERSION, LIMBOAI_VERSION and NAME_PREFIX environment variables.
      - uses: ./modules/limboai/.github/actions/init-version

      - name: Merge classical templates
        uses: actions/upload-artifact/merge@v4
        with:
          name: ${{env.NAME_PREFIX}}.export-templates
          pattern: ${{env.NAME_PREFIX}}.{export-templates,template_}*
          delete-merged: true

      - name: Merge .NET templates
        uses: actions/upload-artifact/merge@v4
        with:
          name: ${{env.NAME_PREFIX}}.dotnet.export-templates
          pattern: ${{env.NAME_PREFIX}}.dotnet.{export-templates,template_}*
          delete-merged: true
