395 строки
11 KiB
YAML
395 строки
11 KiB
YAML
# Copyright (c) .NET Foundation and Contributors
|
|
# See LICENSE file in the project root for full license information.
|
|
|
|
trigger:
|
|
branches:
|
|
include:
|
|
- main
|
|
- develop
|
|
- release-*
|
|
paths:
|
|
exclude:
|
|
- .gitignore
|
|
- LICENSE.md
|
|
- README.md
|
|
- NuGet.Config
|
|
- assets/*
|
|
- config/*
|
|
- .github/*
|
|
|
|
# PR always trigger build
|
|
pr:
|
|
autoCancel: true
|
|
|
|
# add nf-tools repo to resources (for Azure Pipelines templates)
|
|
resources:
|
|
repositories:
|
|
- repository: templates
|
|
type: github
|
|
name: nanoframework/nf-tools
|
|
endpoint: nanoframework
|
|
|
|
jobs:
|
|
|
|
##############################
|
|
- job: Get_Build_Flags
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
steps:
|
|
- checkout: self
|
|
fetchDepth: 1
|
|
|
|
|
|
# get commit message
|
|
- powershell: |
|
|
|
|
# default to false
|
|
$update = $false
|
|
|
|
if($env:Build_Reason -eq 'PullRequest')
|
|
{
|
|
# PR build, nothing interesting in commit message
|
|
}
|
|
else
|
|
{
|
|
# build is not from a PR
|
|
|
|
# get commit ID
|
|
$commitId = git rev-parse HEAD
|
|
|
|
# get PR associate with commit
|
|
$prUrl = "https://api.github.com/repos/nanoframework/metadata-processor/commits/$commitId/pulls"
|
|
$commit = Invoke-RestMethod -Uri $prUrl -ContentType "application/json" -Headers @{"Accept"="application/vnd.github.groot-preview+json"} -Method GET
|
|
|
|
if($commit -ne $null)
|
|
{
|
|
# there is a PR, check labels
|
|
$updateDependents = $commit.labels | where {$_.Name -eq 'CI: Update Dependents'}
|
|
if($updateDependents -ne $null)
|
|
{
|
|
$update = $true
|
|
}
|
|
}
|
|
else
|
|
{
|
|
# not a PR, get subject and commit message for commit
|
|
$commitMessage = git log --format='%B' -1
|
|
|
|
# need to flatten message by removing new lines
|
|
$commitMessage = $commitMessage -replace "`r`n", " "
|
|
|
|
if($commitMessage -like "***UPDATE_DEPENDENTS***")
|
|
{
|
|
$update = $true
|
|
}
|
|
}
|
|
}
|
|
|
|
# set variable to foward to jobs
|
|
echo "##vso[task.setvariable variable=RUN_UPDATE_DEPENDENTS;isOutput=true]$update"
|
|
name: GetPRLabels
|
|
displayName: Check build labels
|
|
|
|
##############################
|
|
# build MDP
|
|
- job: Build_MDP
|
|
condition: eq(variables['UPDATE_DEPENDENTS'], 'false')
|
|
|
|
dependsOn:
|
|
- Get_Build_Flags
|
|
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
variables:
|
|
- group: sign-client-credentials
|
|
- name: DOTNET_NOLOGO
|
|
value: true
|
|
- name: buildPlatform
|
|
value: 'Any CPU'
|
|
- name: buildConfiguration
|
|
value: 'Release'
|
|
- name: solution
|
|
value: 'nanoFramework.Tools.MetadataProcessor.sln'
|
|
- name: NF_MDP_MSBUILDTASK_PATH
|
|
value: '$(System.DefaultWorkingDirectory)/MetadataProcessor.MsBuildTask/bin/Release/net472'
|
|
|
|
steps:
|
|
|
|
# need this here in order to persist GitHub credentials, do a shallow fetch AND init submodules
|
|
- checkout: self
|
|
persistCredentials: true
|
|
submodules: true
|
|
|
|
- script: |
|
|
cd $(System.DefaultWorkingDirectory)/MetadataProcessor.Tests/mscorlib
|
|
git submodule update --init --recursive
|
|
displayName: Update mscorlib sub-module
|
|
|
|
- script: |
|
|
git config --global user.email "nanoframework@outlook.com"
|
|
git config --global user.name "nfbot"
|
|
displayName: Setup git identity
|
|
|
|
- template: azure-pipelines-templates/install-nuget.yml@templates
|
|
|
|
- task: InstallNanoMSBuildComponents@1
|
|
condition: ne( variables['StartReleaseCandidate'], true )
|
|
displayName: Install nanoFramework MSBuild components
|
|
env:
|
|
GITHUB_TOKEN: $(GitHubToken)
|
|
|
|
- task: NuGetCommand@2
|
|
displayName: NuGet restore
|
|
inputs:
|
|
restoreSolution: '$(solution)'
|
|
feedsToUse: config
|
|
nugetConfigPath: 'NuGet.config'
|
|
|
|
- task: VSBuild@1
|
|
inputs:
|
|
solution: '$(solution)'
|
|
platform: '$(buildPlatform)'
|
|
msbuildArchitecture: x64
|
|
msbuildArgs: '/p:PublicRelease=true'
|
|
configuration: '$(buildConfiguration)'
|
|
|
|
- task: PowerShell@2
|
|
displayName: Remove nano Test Adapter
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
Get-ChildItem -Path $env:System_DefaultWorkingDirectory -Include "nanoFramework.TestAdapter.dll" -Recurse |
|
|
Foreach-object {
|
|
Remove-Item -Path $_.fullname
|
|
}
|
|
|
|
- task: VisualStudioTestPlatformInstaller@1
|
|
condition: succeeded()
|
|
displayName: 'Visual Studio Test Platform Installer'
|
|
inputs:
|
|
versionSelector: latestStable
|
|
|
|
- task: VSTest@2
|
|
condition: succeeded()
|
|
displayName: 'Running tests'
|
|
inputs:
|
|
testSelector: 'testAssemblies'
|
|
pathtoCustomTestAdapters:
|
|
testAssemblyVer2: |
|
|
**\*Tests*.dll
|
|
!**\*TestAdapter*.dll
|
|
!**\*TestFramework*.dll
|
|
!**\obj\**
|
|
searchFolder: '$(System.DefaultWorkingDirectory)'
|
|
platform: '$(BuildPlatform)'
|
|
configuration: '$(BuildConfiguration)'
|
|
diagnosticsEnabled: true
|
|
vsTestVersion: toolsInstaller
|
|
codeCoverageEnabled: true
|
|
|
|
- task: CopyFiles@1
|
|
condition: failed()
|
|
displayName: Collecting test results
|
|
inputs:
|
|
Contents: |
|
|
**\TestResults\*.trx
|
|
TargetFolder: '$(Build.ArtifactStagingDirectory)'
|
|
flattenFolders: true
|
|
|
|
- task: CopyFiles@1
|
|
condition: succeeded()
|
|
displayName: Collecting deployable artifacts
|
|
inputs:
|
|
sourceFolder: $(Build.SourcesDirectory)
|
|
Contents: |
|
|
**\bin\Release\nanoFramework.Tools.MetaDataProcessor.exe
|
|
**\bin\Release\nanoFramework.Tools.MetadataProcessor.MsBuildTask.dll
|
|
TargetFolder: '$(Build.ArtifactStagingDirectory)'
|
|
flattenFolders: true
|
|
|
|
# set cloud build vars again as they've been overriten by the tests run
|
|
- script: nbgv cloud -a -c
|
|
condition: succeeded()
|
|
displayName: Set build number
|
|
|
|
- task: PowerShell@2
|
|
condition: succeeded()
|
|
displayName: Save cloud build number
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: Write-Host "$("##vso[build.updatebuildnumber]")$env:NBGV_NuGetPackageVersion"
|
|
|
|
- task: NuGetCommand@2
|
|
condition: succeeded()
|
|
displayName: Pack NuGet with MetadataProcessor Console
|
|
inputs:
|
|
command: 'custom'
|
|
arguments: 'pack MetadataProcessor.Console\package.nuspec -Version $(NBGV_NuGetPackageVersion) -properties commit="$(Build.SourceVersion)" -properties NoWarn=NU5100'
|
|
|
|
- task: CopyFiles@1
|
|
condition: succeeded()
|
|
displayName: Collecting NuGet package artifact
|
|
inputs:
|
|
sourceFolder: $(Build.SourcesDirectory)
|
|
Contents: |
|
|
**\nanoFramework.Tools*.nupkg
|
|
TargetFolder: '$(Build.ArtifactStagingDirectory)'
|
|
flattenFolders: true
|
|
|
|
- task: DotNetCoreCLI@2
|
|
displayName: Install SignTool tool
|
|
condition: and( succeeded(), eq(variables['System.PullRequest.PullRequestId'], '') )
|
|
inputs:
|
|
command: custom
|
|
custom: tool
|
|
arguments: install --tool-path . sign --version 0.9.1-beta.24170.3
|
|
|
|
- pwsh: |
|
|
.\sign code azure-key-vault `
|
|
"**/*.nupkg" `
|
|
--base-directory "$(Build.ArtifactStagingDirectory)" `
|
|
--file-list "$(Build.Repository.LocalPath)\config\filelist.txt" `
|
|
--description ".NET nanoFramework MDP" `
|
|
--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: >-
|
|
and(
|
|
succeeded(),
|
|
eq(variables['System.PullRequest.PullRequestId'], '')
|
|
)
|
|
|
|
# publish artifacts (only possible if this is not a PR originated on a fork)
|
|
- task: PublishPipelineArtifact@1
|
|
displayName: Publish deployables artifacts
|
|
inputs:
|
|
targetPath: '$(Build.ArtifactStagingDirectory)'
|
|
artifactName: deployables
|
|
|
|
# push NuGet packages to NuGet (always happens except on PR builds)
|
|
- task: NuGetCommand@2
|
|
displayName: Push NuGet packages to NuGet
|
|
condition: >-
|
|
and(
|
|
succeeded(),
|
|
eq(variables['System.PullRequest.PullRequestId'], '')
|
|
)
|
|
continueOnError: true
|
|
inputs:
|
|
command: push
|
|
nuGetFeedType: external
|
|
allowPackageConflicts: true
|
|
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
|
|
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
|
|
|
|
# create or update GitHub release
|
|
- task: GithubRelease@1
|
|
condition: >-
|
|
and(
|
|
succeeded(),
|
|
eq(variables['System.PullRequest.PullRequestId'], ''),
|
|
startsWith(variables['Build.SourceBranch'], 'refs/heads/main'),
|
|
eq(variables['UPDATE_DEPENDENTS'], 'false')
|
|
)
|
|
displayName: Create/Update GitHub release
|
|
inputs:
|
|
action: edit
|
|
gitHubConnection: 'github.com_nano-$(System.TeamProject)'
|
|
tagSource: userSpecifiedTag
|
|
tag: v$(NBGV_NuGetPackageVersion)
|
|
title: 'nanoFramework Metadata Processor v$(NBGV_NuGetPackageVersion)'
|
|
assets: '$(Build.ArtifactStagingDirectory)/*'
|
|
isPreRelease: false
|
|
isDraft: false
|
|
addChangeLog: true
|
|
changeLogType: issueBased
|
|
changeLogLabels: |
|
|
[
|
|
{ "label": "Type: bug", "displayName": "Bugs fixed", "state": "closed" },
|
|
{ "label": "Type: enhancement", "displayName": "Enhancements and new features", "state": "closed" },
|
|
{ "label": "Breaking-Change", "displayName": "Breaking Changes", "state": "closed" },
|
|
{ "label": "Type: dependencies", "displayName": "Dependencies updated", "state": "closed" },
|
|
{ "label": "Type: documentation", "displayName": "Documentation", "state": "closed" }
|
|
]
|
|
|
|
##############################
|
|
- job: Update_Dependents
|
|
condition: >-
|
|
and(
|
|
or(
|
|
succeeded('Build_MDP'),
|
|
not(in(dependencies.PreviousJob.result, 'Succeeded', 'Failed', 'Canceled'))
|
|
),
|
|
or(
|
|
eq(dependencies.Get_Build_Flags.outputs['GetPRLabels.RUN_UPDATE_DEPENDENTS'], 'true'),
|
|
eq(variables['UPDATE_DEPENDENTS'], 'true')
|
|
),
|
|
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
|
|
)
|
|
|
|
dependsOn:
|
|
- Get_Build_Flags
|
|
- Build_MDP
|
|
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
variables:
|
|
DOTNET_NOLOGO: true
|
|
|
|
steps:
|
|
# need this here in order to persist GitHub credentials
|
|
- checkout: self
|
|
fetchDepth: 1
|
|
|
|
# Conditional delay step
|
|
- powershell: |
|
|
if ($env:BUILD_MDP_RESULT -eq 'Succeeded') {
|
|
Write-Host "Build_MDP succeeded, waiting for 10 minutes for the NuGet package to be processed before starting the job..."
|
|
Start-Sleep -Seconds 600
|
|
}
|
|
displayName: 'Waiting for NuGet being published'
|
|
env:
|
|
BUILD_MDP_RESULT: $(Build.MDP.result)
|
|
|
|
- template: azure-pipelines-templates/install-nuget.yml@templates
|
|
|
|
# update dependencies
|
|
- task: PowerShell@2
|
|
displayName: Update dependent class libs
|
|
inputs:
|
|
targetType: filePath
|
|
filePath: azure-pipelines/update-dependencies.ps1
|
|
env:
|
|
GH_TOKEN: $(GitHubToken)
|
|
|
|
##################################
|
|
# report build failure to Discord
|
|
- job: Report_Build_Failure
|
|
dependsOn:
|
|
- Build_MDP
|
|
condition: failed('Build_MDP')
|
|
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
|
|
steps:
|
|
|
|
- checkout: self
|
|
fetchDepth: 1
|
|
|
|
# step from template @ nf-tools repo
|
|
- template: azure-pipelines-templates/discord-webhook.yml@templates
|
|
parameters:
|
|
status: 'failure'
|
|
webhookUrl: '$(DiscordWebhook)'
|
|
message: ''
|