name: Publish
on:
  push:
    tags:
      - '*.*.*.*'
jobs:
  Build:
    permissions:
      contents: write
    runs-on: windows-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v6
        with:
          submodules: true
          
      - name: Get Environment Variables
        run: |
          $tag = "${{ github.ref }}" -replace 'refs/tags/', ''

          "tag=$tag" | Out-File -Append -FilePath $Env:GITHUB_ENV
          
      - name: Set up .NET
        uses: actions/setup-dotnet@v5
        with:
          dotnet-version: '10.0.x'

      - name: Download Dalamud Latest
        run: |
          Invoke-WebRequest -Uri https://goatcorp.github.io/dalamud-distrib/stg/latest.zip -OutFile latest.zip
          Expand-Archive -Force latest.zip -DestinationPath "$env:AppData\XIVLauncher\addon\Hooks\dev"

      - name: Restore Nuget Packages for RSR
        run: dotnet restore RotationSolver/RotationSolver.csproj

      - name: Build Plugin
        run: dotnet build --no-restore -c Release RotationSolver/RotationSolver.csproj -p:AssemblyVersion=${{ env.tag }} -p:FileVersion=${{ env.tag }} -p:PackageVersion=${{ env.tag }} -p:InformationalVersion=${{ env.tag }} --output .\build

      - name: Publish Plugin
        uses: softprops/action-gh-release@v3
        with:
          files: ./build/RotationSolver/latest.zip
          token: ${{ secrets.GITHUB_TOKEN }}
