name: Pack Nightly

on:
  workflow_dispatch:
    inputs:
      Version_Prefix:
        description: 'Version Prefix'
        required: true
        default: '11.2.999'
        type: string
      Semi_Avalonia:
        description: 'Pack Semi.Avalonia'
        required: true
        default: 'true'
        type: boolean
      Semi_Avalonia_ColorPicker:
        description: 'Pack Semi.Avalonia.ColorPicker'
        required: true
        default: 'true'
        type: boolean
      Semi_Avalonia_DataGrid:
        description: 'Pack Semi.Avalonia.DataGrid'
        required: true
        default: 'true'
        type: boolean
      Semi_Avalonia_TreeDataGrid:
        description: 'Pack Semi.Avalonia.TreeDataGrid'
        required: true
        default: 'false'
        type: boolean

jobs:
  Pack_Nightly:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.1

      - name: Get Version
        run: |
          VERSION_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
          VERSION="${{ github.event.inputs.Version_Prefix }}-nightly-${VERSION_TIMESTAMP}"
          echo "VERSION=$VERSION" >> $GITHUB_ENV

      - name: Pack Semi.Avalonia
        if: ${{ github.event.inputs.Semi_Avalonia == 'true' }}
        run: dotnet pack ./src/Semi.Avalonia -o ./nugets /p:Version=${{ env.VERSION }}

      - name: Pack Semi.Avalonia.ColorPicker
        if: ${{ github.event.inputs.Semi_Avalonia_ColorPicker == 'true' }}
        run: dotnet pack ./src/Semi.Avalonia.ColorPicker -o ./nugets /p:Version=${{ env.VERSION }}

      - name: Pack Semi.Avalonia.DataGrid
        if: ${{ github.event.inputs.Semi_Avalonia_DataGrid == 'true' }}
        run: dotnet pack ./src/Semi.Avalonia.DataGrid -o ./nugets /p:Version=${{ env.VERSION }}

      - name: Pack Semi.Avalonia.TreeDataGrid
        if: ${{ github.event.inputs.Semi_Avalonia_TreeDataGrid == 'true' }}
        run: dotnet pack ./src/Semi.Avalonia.TreeDataGrid -o ./nugets /p:Version=${{ env.VERSION }}

      - name: Add NuGet Source
        run: dotnet nuget add source ${{ secrets.IRIHI_NUGET_NIGHTLY_FEED }} -n irihi.tech -u ${{ secrets.IRIHI_NUGET_USERNAME }} -p ${{ secrets.IRIHI_NUGET_PASSWORD }} --store-password-in-clear-text

      - name: Publish Nightly Package
        run: dotnet nuget push "./nugets/*.nupkg" --api-key ${{ secrets.IRIHI_NUGET_API_KEY }} --source irihi.tech --skip-duplicate

      - name: Upload a Build Artifact
        uses: actions/upload-artifact@v4.3.1
        with:
          name: nugets
          path: ./nugets
        if: always()