248 строки
8.0 KiB
YAML
248 строки
8.0 KiB
YAML
trigger:
|
|
branches:
|
|
include: ["main", "develop*", "release-*", "refs/tags/*" ]
|
|
paths:
|
|
exclude: [ "doc", "*.md", ".gitignore", "README.md", "LICENSE.md" ]
|
|
|
|
# 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
|
|
|
|
pool:
|
|
vmImage: 'windows-2019'
|
|
|
|
variables:
|
|
DOTNET_NOLOGO: true
|
|
buildPlatform: 'Any CPU'
|
|
buildConfiguration: 'Release'
|
|
|
|
steps:
|
|
|
|
# need this here in order to persist GitHub credentials
|
|
- checkout: self
|
|
submodules: true
|
|
|
|
- script: |
|
|
git config --global user.email "nanoframework@outlook.com"
|
|
git config --global user.name "nfbot"
|
|
git config --global core.autocrlf true
|
|
displayName: Setup git identity
|
|
|
|
- task: NuGetToolInstaller@1
|
|
condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ) )
|
|
displayName: 'Install specific version of NuGet'
|
|
inputs:
|
|
versionSpec: '>=5.9.x'
|
|
|
|
- task: DotNetCoreCLI@2
|
|
displayName: Install NBGV tool
|
|
condition: succeeded()
|
|
inputs:
|
|
command: custom
|
|
custom: tool
|
|
arguments: install -g nbgv
|
|
|
|
- script: nbgv cloud -a -c
|
|
condition: succeeded()
|
|
displayName: Set build number
|
|
|
|
- task: PowerShell@2
|
|
condition: succeeded()
|
|
displayName: Get NuGet build number
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
$MyNuGetVersion = $env:NBGV_NuGetPackageVersion -replace ".g$env:NBGV_GitCommitIdShort", ""
|
|
|
|
# replace preview with alpha if this is a PR build
|
|
if($env:System_PullRequest_PullRequestId -ne $null)
|
|
{
|
|
# mix PR and VersionHeight
|
|
$alphaNumber = [int]$env:System_PullRequest_PullRequestNumber + $env:NBGV_VersionHeight;
|
|
|
|
$alphaPrString = "alpha." + $alphaNumber.ToString()
|
|
$MyNuGetVersion = $MyNuGetVersion -replace "preview", $alphaPrString
|
|
}
|
|
if ($env:System_PullRequest_SourceBranch -like 'release*')
|
|
{
|
|
$MyNuGetVersion = $MyNuGetVersion + "-rc." + $env:NBGV_VersionHeight
|
|
}
|
|
|
|
Write-Host "NuGet build is: $MyNuGetVersion"
|
|
Write-Host "Assembly version is: $env:NBGV_AssemblyVersion"
|
|
|
|
Write-Host "$("##vso[task.setvariable variable=MY_NUGET_VERSION]")$MyNuGetVersion"
|
|
|
|
- task: InstallnFBuildComponents@1
|
|
condition: succeeded()
|
|
displayName: Install nanoFramework MSBuild components
|
|
|
|
# build solutions that need to be build
|
|
- powershell: |
|
|
# setup msbuild
|
|
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
|
$msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
|
|
if ($msbuild) {
|
|
$msbuild = join-path $msbuild 'MSBuild\Current\Bin\MSBuild.exe'
|
|
}
|
|
|
|
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$(GitHubToken)"))))"
|
|
|
|
if($env:DEVICE_TO_BUILD -eq "")
|
|
{
|
|
if($env:System_PullRequest_PullRequestId -ne $null)
|
|
{
|
|
Write-host "Building from PR"
|
|
|
|
# get files changed in PR, if this is a PR
|
|
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/nanoFramework.IoT.Device/pulls/$env:System_PullRequest_PullRequestNumber/files" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
|
|
|
|
# filter removed files
|
|
$files = $commit.where{$_.status -ne 'removed'}
|
|
}
|
|
else
|
|
{
|
|
Write-host "Building from a commit"
|
|
|
|
# get files changed in the commit, if this is NOT a PR
|
|
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/nanoFramework.IoT.Device/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
|
|
$files1 = $files | % {$_.filename} | Where-Object {$_ -match 'devices*'}
|
|
|
|
Write-host "Files changed:"
|
|
$files1 | % { Write-host $_ }
|
|
Write-host ""
|
|
|
|
# pattern to select device folder name
|
|
$pattern = '(devices\/)(?<folder>\w+)'
|
|
|
|
# filter out the collection
|
|
$results = [Regex]::Matches($files1, $pattern)
|
|
|
|
# get unique folder names
|
|
$deviceFolders = $results | Sort-Object | Select-Object | Foreach-Object {$_.Groups["folder"].Value} | Get-Unique
|
|
}
|
|
else
|
|
{
|
|
# build for a specific device
|
|
|
|
$deviceFolders = New-Object System.Collections.ArrayList
|
|
$deviceFolders.Add("$env:DEVICE_TO_BUILD")
|
|
}
|
|
|
|
foreach ($folder in $deviceFolders)
|
|
{
|
|
"Processing '$folder'..." | Write-Host -ForegroundColor Yellow
|
|
|
|
# try to find the solution
|
|
$solutionFile = Get-ChildItem -Path "devices\$folder\" -Include "$folder.sln" -Recurse
|
|
|
|
if($null -eq $solutionFile)
|
|
{
|
|
"Couldn't find any solution file!" | Write-Host -ForegroundColor Red
|
|
throw "Couldn't the solution for '$folder'..."
|
|
}
|
|
else
|
|
{
|
|
"Solution file is: '$solutionFile'" | Write-Host -ForegroundColor Yellow
|
|
}
|
|
|
|
# try to find the nuspec
|
|
$nuspecFile = Get-ChildItem -Path "devices\$folder\" -Include "$folder.nuspec" -Recurse
|
|
|
|
if($null -eq $nuspecFile)
|
|
{
|
|
"Couldn't find the nuspec file!" | Write-Host -ForegroundColor Red
|
|
throw "Couldn't the nuspec for '$folder'..."
|
|
}
|
|
else
|
|
{
|
|
"nuspec file is: '$nuspecFile'" | Write-Host -ForegroundColor Yellow
|
|
}
|
|
|
|
# need to restore NuGets first
|
|
nuget restore $solutionFile
|
|
|
|
# build solution
|
|
& "$msbuild" "$solutionFile" /verbosity:normal /p:Configuration=Release
|
|
|
|
# package NuGet
|
|
nuget pack $nuspecFile -Version $(MY_NUGET_VERSION) -properties commit="$(Build.SourceVersion)" -OutputDirectory $env:Agent_TempDirectory
|
|
}
|
|
displayName: Build and pack solutions
|
|
|
|
- task: CopyFiles@1
|
|
condition: succeeded()
|
|
displayName: Collecting deployable artifacts
|
|
inputs:
|
|
sourceFolder: $(Agent.TempDirectory)
|
|
Contents: |
|
|
*.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 . SignClient
|
|
|
|
- pwsh: |
|
|
.\SignClient "Sign" `
|
|
--baseDirectory "$(Build.ArtifactStagingDirectory)" `
|
|
--input "**/*.nupkg" `
|
|
--config "$(Build.Repository.LocalPath)\config\SignClient.json" `
|
|
--filelist "$(Build.Repository.LocalPath)\config\filelist.txt" `
|
|
--user "$(SignClientUser)" `
|
|
--secret '$(SignClientSecret)' `
|
|
--name "IoT.Device" `
|
|
--description "IoT.Device" `
|
|
--descriptionUrl "https://github.com/$env:Build_Repository_Name"
|
|
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: PublishBuildArtifacts@1
|
|
condition: succeeded()
|
|
displayName: Publish deployables artifacts
|
|
inputs:
|
|
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
|
|
ArtifactName: deployables
|
|
ArtifactType: Container
|
|
|
|
# push NuGet class lib package to NuGet (always happens except on PR builds)
|
|
- task: NuGetCommand@2
|
|
condition: and( succeeded(), eq(variables['System.PullRequest.PullRequestId'], ''))
|
|
continueOnError: true
|
|
displayName: Push NuGet packages to NuGet
|
|
inputs:
|
|
command: push
|
|
nuGetFeedType: external
|
|
allowPackageConflicts: true
|
|
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
|
|
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
|
|
|
|
# step from template @ nf-tools repo
|
|
# report error
|
|
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
|
|
parameters:
|
|
status: 'failure'
|
|
webhookUrl: '$(DiscordWebhook)'
|
|
message: ''
|