name: Publish a new release

permissions:
  contents: write

on:
  push:
    branch: stable
    tags:
      - "v?[0-9]*"

  workflow_dispatch:
    inputs:
      draft:
        description: "Draft"
        required: true
        type: boolean
        default: false
      prerelease:
        description: "Prerelease"
        required: true
        type: boolean
        default: false
      release_name:
        description: "Release name"
        required: true
        type: string
        default: "Release name"
      tag_name:
        description: "Tag name"
        required: false
        type: string
        default: github.ref_name

jobs:
  package_multiplatform:
    name: Build release assets
    if: vars.RELEASE_ENABLE == 'true'
    uses: ./.github/workflows/job_build_game.yml
    secrets: inherit

  publish_release:
    if: vars.RELEASE_ENABLE == 'true'
    name: Create a GitHub release
    needs:
      - package_multiplatform
    with:
      release_name: ${{ inputs.release_name }}
      draft: ${{ inputs.draft || false }}
      prerelease: ${{ inputs.draft || false }}
      tag_name: ${{ inputs.tag_name || github.ref_name }}
    uses: ./.github/workflows/job_release.yml
