name: NuGet Preview Release

on:
  schedule:
  - cron: "5 4 3 */1 *" # once a month, at 4:05 on 3rd
  workflow_dispatch:

jobs:
  release:
    name: Release Preview
    runs-on: ubuntu-latest
    environment: NuGet
    timeout-minutes: 10

    env:
      PYTHONNET_SHUTDOWN_MODE: Normal

    steps:
      - name: Get Date
        run: |
          echo "DATE_VER=$(date "+%Y-%m-%d")" >> $GITHUB_ENV

      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup .NET
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '6.0.x'

      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
          architecture: x64

      - name: Install dependencies
        run: |
          pip install --upgrade -r requirements.txt
          pip install numpy # for tests

      - name: Build and Install
        run: |
          pip install -v .

      - name: Set Python DLL path (non Windows)
        if: ${{ matrix.os != 'windows' }}
        run: |
          echo PYTHONNET_PYDLL=$(python -m find_libpython) >> $GITHUB_ENV

      - name: Python Tests
        run: pytest

      - name: Embedding tests
        run: dotnet test --runtime any-ubuntu src/embed_tests/

      - name: Pack
        run: dotnet pack --configuration Release --version-suffix preview${{env.DATE_VER}} --output "Release-Preview"

      - name: Publish NuGet
        run: |
          dotnet nuget push --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_MONTHLY }} Release-Preview/*.nupkg
          dotnet nuget push --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_MONTHLY }} Release-Preview/*.snupkg
