
name: Push nuget and docker image Actions Workflow

on:
  push:
    branches:        
      - stage
jobs:
  Deploy:
    runs-on: windows
    steps:
      - name: Checkout
        uses: https://git.afrino.co/actions/checkout@v3
      - name: Setup dotnet
        uses: https://git.afrino.co/actions/setup-dotnet@v3
        with:
          dotnet-version: 7.0.x
      
      - name: Remove Package Source
        run: dotnet nuget remove source FourSat
        continue-on-error: true
      - name: Add Package Source
        run: dotnet nuget add source --name FourSat --username systemuser --password sZSA7PTiv3pUSQZ https://git.afrino.co/api/packages/FourSat/nuget/index.json --store-password-in-clear-text

      - name: Install dependencies
        run: dotnet restore ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj"
      - name: Build
        run: dotnet build ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj" --configuration Release --no-restore
      - name: Test
        run: dotnet test ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj" --no-restore --verbosity normal
      - name: Recycle Apppool
        run: |
          & "C:\Windows\System32\inetsrv\appcmd.exe" recycle apppool /apppool.name:cms.kbs1.ir
        shell: powershell
      - name: Stop Website
        run: |
          & "C:\Windows\System32\inetsrv\appcmd.exe" stop site /site.name:cms.kbs1.ir
        shell: powershell
      - name: Publish
        run: dotnet publish ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj" -c Release -o publish
      - name: Copy Publish To IIS Directory
        run: Get-ChildItem -Path "publish\*" | Copy-Item -Destination "E:\kbs1.ir\cms.kbs1.ir\" -Recurse -Force
      - name: Start Website
        run: |
          & "C:\Windows\System32\inetsrv\appcmd.exe" start site /site.name:cms.kbs1.ir
        shell: powershell
