432 строки
12 KiB
YAML
432 строки
12 KiB
YAML
trigger:
|
|
branches:
|
|
include: [main, develop, "release-*" ]
|
|
paths:
|
|
exclude:
|
|
- azure-pipelines.yml
|
|
- README.md
|
|
- README.zh-cn.md
|
|
- CHANGELOG.md
|
|
- CODE_OF_CONDUCT.md
|
|
- LICENSE.md
|
|
- .gitignore
|
|
|
|
tags:
|
|
include:
|
|
- refs/tags/v*
|
|
|
|
# PR always trigger build
|
|
pr:
|
|
autoCancel: true
|
|
|
|
jobs:
|
|
|
|
##############################
|
|
- job: Check_Build_Options
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
steps:
|
|
|
|
- checkout: self
|
|
|
|
# check what changed
|
|
- powershell: |
|
|
git config --global user.email "nfbot"
|
|
git config --global user.name "nanoframework@outlook.com"
|
|
|
|
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$(GitHubToken)")))"
|
|
|
|
if($env:System_PullRequest_PullRequestId -ne $null)
|
|
{
|
|
# get files changed in PR, if this is a PR
|
|
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/$env:Build_Repository_Name/pulls/$env:System_PullRequest_PullRequestNumber/files" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
|
|
|
|
# filter removed files
|
|
$files = $commit.where{$_.status -ne 'removed'}
|
|
}
|
|
else
|
|
{
|
|
# get files changed in the commit, if this is NOT a PR
|
|
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/$env:Build_Repository_Name/commits/$(Build.SourceVersion)" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
|
|
|
|
# filter removed files
|
|
$files = $commit.files.where{$_.status -ne 'removed'}
|
|
}
|
|
|
|
# get file names only
|
|
$files = $files | % {$_.filename}
|
|
|
|
Write-host "Files changed:"
|
|
$files | % { Write-host $_ }
|
|
Write-host ""
|
|
|
|
# set default values
|
|
echo "##vso[task.setvariable variable=BUILD_NANOVC;isOutput=true]false"
|
|
echo "##vso[task.setvariable variable=BUILD_NANODU;isOutput=true]false"
|
|
echo "##vso[task.setvariable variable=BUILD_PROFILER;isOutput=true]false"
|
|
|
|
if( ($files.where{$_.Contains('tools/VersionCop')}).Count -gt 0)
|
|
{
|
|
# files at nano VersionCop folder
|
|
echo "##vso[task.setvariable variable=BUILD_NANOVC;isOutput=true]true"
|
|
|
|
Write-host "Building VersionCop"
|
|
}
|
|
|
|
if( ($files.where{$_.Contains('tools/DependencyUpdater')}).Count -gt 0)
|
|
{
|
|
# files at nano DependencyUpdater folder
|
|
echo "##vso[task.setvariable variable=BUILD_NANODU;isOutput=true]true"
|
|
|
|
Write-host "Building DependencyUpdater"
|
|
}
|
|
|
|
if( ($files.where{$_.Contains('tools/Profiler')}).Count -gt 0)
|
|
{
|
|
# files at nano Profiler folder
|
|
echo "##vso[task.setvariable variable=BUILD_PROFILER;isOutput=true]true"
|
|
|
|
Write-host "Building Profiler"
|
|
}
|
|
|
|
name: TargetsToBuild
|
|
displayName: Get targets to build
|
|
|
|
##############
|
|
- job: Build_VersionCop
|
|
condition: >-
|
|
or(
|
|
eq(dependencies.Check_Build_Options.outputs['TargetsToBuild.BUILD_NANOVC'], true),
|
|
eq(variables['BUILD_VERSIONCOP'], 'true')
|
|
)
|
|
dependsOn:
|
|
Check_Build_Options
|
|
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
variables:
|
|
- group: sign-client-credentials
|
|
- name: DOTNET_NOLOGO
|
|
value: true
|
|
|
|
steps:
|
|
|
|
- checkout: self
|
|
persistCredentials: true
|
|
|
|
- template: azure-pipelines-templates/install-nuget.yml
|
|
|
|
- task: NuGetCommand@2
|
|
displayName: Restore NuGet packages
|
|
condition: succeeded()
|
|
retryCountOnTaskFailure: 5
|
|
inputs:
|
|
restoreSolution: $(System.DefaultWorkingDirectory)/tools/VersionCop/nanoFramework.VersionCop.sln
|
|
feedsToUse: select
|
|
includeNuGetOrg: true
|
|
|
|
- script: dotnet build nanoFramework.VersionCop.sln -c Release -p:Platform="Any CPU" -p:PublicRelease=true --no-restore /t:build,pack
|
|
displayName: Build NuGet package
|
|
condition: succeeded()
|
|
workingDirectory: '$(System.DefaultWorkingDirectory)/tools/VersionCop'
|
|
|
|
- task: CopyFiles@1
|
|
condition: succeeded()
|
|
displayName: Collecting deployable artifacts
|
|
inputs:
|
|
sourceFolder: $(Agent.BuildDirectory)
|
|
Contents: |
|
|
**\nanovc*.nupkg
|
|
TargetFolder: '$(Build.ArtifactStagingDirectory)'
|
|
flattenFolders: true
|
|
|
|
- task: PowerShell@2
|
|
condition: >-
|
|
and(
|
|
succeeded(),
|
|
eq(variables['StartReleaseCandidate'], false),
|
|
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
|
|
)
|
|
displayName: Check deployable artifacts
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
|
|
$artifacts = (Get-ChildItem -Path "$env:Build_ArtifactStagingDirectory" -Recurse)
|
|
|
|
if ($artifacts.Count -eq 0)
|
|
{
|
|
Write-Error "No deployable artifacts found!"
|
|
Exit 1
|
|
}
|
|
|
|
- task: DotNetCoreCLI@2
|
|
displayName: Install Sign Client CLI
|
|
condition: succeeded()
|
|
inputs:
|
|
command: custom
|
|
custom: tool
|
|
arguments: install --tool-path . sign --version 0.9.1-beta.23530.1
|
|
|
|
- pwsh: |
|
|
.\sign code azure-key-vault `
|
|
"**/*.nupkg" `
|
|
--base-directory "$(Build.ArtifactStagingDirectory)" `
|
|
--description ".NET nanoFramework VersionCop" `
|
|
--description-url "https://github.com/$env:Build_Repository_Name" `
|
|
--azure-key-vault-tenant-id "$(SignTenantId)" `
|
|
--azure-key-vault-client-id "$(SignClientId)" `
|
|
--azure-key-vault-client-secret "$(SignClientSecret)" `
|
|
--azure-key-vault-certificate "$(SignKeyVaultCertificate)" `
|
|
--azure-key-vault-url "$(SignKeyVaultUrl)" `
|
|
--timestamp-url http://timestamp.digicert.com
|
|
displayName: Sign packages
|
|
continueOnError: true
|
|
condition: succeeded()
|
|
|
|
# publish artifacts (only possible if this is not a PR originated on a fork)
|
|
- task: PublishPipelineArtifact@1
|
|
condition: succeeded()
|
|
displayName: Publish deployables artifacts
|
|
inputs:
|
|
targetPath: '$(Build.ArtifactStagingDirectory)'
|
|
artifactName: deployables
|
|
artifactType: pipeline
|
|
|
|
# push NuGet packages to NuGet
|
|
- task: NuGetCommand@2
|
|
displayName: Push NuGet packages to NuGet
|
|
condition: >-
|
|
and(
|
|
succeeded(),
|
|
eq(variables['System.PullRequest.PullRequestId'], '')
|
|
)
|
|
continueOnError: true
|
|
inputs:
|
|
command: push
|
|
nuGetFeedType: external
|
|
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
|
|
allowPackageConflicts: true
|
|
includeSymbols: true
|
|
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
|
|
|
|
##############
|
|
- job: Build_DependencyUpdater
|
|
condition: >-
|
|
or(
|
|
eq(dependencies.Check_Build_Options.outputs['TargetsToBuild.BUILD_NANODU'], true),
|
|
eq(variables['BUILD_DEPENDENCYUPDATER'], 'true')
|
|
)
|
|
dependsOn:
|
|
Check_Build_Options
|
|
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
variables:
|
|
- group: sign-client-credentials
|
|
- name: DOTNET_NOLOGO
|
|
value: true
|
|
|
|
steps:
|
|
|
|
- checkout: self
|
|
persistCredentials: true
|
|
|
|
- template: azure-pipelines-templates/install-nuget.yml
|
|
|
|
- task: NuGetCommand@2
|
|
displayName: Restore NuGet packages
|
|
condition: succeeded()
|
|
retryCountOnTaskFailure: 5
|
|
inputs:
|
|
restoreSolution: $(System.DefaultWorkingDirectory)/tools/DependencyUpdater/DependencyUpdater.sln
|
|
feedsToUse: select
|
|
includeNuGetOrg: true
|
|
|
|
- script: dotnet build DependencyUpdater.sln -c Release -p:Platform="Any CPU" -p:PublicRelease=true --no-restore /t:build,pack
|
|
displayName: Build NuGet package
|
|
condition: succeeded()
|
|
workingDirectory: '$(System.DefaultWorkingDirectory)/tools/DependencyUpdater'
|
|
|
|
- task: DotNetCoreCLI@2
|
|
condition: succeeded()
|
|
displayName: 'Running Unit Tests'
|
|
inputs:
|
|
command: 'test'
|
|
projects: |
|
|
**/*Tests.csproj
|
|
!**/obj/**
|
|
!**/bin/**/ref/**
|
|
arguments: '--configuration Release --collect "XPlat Code coverage"'
|
|
testRunTitle: 'Unit Tests'
|
|
|
|
# First install the tool on the machine, then run it
|
|
- script: |
|
|
dotnet tool install -g dotnet-reportgenerator-globaltool
|
|
reportgenerator -reports:$(Agent.WorkFolder)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
|
|
displayName: 'Create code coverage report'
|
|
condition: always()
|
|
|
|
- task: PublishCodeCoverageResults@1
|
|
displayName: 'Publish code coverage results'
|
|
inputs:
|
|
codeCoverageTool: Cobertura
|
|
summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
|
|
condition: always()
|
|
|
|
- task: CopyFiles@1
|
|
condition: succeeded()
|
|
displayName: Collecting deployable artifacts
|
|
inputs:
|
|
sourceFolder: $(Agent.BuildDirectory)
|
|
Contents: |
|
|
**\nanodu*.nupkg
|
|
TargetFolder: '$(Build.ArtifactStagingDirectory)'
|
|
flattenFolders: true
|
|
|
|
- task: PowerShell@2
|
|
condition: >-
|
|
and(
|
|
succeeded(),
|
|
eq(variables['StartReleaseCandidate'], false),
|
|
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
|
|
)
|
|
displayName: Check deployable artifacts
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
|
|
$artifacts = (Get-ChildItem -Path "$env:Build_ArtifactStagingDirectory" -Recurse)
|
|
|
|
if ($artifacts.Count -eq 0)
|
|
{
|
|
Write-Error "No deployable artifacts found!"
|
|
Exit 1
|
|
}
|
|
|
|
- task: DotNetCoreCLI@2
|
|
displayName: Install Sign Client CLI
|
|
condition: succeeded()
|
|
inputs:
|
|
command: custom
|
|
custom: tool
|
|
arguments: install --tool-path . sign --version 0.9.1-beta.23530.1
|
|
|
|
- pwsh: |
|
|
.\sign code azure-key-vault `
|
|
"**/*.nupkg" `
|
|
--base-directory "$(Build.ArtifactStagingDirectory)" `
|
|
--description ".NET nanoFramework DependencyUpdater" `
|
|
--description-url "https://github.com/$env:Build_Repository_Name" `
|
|
--azure-key-vault-tenant-id "$(SignTenantId)" `
|
|
--azure-key-vault-client-id "$(SignClientId)" `
|
|
--azure-key-vault-client-secret "$(SignClientSecret)" `
|
|
--azure-key-vault-certificate "$(SignKeyVaultCertificate)" `
|
|
--azure-key-vault-url "$(SignKeyVaultUrl)" `
|
|
--timestamp-url http://timestamp.digicert.com
|
|
displayName: Sign packages
|
|
continueOnError: true
|
|
condition: succeeded()
|
|
|
|
# publish artifacts (only possible if this is not a PR originated on a fork)
|
|
- task: PublishPipelineArtifact@1
|
|
condition: succeeded()
|
|
displayName: Publish deployables artifacts
|
|
inputs:
|
|
targetPath: '$(Build.ArtifactStagingDirectory)'
|
|
artifactName: deployables
|
|
artifactType: pipeline
|
|
|
|
# push NuGet packages to NuGet
|
|
- task: NuGetCommand@2
|
|
displayName: Push NuGet packages to NuGet
|
|
condition: >-
|
|
and(
|
|
succeeded(),
|
|
eq(variables['System.PullRequest.PullRequestId'], '')
|
|
)
|
|
continueOnError: true
|
|
inputs:
|
|
command: push
|
|
nuGetFeedType: external
|
|
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
|
|
includeSymbols: true
|
|
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
|
|
|
|
##############
|
|
- job: Build_NanoProfiler
|
|
condition: >-
|
|
or(
|
|
eq(dependencies.Check_Build_Options.outputs['TargetsToBuild.BUILD_PROFILER'], true),
|
|
eq(variables['BUILD_NANOPROFILER'], 'true')
|
|
)
|
|
dependsOn:
|
|
Check_Build_Options
|
|
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
variables:
|
|
- group: sign-client-credentials
|
|
- name: DOTNET_NOLOGO
|
|
value: true
|
|
|
|
steps:
|
|
|
|
- checkout: self
|
|
persistCredentials: true
|
|
|
|
- template: azure-pipelines-templates/install-nuget.yml
|
|
|
|
- task: NuGetCommand@2
|
|
displayName: Restore NuGet packages
|
|
condition: succeeded()
|
|
retryCountOnTaskFailure: 5
|
|
inputs:
|
|
restoreSolution: $(System.DefaultWorkingDirectory)/tools/Profiler/NanoProfiler/NanoProfiler.sln
|
|
feedsToUse: select
|
|
includeNuGetOrg: true
|
|
|
|
- task: VSBuild@1
|
|
condition: succeeded()
|
|
displayName: Build nanoProfiler
|
|
inputs:
|
|
solution: '$(System.DefaultWorkingDirectory)/tools/Profiler/NanoProfiler/NanoProfiler.sln'
|
|
platform: 'Any CPU'
|
|
msbuildArgs: '/p:PublicRelease=true'
|
|
configuration: 'Release'
|
|
maximumCpuCount: true
|
|
|
|
##################################
|
|
# report build failure to Discord
|
|
- job: Report_Build_Failure
|
|
dependsOn:
|
|
- Check_Build_Options
|
|
- Build_VersionCop
|
|
- Build_DependencyUpdater
|
|
- Build_NanoProfiler
|
|
condition: >-
|
|
or(
|
|
failed('Check_Build_Options'),
|
|
failed('Build_VersionCop'),
|
|
failed('Build_DependencyUpdater'),
|
|
failed('Build_NanoProfiler')
|
|
)
|
|
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
steps:
|
|
|
|
- checkout: self
|
|
|
|
# step from template @ nf-tools repo
|
|
- template: azure-pipelines-templates/discord-webhook.yml
|
|
parameters:
|
|
status: 'failure'
|
|
webhookUrl: '$(DiscordWebhook)'
|
|
message: ''
|