BotBuilder-Samples/build/yaml/sample-ts-samplebot-linux-t...

331 строка
14 KiB
YAML

# This is used in the pipelines Sample-Ts-CoreBot-Linux-Test-yaml and Sample-Ts-EchoBot-Linux-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 '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 'AzureDeploymentCredsVariableGroup' 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 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-dev.20210726.c56bbf1'
- name: packageFeed
displayName: Package feed to use
type: string
default: npm
values:
- npm
- MyGet
# 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: AzureDeploymentCredsVariableGroup
#- group: SamplesE2ETestsVariableGroup
#- group: MyGetPersonalAccessTokenVariableGroup
jobs:
- job: Job_1
displayName: Agent job 1
pool:
vmImage: windows-2019
steps:
- checkout: self
persistCredentials: True
- powershell: |
$packageName = "botbuilder";
Write-Host "Get $packageName preview version tagged 'next' from npmjs.com";
" "
"Available versions:";
npm view $packageName versions | Select -Last 30;
$dist = npm dist-tag ls $packageName;
$next = $dist.Where({$_.StartsWith("next:")});
[string]$latestVersion = $next.Split(':')[-1].Trim();
"Latest version:";
$packageName;
$latestVersion;
"##vso[task.setvariable variable=TargetVersion;]$latestVersion";
displayName: From npm feed get latest botbuilder package version - https://www.npmjs.com/package/botbuilder
condition: ${{ and(eq(parameters.testLatestPackage, true), eq(parameters.packageFeed, 'npm')) }}
- powershell: |
$myGetPersonalAccessToken = "$(MyGetPersonalAccessToken)";
$myGetFeedName = "botbuilder-v4-js-daily";
$packageName = "botbuilder-ai";
$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 | Select -Last 30;
[string]$latestVersion = $package.versions[-1];
" "
"Latest version:";
$package.id;
$latestVersion;
"##vso[task.setvariable variable=TargetVersion;]$latestVersion";
displayName: 'From MyGet feed get latest botbuilder version number - https://botbuilder.myget.org/gallery/botbuilder-v4-dotnet-daily'
condition: ${{ and(eq(parameters.testLatestPackage, true), eq(parameters.packageFeed, 'MyGet')) }}
- powershell: |
$targetVersion = "${{ parameters.versionToTest }}";
$targetVersion;
"##vso[task.setvariable variable=TargetVersion;]$targetVersion";
displayName: 'From user input get specific botbuilder 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 botbuilder version
inputs:
tags: |
Using botbuilder version $(TargetVersion)
From ${{ parameters.packageFeed }} feed
Test latest = ${{ parameters.testLatestPackage }}
- powershell: |
# SetDependencyVersionInPackageJsonFile0.ps1
$path = "$(SampleRootPath)/package.json";
$packages = @('botbuilder','botbuilder-ai','botbuilder-dialogs','botbuilder-testing');
$newVersion = "$(TargetVersion)";
$content = Get-ChildItem -Path "$path" | Get-Content -Raw
foreach ($package in $packages) {
$find = "$package`": `"\S*`"";
$replace = "$package`": `"$newVersion`"";
$content = $content -Replace "$find", "$replace";
}
Set-Content -Path $path -Value $content;
'-------------'; get-content $path; '===================';
displayName: Set botbuilder version reference in package.json
- powershell: |
Set-Location -Path "$(SampleRootPath)"
New-Item -Path . -Name ".npmrc" -ItemType "file" -Value "registry=https://registry.npmjs.com/"
displayName: Create .npmrc for npm feed - https://www.npmjs.com/search?q=botbuilder
condition: ${{ eq(parameters.packageFeed, 'npm') }}
- powershell: |
Set-Location -Path "$(SampleRootPath)"
New-Item -Path . -Name ".npmrc" -ItemType "file" -Value "registry=https://botbuilder.myget.org/F/botbuilder-v4-js-daily/npm/"
displayName: Create .npmrc for MyGet feed - https://botbuilder.myget.org/feed/Packages/botbuilder-v4-js-daily
condition: ${{ eq(parameters.packageFeed, 'MyGet') }}
- task: Npm@1
displayName: npm install $(SampleFolderName)
inputs:
workingDir: $(SampleRootPath)
verbose: false
- 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\linux\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\linux\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\linux\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\linux\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)))
- powershell: |
Set-PSDebug -Trace 1;
# Copy Azure deploy scripts for Linux
Move-Item -Path $(SampleRootPath)\deploymentScripts\linux\* -Destination $(SampleRootPath)\;
Set-PSDebug -Trace 0;
displayName: Move .deployment, deploy.sh scripts into position
- script: |
echo on
git config --global user.name "SampleTs$(SampleBotName)LinuxTestPipeline"
git config --global user.email BotBuilderTs@Pipeline.com
git init
git add .
git commit -m "Add bot source code"
git remote add azure https://$(AzureDeploymentUser):$(AzureDeploymentPassword)@$(AzureBotName).scm.azurewebsites.net:443/$(AzureBotName).git
git push azure master
workingDirectory: '$(System.DefaultWorkingDirectory)/samples/javascript_nodejs/$(SampleFolderName)'
displayName: 'Deploy the bot to Azure'
- task: AzureCLI@2
displayName: Create DirectLine channel
inputs:
azureSubscription: 'FUSE Temporary'
scriptType: batch
scriptLocation: inlineScript
inlineScript: call az bot directline create --name "$(AzureBotName)" --resource-group "$(BotGroup)" > "$(System.DefaultWorkingDirectory)\DirectLineCreate.json" --debug
- 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: NuGetToolInstaller@1
displayName: "Use NuGet latest"
- powershell: |
$file = "$(System.DefaultWorkingDirectory)/samples/csharp_dotnetcore/tests/Samples.$(SampleBotName).FunctionalTests/nuget.config";
$content = @"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</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 Samples.$(SampleBotName).FunctionalTests.csproj for NuGet.org feed
- task: NuGetCommand@2
displayName: NuGet restore dotnet Samples.$(SampleBotName).FunctionalTests.csproj
inputs:
solution: samples/csharp_dotnetcore/tests/Samples.$(SampleBotName).FunctionalTests/Samples.$(SampleBotName).FunctionalTests.csproj
nugetConfigPath: $(System.DefaultWorkingDirectory)/samples/csharp_dotnetcore/tests/Samples.$(SampleBotName).FunctionalTests/nuget.config
- task: DotNetCoreCLI@2
displayName: dotnet build dotnet Samples.$(SampleBotName).FunctionalTests.csproj
inputs:
projects: $(System.DefaultWorkingDirectory)/samples/csharp_dotnetcore/tests/Samples.$(SampleBotName).FunctionalTests/Samples.$(SampleBotName).FunctionalTests.csproj
- 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
...