name: Build And Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      tag_name:
        description: "Tag for the release (for example: v1.0.0)"
        required: true
        type: string

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    env:
      RELEASE_TAG: ${{ github.event.inputs.tag_name || github.ref_name }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Setup .NET SDK
        uses: actions/setup-dotnet@v5
        with:
          dotnet-version: "9.0.x"

      - name: Restore dependencies
        run: dotnet restore FoodsharingSiegen.sln

      - name: Publish server build
        run: dotnet publish ./FoodsharingSiegen.Server/FoodsharingSiegen.Server.csproj -c Release -o ./artifacts/publish

      - name: Create zip package
        run: |
          cd artifacts
          zip -r FoodsharingSiegen.Server-${{ env.RELEASE_TAG }}.zip publish

      - name: Create release and upload artifact
        uses: https://gitea.com/actions/gitea-release-action@v1
        with:
          files: artifacts/FoodsharingSiegen.Server-${{ env.RELEASE_TAG }}.zip
          tag_name: ${{ env.RELEASE_TAG }}
          name: Release ${{ env.RELEASE_TAG }}
          target_commitish: ${{ github.sha }}
          token: ${{ github.token }}
