name: Publish PREVIEW artifacts to NUGET

on: workflow_dispatch
    
jobs:

  main_job:
    runs-on: ubuntu-latest
    permissions:
      contents: write # required for pushing the tag    
    
    steps:

    - name: Checkout
      uses: actions/checkout@v4

    - name: Define Version at GHENV_PACKAGEVERSION
      run: |
        chmod +x ./.github/workflows/FormatSemver.sh
        ./.github/workflows/FormatSemver.sh "${{ vars.SharpGLTF_Version }}-Preview-DATE-TIME" >> $GITHUB_ENV

    - name: build
      uses: ./.github/actions/Build
      with:
        nuget-semver: "${{env.GHENV_PACKAGEVERSION}}"

    - name: Download all artifacts
      uses: actions/download-artifact@v4
      with:
        name: nuget-packages

    - name: Push to NuGet
      run: dotnet nuget push "*.nupkg" --api-key ${{secrets.SharpGLTF_PublishToNuget}} --source https://api.nuget.org/v3/index.json

    - name: create tag
      uses: ./.github/actions/PushGithubTag
      with:
        tag-name: "${{env.GHENV_PACKAGEVERSION}}"
        message: "new tag for ${{env.GHENV_PACKAGEVERSION}}"