BotBuilder-Samples/build/yaml/sample-dotnet-samplebot-win...

395 строки
16 KiB
YAML

# This is used in the pipelines Sample-DotNet-CoreBot-Win-Test-yaml and Sample-DotNet-EchoBot-Win-Test-yaml.
# 'Allow scripts to access the OAuth token' was selected in pipeline. Add the following YAML to any steps requiring access:
# env:
# MY_ACCESS_TOKEN: $(System.AccessToken)
# Variable 'AppId' is defined in Azure
# Variable 'AppSecret' is defined in Azure
# Variable 'AzureBotName' is defined in Azure
# Variable 'AzureSubscription' is defined in Azure
# Variable 'BotGroup' is defined in Azure
# Variable 'BuildConfiguration' is defined in Azure
# Variable 'DeleteResourceGroup' is defined in Azure
# Variable 'MyGetPersonalAccessToken' is defined in Azure
# Variable 'runCodesignValidationInjection' is defined in Azure
# Variable 'SampleBotName' is defined in Azure
# Variable 'SampleFolderName' is defined in Azure
# Variable 'SampleRootPath' is defined in Azure
# Variable Group 'SamplesE2ETestsVariableGroup' is defined in Azure
# Variable Group 'MyGetPersonalAccessTokenVariableGroup' is defined in Azure
# Define the build number format.
name: $(Build.BuildId)
parameters:
- name: testLatestPackage
displayName: Test latest v4 package version
type: boolean
default: true
- name: versionToTest
displayName: Version to test (Only if 'Test latest' is unchecked)
type: string
default: 'Example: 4.15.0-daily.20210714.258979.1220aed'
- name: packageFeed
displayName: Package feed to use
type: string
default: Azure
values:
- Azure
- MyGet
- NuGet
# Run this job every night at 2 AM (PST) on the main branch
schedules:
- cron: 0 9 * * *
displayName: Daily 2AM PST build
branches:
include:
- main
always: true
# Do not run PR validation
pr: none
# Do not run CI validation
trigger: none
resources:
repositories:
- repository: self
type: git
ref: main
#variables:
#- group: SamplesE2ETestsVariableGroup
#- group: MyGetPersonalAccessTokenVariableGroup
jobs:
- job: Job_1
displayName: Agent job 1
pool:
vmImage: windows-2022
steps:
- checkout: self
persistCredentials: True
- powershell: |
$file = "$(SampleRootPath)\nuget.config";
$content = @"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="ConversationalAI" value="https://pkgs.dev.azure.com/ConversationalAI/BotFramework/_packaging/SDK/nuget/v3/index.json" />
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
"@;
New-Item -Path $file -ItemType "file" -Value $content;
'-------------'; get-content "$file"; '===================';
displayName: Create nuget.config for Azure feed
condition: ${{ eq(parameters.packageFeed, 'Azure') }}
- powershell: |
$file = "$(SampleRootPath)\nuget.config";
$content = @"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyGet" value="https://botbuilder.myget.org/F/botbuilder-v4-dotnet-daily/api/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
"@;
New-Item -Path $file -ItemType "file" -Value $content;
'-------------'; get-content "$file"; '===================';
displayName: Create nuget.config for MyGet feed
condition: ${{ eq(parameters.packageFeed, 'MyGet') }}
- powershell: |
$file = "$(SampleRootPath)\nuget.config";
$content = @"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
"@;
New-Item -Path $file -ItemType "file" -Value $content;
'-------------'; get-content "$file"; '===================';
displayName: Create nuget.config for NuGet feed
condition: ${{ eq(parameters.packageFeed, 'NuGet') }}
- powershell: |
$packageName = "Microsoft.Bot.Builder.Integration.AspNet.Core";
#$url = "https://feeds.dev.azure.com/ConversationalAI/BotFramework/_apis/packaging/Feeds/SDK/Packages/26dde74d-6079-401c-a9e0-c6d839e02c18/versions?api-version=5.1-preview.1"
Write-Host "Get latest $packageName version number from Azure ConversationalAI BotFramework SDK feed";
$RegistryUrlSource = "https://pkgs.dev.azure.com/ConversationalAI/BotFramework/_packaging/SDK/nuget/v3/index.json"
$Packagelist = nuget list Microsoft.Bot.Builder.Integration.AspNet.Core -Source "$RegistryUrlSource" -PreRelease -AllVersions;
" "
"Available versions:";
$PackageList -like "* 5.*" | Select -First 20;
$PackageList -like "* 4.*" | Select -First 20;
[string]$latestVersion = ($PackageList -like "* 4.*" | Select -First 1).Split(" ")[-1];
" "
"Latest v4 version:";
$packageName;
$latestVersion;
"##vso[task.setvariable variable=TargetVersion;]$latestVersion";
displayName: 'From Azure feed get latest Bot.Builder version number - https://dev.azure.com/ConversationalAI/BotFramework/_packaging?_a=feed&feed=SDK'
condition: ${{ and(eq(parameters.testLatestPackage, true), eq(parameters.packageFeed, 'Azure')) }}
- powershell: |
$myGetPersonalAccessToken = "$(MyGetPersonalAccessToken)";
$myGetFeedName = "botbuilder-v4-dotnet-daily";
$packageName = "Microsoft.Bot.Builder.Integration.AspNet.Core";
$url = "https://botbuilder.myget.org/F/$myGetFeedName/auth/$myGetPersonalAccessToken/api/v2/feed-state";
Write-Host "Get latest $packageName version number from MyGet $myGetFeedName";
$result = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json";
$package = $result.packages | Where-Object {$_.id -eq $packageName};
" "
"Available versions:";
$package.versions -like "4.*" | Select -Last 20;
$package.versions -like "5.*" | Select -Last 20;
[string]$latestVersion = ($package.versions -like "4.*")[-1];
" "
"Latest v4 version:";
$package.id;
$latestVersion;
"##vso[task.setvariable variable=TargetVersion;]$latestVersion";
displayName: 'From MyGet feed get latest Bot.Builder version number - https://botbuilder.myget.org/gallery/botbuilder-v4-dotnet-daily'
condition: ${{ and(eq(parameters.testLatestPackage, true), eq(parameters.packageFeed, 'MyGet')) }}
- powershell: |
$packageName = "Microsoft.Bot.Builder.Integration.AspNet.Core";
Write-Host "Get latest $packageName version number from NuGet.org feed";
$registryUrlSource = "https://nuget.org/api/v2/";
$packageList = Find-package -AllVersions -source $registryUrlSource -Name $packageName -AllowPrereleaseVersions;
" "
"Available versions:";
$PackageList.Version -like "5.*" | Select -First 20;
$PackageList.Version -like "4.*" | Select -First 20;
# Get the latest version 4.n value. Ignore version 5.
$latestVersion = ($PackageList.Version -like "4.*")[0];
" "
"Latest v4 version:";
$packageName;
$latestVersion;
"##vso[task.setvariable variable=TargetVersion;]$latestVersion";
displayName: 'From NuGet feed get latest Bot.Builder version number - https://www.nuget.org/packages?q=Bot.Builder'
condition: ${{ and(eq(parameters.testLatestPackage, true), eq(parameters.packageFeed, 'NuGet')) }}
- powershell: |
$targetVersion = "${{ parameters.versionToTest }}";
$targetVersion;
"##vso[task.setvariable variable=TargetVersion;]$targetVersion";
displayName: 'From user input get specific Bot.Builder version number'
condition: ${{ ne(parameters.testLatestPackage, true) }}
- powershell: 'gci env:* | sort-object name | Format-Table -AutoSize -Wrap'
displayName: 'Display env vars'
- task: tagBuildOrRelease@0
displayName: Tag Build with Bot.Builder version
inputs:
tags: |
Using Bot.Builder version $(TargetVersion)
From ${{ parameters.packageFeed }} feed
Test latest = ${{ parameters.testLatestPackage }}
- powershell: |
$path = "$(SampleRootPath)\\$(SampleBotName).csproj";
$packages = @('Microsoft.Bot.Builder.Integration.AspNet.Core','Microsoft.Bot.Builder.AI.Luis','Microsoft.Bot.Builder.Dialogs');
$newVersion = "$(TargetVersion)";
$content = Get-ChildItem -Path "$path" | Get-Content -Raw
foreach ($package in $packages) {
$find = "$package`" Version=`"\S*`"";
$replace = "$package`" Version=`"$newVersion`"";
$content = $content -Replace "$find", "$replace";
}
Set-Content -Path $path -Value $content;
'-------------'; get-content $path; '===================';
displayName: Set Bot.Builder version reference in $(SampleBotName).csproj
- task: NuGetToolInstaller@1
displayName: "Use NuGet latest"
- task: NuGetCommand@2
displayName: NuGet restore $(SampleBotName).csproj
inputs:
restoreSolution: $(SampleRootPath)\$(SampleBotName).csproj
feedsToUse: config
nugetConfigPath: $(SampleRootPath)\nuget.config
- task: DotNetCoreCLI@2
displayName: dotnet publish $(SampleBotName).csproj
inputs:
command: publish
publishWebProjects: false
projects: $(SampleRootPath)\$(SampleBotName).csproj
arguments: --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)
- task: AzureCLI@2
displayName: 'Preexisting RG: create Azure resources. Runs in even builds.'
inputs:
azureSubscription: 'FUSE Temporary'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
Write-Host "`n***** Creating Azure resources using the preexisting-rg template *****";
Write-Host "This task runs for even-numbered builds. Build ID = $(Build.BuildId)";
Write-Host "************************************************************************";
Set-PSDebug -Trace 1;
az group create --location westus --name $(BotGroup);
# set up app service plan, app service (web app)
az deployment group create --resource-group "$(BotGroup)" --template-file "$(SampleRootPath)\DeploymentTemplates\DeployUseExistResourceGroup\template-BotApp-with-rg.json" --parameters appId="$(AppId)" appSecret="$(AppSecret)" appServiceName="$(AzureBotName)" newAppServicePlanName="$(AzureBotName)" newAppServicePlanLocation="westus" --name "$(AzureBotName)";
# set up bot channels registration
az deployment group create --resource-group "$(BotGroup)" --template-file "$(SampleRootPath)\DeploymentTemplates\DeployUseExistResourceGroup\template-AzureBot-with-rg.json" --parameters appId="$(AppId)" azureBotId="$(AzureBotName)";
Set-PSDebug -Trace 0;
condition: and(succeeded(), or( endsWith(variables['Build.BuildId'], 0), endsWith(variables['Build.BuildId'], 2), endsWith(variables['Build.BuildId'], 4), endsWith(variables['Build.BuildId'], 6), endsWith(variables['Build.BuildId'], 8)))
- task: AzureCLI@2
displayName: 'New RG: create Azure resources. Runs in odd builds.'
inputs:
azureSubscription: 'FUSE Temporary'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
Write-Host "`n***** Creating Azure resources using the new-rg template *****";
Write-Host "This task runs for odd-numbered builds. Build ID = $(Build.BuildId)";
Write-Host "****************************************************************";
Set-PSDebug -Trace 1;
# set up resource group, app service plan, app service (web app)
az deployment sub create --name "$(BotGroup)" --template-file "$(SampleRootPath)\DeploymentTemplates\DeployWithNewResourceGroup\template-BotApp-new-rg.json" --location "westus" --parameters appId=$(AppId) appSecret="$(AppSecret)" appServiceName="$(AzureBotName)" appServicePlanName="$(AzureBotName)" groupName="$(BotGroup)" groupLocation="westus" appServicePlanLocation="westus";
# set up bot channels registration
az deployment sub create --name "$(BotGroup)" --template-file "$(SampleRootPath)\DeploymentTemplates\DeployWithNewResourceGroup\template-AzureBot-new-rg.json" --location "westus" --parameters appId=$(AppId) azureBotId="$(AzureBotName)" groupName="$(BotGroup)" groupLocation="westus";
Set-PSDebug -Trace 0;
condition: and(succeeded(), or( endsWith(variables['Build.BuildId'], 1), endsWith(variables['Build.BuildId'], 3), endsWith(variables['Build.BuildId'], 5), endsWith(variables['Build.BuildId'], 7), endsWith(variables['Build.BuildId'], 9)))
- task: AzureCLI@2
displayName: 'Deploy bot, create DirectLine channel '
inputs:
azureSubscription: 'FUSE Temporary'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
# prepare .deployment file
az bot prepare-deploy --lang Csharp --code-dir "$(SampleRootPath)" --proj-file-path "$(SampleBotName).csproj";
az webapp deployment source config-zip --resource-group "$(BotGroup)" --name "$(AzureBotName)" --src "$(Build.ArtifactStagingDirectory)/$(SampleFolderName).zip"
az bot directline create -n "$(AzureBotName)" -g "$(BotGroup)" > "$(System.DefaultWorkingDirectory)\DirectLineCreate.json"
- powershell: |
# Key = Direct Line channel "Secret keys" in Azure portal
$json = Get-Content '$(System.DefaultWorkingDirectory)\DirectLineCreate.json' | Out-String | ConvertFrom-Json;
$key = $json.properties.properties.sites.key;
echo "##vso[task.setvariable variable=DIRECTLINE;]$key";
echo "##vso[task.setvariable variable=BOTID;]$(AzureBotName)";
Write-Host "setx DIRECTLINE $key";
Write-Host "setx BOTID $(AzureBotName)";
displayName: Set DIRECTLINE key, BOTID for running tests
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: $(SampleFolderName)-zip'
continueOnError: True
enabled: False
inputs:
ArtifactName: $(SampleFolderName)-zip
- task: NuGetCommand@2
displayName: NuGet restore Samples.$(SampleBotName).FunctionalTests.csproj
inputs:
solution: samples/csharp_dotnetcore/tests/Samples.$(SampleBotName).FunctionalTests/Samples.$(SampleBotName).FunctionalTests.csproj
selectOrConfig: config
nugetConfigPath: $(SampleRootPath)\nuget.config
- task: DotNetCoreCLI@2
displayName: dotnet build Samples.$(SampleBotName).FunctionalTests.csproj
inputs:
projects: $(System.DefaultWorkingDirectory)/samples/csharp_dotnetcore/tests/Samples.$(SampleBotName).FunctionalTests/Samples.$(SampleBotName).FunctionalTests.csproj
- powershell: |
Start-Sleep -Seconds 15
displayName: Sleep for 15 seconds
enabled: true
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
projects: $(System.DefaultWorkingDirectory)/samples/csharp_dotnetcore/tests/Samples.$(SampleBotName).FunctionalTests/**Tests.csproj
arguments: --verbosity Normal
- script: |
dir .. /s
displayName: 'Dir workspace'
continueOnError: true
condition: always()
- task: AzureCLI@2
displayName: Delete bot, app service, app service plan, group
inputs:
azureSubscription: 'FUSE Temporary'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
Set-PSDebug -Trace 1;
Write-Host "1) Delete Bot:";
az bot delete --name $(AzureBotName) --resource-group $(BotGroup);
Write-Host "2) Delete App Service:";
az webapp delete --name $(AzureBotName) --resource-group $(BotGroup);
Write-Host "3) Delete App Service plan:";
az appservice plan delete --name $(AzureBotName) --resource-group $(BotGroup) --yes;
Write-Host "4) Delete Resource Group:";
az group delete --name $(BotGroup) --yes;
Set-PSDebug -Trace 0;
condition: and(succeededOrFailed(), ne(variables['DeleteResourceGroup'], 'false'))
continueOnError: True
...