name: Build and Release

on:
  push:
    tags:
      - "*.*.*.*"

jobs:
  Build:
    runs-on: ubuntu-latest
    env:
        DALAMUD_HOME: /tmp/dalamud
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Set up .NET
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: 9.0.x
          
      - name: Download Dalamud Latest
        run: |
          wget https://goatcorp.github.io/dalamud-distrib/latest.zip -O ${{ env.DALAMUD_HOME }}.zip
          unzip ${{ env.DALAMUD_HOME }}.zip -d ${{ env.DALAMUD_HOME }}

      - name: Restore Project
        run: dotnet restore

      - name: Build Project
        run: dotnet build --configuration Release SpotifyHonorific/SpotifyHonorific.csproj -p:AssemblyVersion=${{ github.ref_name }}

      - name: Create Release
        uses: actions/create-release@v1
        id: create_release
        with:
          draft: false
          prerelease: false
          release_name: ${{ github.ref_name }}
          tag_name: ${{ github.ref_name }}
        env:
          GITHUB_TOKEN: ${{ github.token }}

      - name: Upload Release Asset
        uses: actions/upload-release-asset@v1
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: SpotifyHonorific/bin/Release/SpotifyHonorific/latest.zip
          asset_name: SpotifyHonorific.zip
          asset_content_type: application/zip
        env:
          GITHUB_TOKEN: ${{ github.token }}