variables:
 NUGET_PATH: 'C:\Tools\nuget.exe'
 MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe'
 SOL_NAME: 'IOB-WIN-NEXT'
 APP_NAME: 'IOB-WIN-NEXT'
 NUM_REL: '0.1.2.3'
 NUM_DEB: '0.1.2-beta.3'
 CONFIG: ''
 VERS_MAIN: '3.9'
 NEW_REL: ''
 OUTPUT_DIR: ''
 NET_SHARE_X: '\\codedoc.egalware.com\library'
 NET_USER_X: 'gitlab'
 NEXUS_PATH: 'MAPO/IOB-WIN-NEXT'
 URL_VERSIONS_LOG: "https://liman.egalware.com/ELM.API/api/release/save"
 CRITICAL_STRING: "#critical#"

.DocReplica: &DocReplica
  - |
    net use A: /delete
    net use A: $env:NET_SHARE_X /u:$env:NET_USER_X $XDRIVE_PASSWD
    ROBOCOPY docfx A:\$env:APP_NAME /MIR /XF .git* /XD .git
    SLEEP 2
    net use A: /delete

# helper x fix pacchetti nuget da repo locale nexus.steamware.net
.nuget-fix: &nuget-fix
   - |
      echo "esecuzione Nuget FIX steps"
      dotnet nuget list source
      $hasSource = dotnet nuget list source | Select-String -Pattern "Steamware Nexus Proxy"
      if (! [String]::IsNullOrWhiteSpace($hasSource)) {
        dotnet nuget remove source "`"Steamware Nexus Proxy`""
      }
      $hasSource = dotnet nuget list source | Select-String -Pattern "Steamware Nexus"
      if (! [String]::IsNullOrWhiteSpace($hasSource)) {
        dotnet nuget remove source "`"Steamware Nexus`""
      }
      $hasSource = dotnet nuget list source | Select-String -Pattern "nexus-proxy-v3"
      if (! [String]::IsNullOrWhiteSpace($hasSource)) {
        dotnet nuget remove source nexus-proxy-v3
      }
      $hasSource = dotnet nuget list source | Select-String -Pattern "nexus-hosted"
      if (! [String]::IsNullOrWhiteSpace($hasSource)) {
        dotnet nuget remove source nexus-hosted
      }
      $hasSource = dotnet nuget list source | Select-String -Pattern "Microsoft Visual Studio Offline Packages"
      if (! [String]::IsNullOrWhiteSpace($hasSource)) {
        dotnet nuget remove source 'Microsoft Visual Studio Offline Packages'
      }
      echo "Situazione sorgenti post remove:"
      dotnet nuget list source 
      dotnet nuget add source https://nexus.steamware.net/repository/nuget-proxy-v3/index.json -n nexus-proxy-v3 -u nugetUser -p $NEXUS_PASSWD --store-password-in-clear-text
      dotnet nuget add source https://nexus.steamware.net/repository/nuget-hosted/ -n nexus-hosted -u nugetUser -p $NEXUS_PASSWD --store-password-in-clear-text
      $hasSource = dotnet nuget list source
      echo "Situazione sorgenti FINALE:"
      dotnet nuget list source 

# helper x fix version number
.version-fix: &version-fix
   - |
      $env:NEW_REL = $env:VERS_MAIN+"."+(get-date -format yyMM)+"."+(get-date -format ddHH)
      $env:NUM_REL = $env:VERS_MAIN+"."+(get-date -format yyMM)+"."+(get-date -format dHH)
      $env:NUM_DEB = $env:VERS_MAIN+"."+(get-date -format yyMM)+"-beta."+(get-date -format dHH)
      $env:NEW_COPYRIGHT = "EgalWare @ 2006-" + (get-date -format yyyy) 
      $contenuto = Get-Content -path 'VersGen\VersGen.cs' -Raw
      $newContenuto = $contenuto -replace '0.0.0.0', $env:NEW_REL
      $newContenuto = $newContenuto -replace 'EgalWare © 2006', $env:NEW_COPYRIGHT
      $newContenuto | Set-Content -Path 'VersGen\VersGen.cs'  
      # display versioni generate
      $resoconto = "Effettuato fix file VersGen | release v: " + $env:NUM_REL + " | debug v: " + $env:NUM_DEB;
      Write-Output $resoconto;
      echo "Replace completati"

# helper x fix nuspec file
.nuspec-fix: &nuspec-fix
   - |
      echo "Modifica dati file nuspec Release"
      $currRelease = $env:NUM_REL
      $currDebug = $env:NUM_DEB 
      $find = "<version>(.|\n)*?</version>";
      $fileNameRel = "$env:APP_NAME.Release.nuspec";
      $replRel = "<version>" + $currRelease + "</version>";
      $nuspDataRel = Get-Content $fileNameRel;
      $nuspDataRelUpd = $nuspDataRel -replace $find, $replRel;
      $nuspDataRelUpd = $nuspDataRelUpd -replace "#copyright#", $replCopy;
      $nuspDataRelUpd = $nuspDataRelUpd -replace "#releaseNotes#", "Build $adesso";
      Set-Content -Path $fileNameRel -Value $nuspDataRelUpd;
      echo "Modifica dati file nuspec Debug"
      $fileNameDeb = "$env:APP_NAME.Debug.nuspec";
      $replDeb = "<version>" + $currDebug + "</version>";
      $nuspDataDeb = Get-Content $fileNameDeb;
      $nuspDataDebUpd = $nuspDataDeb -replace $find, $replDeb;
      $nuspDataDebUpd = $nuspDataDebUpd -replace "#copyright#", $replCopy;
      $nuspDataDebUpd = $nuspDataDebUpd -replace "#releaseNotes#", "Build $adesso";
      Set-Content -Path $fileNameDeb -Value $nuspDataDebUpd;
      echo "replace completati"

# helper pulizia files zip
.cleanup-zip: &cleanup-zip
   - |
      $env:OUTPUT_DIR = "Releases\" + $CI_COMMIT_BRANCH + "\*"
      if ((Test-Path $env:OUTPUT_DIR))
      {
        Remove-Item $env:OUTPUT_DIR -Force -Recurse -ErrorAction Ignore
      }
      echo "Clening ZIP dir: $env:OUTPUT_DIR"

# helper creazione files zip
.zipper: &zipper
   - |
      $7zipPath = $env:ProgramFiles+"\7-Zip\7z.exe"
      if (-not (Test-Path -Path $7zipPath -PathType Leaf)) {
          throw "7 zip file '$7zipPath' not found"
      }
      Set-Alias 7zip $7zipPath
      $Target = "Releases\" + $CI_COMMIT_BRANCH + "\" + $env:APP_NAME + ".zip"
      cd "$env:APP_NAME\bin\"
      $Source = "*"
      7zip a -tzip $Target $Source  -xr!DATA\CONF
      echo "called ZIP $Source --> $Target"      
      
# helper creazione hash files
.hashBuild: &hashBuild
   - |
      $Target = "Releases\" + $CI_COMMIT_BRANCH + "\" + $env:APP_NAME + ".zip"
      $MD5 = Get-FileHash $Target -Algorithm MD5
      $SHA1 = Get-FileHash $Target -Algorithm SHA1
      New-Item $Target".md5"
      New-Item $Target".sha1"
      $MD5.Hash | Set-Content -Path $Target".md5"
      $SHA1.Hash | Set-Content -Path $Target".sha1"
      echo "Created HASH files for $Target"      

.nexusUpload: &nexusUpload
   - |
      Set-Alias mCurl  C:\Windows\system32\curl.exe
      $VersNumb = $env:NEW_REL
      echo "Curr Version: $VersNumb"     
      if($CI_COMMIT_BRANCH -eq "master")
      {
        $version = "stable"
      }
      else
      {
        $version = "unstable"
      }
      $File2Send = Get-ChildItem("Releases\" + $CI_COMMIT_BRANCH + "\" + $env:APP_NAME + ".*")
      ForEach ($File in $File2Send) {
        $FileName = Split-Path $File -leaf
        mCurl -v -u GitLab:$NEXUS_PASSWD --upload-file $File https://nexus.steamware.net/repository/SWS/$env:NEXUS_PATH/$version/LAST/$FileName
        mCurl -v -u GitLab:$NEXUS_PASSWD --upload-file $File https://nexus.steamware.net/repository/SWS/$env:NEXUS_PATH/$version/ARCHIVE/$VersNumb/$FileName
      }
      echo "Upload area utility for Releases\$CI_COMMIT_BRANCH\$env:APP_NAME.*" 
      $FileUtility = Get-ChildItem("Releases\$CI_COMMIT_BRANCH\$env:APP_NAME.*")
      ForEach ($File in $FileUtility) {
        $FileName = Split-Path $File -leaf
        mCurl -v -u GitLab:$NEXUS_PASSWD --upload-file $File https://nexus.steamware.net/repository/utility/MAPO/$env:APP_NAME/$version/$FileName
      }

# helper invio notifica a log versioni online (LiMan)
.SendToVersionsLog: &SendToVersionsLog
   - |
      echo "----------------------------------------------"
      echo "   Invio versione a Liman x log online"
      echo "----------------------------------------------"
      $tags = ""
      # se critico scrive tag
      if ( $CI_COMMIT_MESSAGE | Select-String -Pattern $env:CRITICAL_STRING) {
         $tags = "CRITICAL"
      }
      $date = (Get-Date).toString("yyyy-MM-ddTHH:mm:ss.fffZ")
      $body =
      @{
            codInst = "EgalWare"
            codApp = $env:APP_NAME
            uplAppId = "UpdateManager"
            masterKey = $LiMan_Key
            tipo = "WinApp"
            versNum = $env:NEW_REL
            versText = $env:NEW_REL
            releaseDate = $date
            relTags = $tags
      }
      $jsonBody = ConvertTo-Json -InputObject $body
      echo $jsonBody
      Invoke-WebRequest -Method Post -URI $env:URL_VERSIONS_LOG -ContentType "application/json" -Body $jsonBody -UseBasicParsing


stages:
 - build
 - release
 - docfx

# --------------------------------
# BUILD
# --------------------------------
IOB-WIN:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-FANUC:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FANUC
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-FILE:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FILE
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-FTP:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FTP
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-KAWASAKI:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-KAWASAKI
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
 
IOB-WIN-MBUS:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MBUS
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
 
IOB-WIN-MITSUBISHI:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MITSUBISHI
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-MTC:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MTC
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-NEXT:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-NEXT
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-OMRON:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OMRON
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-OPC-UA:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OPC-UA
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-OSAI:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OSAI
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-PING:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-PING
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-SHELLY:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SHELLY
    VERS_MAIN: '4.0'
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-SIEMENS:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SIEMENS
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-SQL:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SQL
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-WPS:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-WPS
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

IOB-WIN-WS:build:
  stage: build
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-WS
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'

# --------------------------------
# RELEASE
# --------------------------------
IOB-WIN:release:
  stage: release
  needs: ["IOB-WIN:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN
    NEXUS_PATH: MAPO/IOB-WIN
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN/*
        - IOB-WIN/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-FANUC:release:
  stage: release
  needs: ["IOB-WIN-FANUC:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FANUC
    NEXUS_PATH: MAPO/IOB-WIN-FANUC
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-FANUC/*
        - IOB-WIN-FANUC/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-FILE:release:
  stage: release
  needs: ["IOB-WIN-FILE:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FILE
    NEXUS_PATH: MAPO/IOB-WIN-FILE
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-FILE/*
        - IOB-WIN-FILE/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-FTP:release:
  stage: release
  needs: ["IOB-WIN-FTP:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FTP
    NEXUS_PATH: MAPO/IOB-WIN-FTP
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-FTP/*
        - IOB-WIN-FTP/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-KAWASAKI:release:
  stage: release
  needs: ["IOB-WIN-KAWASAKI:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-KAWASAKI
    NEXUS_PATH: MAPO/IOB-WIN-KAWASAKI
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-KAWASAKI/*
        - IOB-WIN-KAWASAKI/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-MBUS:release:
  stage: release
  needs: ["IOB-WIN-MBUS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MBUS
    NEXUS_PATH: MAPO/IOB-WIN-MBUS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-MBUS/*
        - IOB-WIN-MBUS/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-MITSUBISHI:release:
  stage: release
  needs: ["IOB-WIN-MITSUBISHI:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MITSUBISHI
    NEXUS_PATH: MAPO/IOB-WIN-MITSUBISHI
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-MITSUBISHI/*
        - IOB-WIN-MITSUBISHI/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-MTC:release:
  stage: release
  needs: ["IOB-WIN-MTC:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MTC
    NEXUS_PATH: MAPO/IOB-WIN-MTC
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-MTC/*
        - IOB-WIN-MTC/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-NEXT:release:
  stage: release
  needs: ["IOB-WIN-NEXT:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-NEXT
    NEXUS_PATH: MAPO/IOB-WIN-NEXT
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-NEXT/*
        - IOB-WIN-NEXT/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-OMRON:release:
  stage: release
  needs: ["IOB-WIN-OMRON:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OMRON
    NEXUS_PATH: MAPO/IOB-WIN-OMRON
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-OMRON/*
        - IOB-WIN-OMRON/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-OPC-UA:release:
  stage: release
  needs: ["IOB-WIN-OPC-UA:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OPC-UA
    NEXUS_PATH: MAPO/IOB-WIN-OPC-UA
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-OPC-UA/*
        - IOB-WIN-OPC-UA/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-OSAI:release:
  stage: release
  needs: ["IOB-WIN-OSAI:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OSAI
    NEXUS_PATH: MAPO/IOB-WIN-OSAI
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-OSAI/*
        - IOB-WIN-OSAI/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-PING:release:
  stage: release
  needs: ["IOB-WIN-PING:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-PING
    NEXUS_PATH: MAPO/IOB-WIN-PING
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-PING/*
        - IOB-WIN-PING/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-SHELLY:release:
  stage: release
  needs: ["IOB-WIN-SHELLY:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SHELLY
    NEXUS_PATH: MAPO/IOB-WIN-SHELLY
    VERS_MAIN: '4.0'
  # rules:
  #   - if: $CI_COMMIT_BRANCH == 'master'
  #     changes: 
  #       - IOB-WIN-SHELLY/*
  #       - IOB-WIN-SHELLY/**/*
  #     when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-SIEMENS:release:
  stage: release
  needs: ["IOB-WIN-SIEMENS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SIEMENS
    NEXUS_PATH: MAPO/IOB-WIN-SIEMENS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-SIEMENS/*
        - IOB-WIN-SIEMENS/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-SQL:release:
  stage: release
  needs: ["IOB-WIN-SQL:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SQL
    NEXUS_PATH: MAPO/IOB-WIN-SQL
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-SQL/*
        - IOB-WIN-SQL/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-WPS:release:
  stage: release
  needs: ["IOB-WIN-WPS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-WPS
    NEXUS_PATH: MAPO/IOB-WIN-WPS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-WPS/*
        - IOB-WIN-WPS/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

IOB-WIN-WS:release:
  stage: release
  needs: ["IOB-WIN-WS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-WS
    NEXUS_PATH: MAPO/IOB-WIN-WS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-WS/*
        - IOB-WIN-WS/**/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
    - *version-fix
    - *cleanup-zip
  script:  
    - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=Release /p:Platform="x86" /p:OutputPath=bin/ /nodeReuse:false /verbosity:minimal /m'
    - *zipper
    - *hashBuild
    - *nexusUpload
    - *SendToVersionsLog

# --------------------------------
# DocFx
# --------------------------------

IOB-WIN-FANUC:docfx:
  stage: docfx
  needs: ["IOB-WIN-FANUC:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FANUC
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-FANUC/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-FILE:docfx:
  stage: docfx
  needs: ["IOB-WIN-FILE:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FILE
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-FILE/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-FTP:docfx:
  stage: docfx
  needs: ["IOB-WIN-FTP:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-FTP
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-FTP/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-KAWASAKI:docfx:
  stage: docfx
  needs: ["IOB-WIN-KAWASAKI:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-KAWASAKI
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-KAWASAKI/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-MBUS:docfx:
  stage: docfx
  needs: ["IOB-WIN-MBUS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MBUS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-MBUS/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-MITSUBISHI:docfx:
  stage: docfx
  needs: ["IOB-WIN-MITSUBISHI:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MITSUBISHI
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-MITSUBISHI/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-MTC:docfx:
  stage: docfx
  needs: ["IOB-WIN-MTC:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-MTC
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-MTC/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-NEXT:docfx:
  stage: docfx
  needs: ["IOB-WIN-NEXT:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-NEXT
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-NEXT/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-OMRON:docfx:
  stage: docfx
  needs: ["IOB-WIN-OMRON:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OMRON
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-OMRON/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-OPC-UA:docfx:
  stage: docfx
  needs: ["IOB-WIN-OPC-UA:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OPC-UA
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-OPC-UA/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-OSAI:docfx:
  stage: docfx
  needs: ["IOB-WIN-OSAI:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-OSAI
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-OSAI/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-PING:docfx:
  stage: docfx
  needs: ["IOB-WIN-PING:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-PING
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-PING/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-SHELLY:docfx:
  stage: docfx
  needs: ["IOB-WIN-SHELLY:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SHELLY
    VERS_MAIN: '4.0'
  # rules:
  #   - if: $CI_COMMIT_BRANCH == 'master'
  #     changes: 
  #       - IOB-WIN-SHELLY/*
  #     when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-SIEMENS:docfx:
  stage: docfx
  needs: ["IOB-WIN-SIEMENS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SIEMENS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-SIEMENS/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-SQL:docfx:
  stage: docfx
  needs: ["IOB-WIN-SQL:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-SQL
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-SQL/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-WPS:docfx:
  stage: docfx
  needs: ["IOB-WIN-WPS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-WPS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-WPS/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica

IOB-WIN-WS:docfx:
  stage: docfx
  needs: ["IOB-WIN-WS:build"]
  tags:
    - win
  variables:
    APP_NAME: IOB-WIN-WS
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes: 
        - IOB-WIN-WS/*
      when: always
  before_script:
    - *nuget-fix
    - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet'
  script:
    - docfx $env:APP_NAME/docfx.json
    - mv $env:APP_NAME/_site "docfx"
    - *DocReplica
