name: Build packages and store artifacts

on: [workflow_dispatch, workflow_call]
    
jobs:
  build:
    runs-on: ubuntu-latest    
    timeout-minutes: 5
    steps:   

      # ---------------------------------------------  DotNet SDK

    - name: Setup .NET SDK
      uses: actions/setup-dotnet@v4

      # ---------------------------------------------  checkout repo

    - name: Checkout
      uses: actions/checkout@v4

      # ---------------------------------------------  install dependencies

    - name: Install dependencies
      run: dotnet tool restore

    - name: Install dependencies
      run: dotnet restore

    - name: define version suffix
      run: |
          if [ -z "${{ env.VERSIONSUFFIX }}" ]; then
          echo "VERSIONSUFFIX=${{ inputs.version-suffix }}" >> $GITHUB_ENV
          fi
          if [ -z "${{ env.VERSIONSUFFIX }}" ]; then
          echo "VERSIONSUFFIX=Test-$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV          
          fi
          echo "VERSIONSUFFIX is set to ${{ env.VERSIONSUFFIX }}"

      # ---------------------------------------------  build

    - name: Build
      run: dotnet build -c Release --version-suffix ${{ env.VERSIONSUFFIX }}
    
    - name: Pack
      run: dotnet pack -c Release --no-build --output "."

    - name: Archive
      uses: actions/upload-artifact@v4
      with:
        name: nuget-packages
        retention-days: 1
        path: |
            *.nupkg
            *.snupkg