name: Release

on:
  push:
    branches: ['**']   # every commit on any branch -> nightly
    tags: ['**']       # any tag push -> versioned draft
  workflow_dispatch:

# The default token is read-only; release/tag operations need write.
permissions:
  contents: write

jobs:
  export_game:
    runs_on: Debian-x86
    permissions:
      contents: write
    name: Export Game
    steps:
    - name: checkout
      uses: actions/checkout@v5
    - name: install .NET SDK
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: '8.0.x'
    - name: install 7zip
      run: apt-get update && apt-get install -y p7zip-full
    - name: export game
      id: export
      uses: firebelley/godot-export@v8.0.0
      with:
        godot_executable_download_url: https://godot-releases.nbg1.your-objectstorage.com/4.6.3-stable/Godot_v4.6.3-stable_mono_linux_x86_64.zip
        godot_export_templates_download_url: https://godot-releases.nbg1.your-objectstorage.com/4.6.3-stable/Godot_v4.6.3-stable_mono_export_templates.tpz
        relative_project_path: ./
        archive_output: true
        # cache: true # doesn't work on gitea

    # --- not tagged: rolling nightly, updates the existing release ---
    - name: create nightly release
      if: ${{ !startsWith(github.ref, 'refs/tags/') }}
      uses: akkuman/gitea-release-action@v1
      with:
        tag_name: nightly
        target_commitish: ${{ github.sha }}
        name: Latest Nightly Build
        prerelease: true
        files: ${{ steps.export.outputs.archive_directory }}/*

    # --- tagged with a version: versioned draft release ---
    - name: create versioned release draft
      if: ${{ startsWith(github.ref, 'refs/tags/') }}
      uses: akkuman/gitea-release-action@v1
      with:
        tag_name: ${{ github.ref_name }}
        name: ${{ github.ref_name }}
        draft: true
        files: ${{ steps.export.outputs.archive_directory }}/*