代码拉取完成,页面将自动刷新
# 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:
- .github_changelog_generator
- .gitignore
- LICENSE.md
- README.md
- README.zh-cn.md
- NuGet.Config
- update-esptool.ps1
- update-jlink.ps1
- assets/*
- config/*
- .github/*
- Samples/*
# 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: Check_Build_Options
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
# get commit message
- powershell: |
# default to false
$update = $false
if($env:System_PullRequest_PullRequestId -ne $null)
{
# PR build, nothing interesting in commit message
Write-Host "Build from PR"
}
else
{
if($env:StartReleaseCandidate -like "true")
{
# this is a release prep so NO build
echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]true"
Write-Host "Release preparation, skipping build."
}
else
{
# build NOT from PR
Write-Host "Build NOT from PR, commit ID: $env:Build_SourceVersion"
# get PR associated with commit
$prUrl = "https://api.github.com/repos/$env:Build_Repository_Name/commits/$env:Build_SourceVersion/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
}
}
}
}
# set variable to foward to jobs
echo "##vso[task.setvariable variable=RUN_UPDATE_DEPENDENTS;isOutput=true]$update"
name: BuildOptions
displayName: Evaluate build options
- task: PowerShell@2
condition: eq( variables['StartReleaseCandidate'], true)
displayName: NBGV prepare release
inputs:
targetType: 'inline'
script: |
# compute authorization header in format "AUTHORIZATION: basic 'encoded token'"
# 'encoded token' is the Base64 of the string "nfbot:personal-token"
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$(GitHubToken)"))))"
cd "$env:Agent_TempDirectory" > $null
Write-Host "Cloning from: $env:BUILD_REPOSITORY_URI"
git clone $env:BUILD_REPOSITORY_URI repo
cd repo > $null
git config --global gc.auto 0
git config --global user.name nfbot
git config --global user.email nanoframework@outlook.com
git config --global core.autocrlf true
Write-Host "Checkout main branch..."
git checkout --quiet main > $null
# prepare release and capture output
Write-Host "Prepare release with NBGV..."
$release = nbgv prepare-release
Write-Host "Prepare commit..."
# get commit message for the merge
$commitMessage = git log -1 --pretty=%B
# amend commit message to skip build
git commit --amend -m "$commitMessage" -m "***NO_CI***" > $null
Write-Host "Pushing changes to GitHub..."
# push all changes to github
git -c http.extraheader="AUTHORIZATION: $auth" push --quiet --all origin
# get release branch name
$branch = $release.Split(' ')[0]
Write-Host "Prepare PR..."
# start PR for release
$prRequestBody = @{title="Release $branch";body="";head="$branch";base="main"} | ConvertTo-Json
$githubApiEndpoint = "https://api.github.com/repos/$env:BUILD_REPOSITORY_NAME/pulls"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$headers = @{}
$headers.Add("Authorization","$auth")
$headers.Add("Accept","application/vnd.github.symmetra-preview+json")
try
{
$result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header $headers -ContentType "application/json" -Body $prRequestBody
'Started PR for new release...' | Write-Host -NoNewline
'OK' | Write-Host -ForegroundColor Green
}
catch
{
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
"Error starting PR: $responseBody" | Write-Host -ForegroundColor Red
}
workingDirectory: $(Agent.TempDirectory)
ignoreLASTEXITCODE: true
###########################################################
# build tool
- job: Build_tool
condition: >-
and(
succeeded(),
ne(dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true)
)
dependsOn:
- Check_Build_Options
pool:
vmImage: 'windows-latest'
variables:
DOTNET_NOLOGO: true
buildPlatform: 'x64'
buildConfiguration: 'Release'
solution: 'nanoFirmwareFlasher.sln'
run_update_dependents: $[dependencies.Check_Build_Options.outputs['BuildOptions.RUN_UPDATE_DEPENDENTS']]
steps:
# need this here in order to persist GitHub credentials
- checkout: self
persistCredentials: true
- script: |
git config --global user.email "nanoframework@outlook.com"
git config --global user.name "nfbot"
displayName: Setup git identity
# only required when updating dependents
- script: nbgv cloud -a -c
condition: >-
eq(variables['UPDATE_DEPENDENTS'], 'true')
displayName: Set Cloud Version
- task: Cache@2
displayName: Cache NuGet packages
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json, !bin/**'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: $(UserProfile)/.nuget/packages
- task: DotNetCoreCLI@2
displayName: Restore NuGet packages
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
inputs:
command: restore
restoreArguments: '--locked-mode'
verbosityRestore: minimal
projects: nanoFirmwareFlasher.sln
feedsToUse: config
nugetConfigPath: NuGet.Config
- script: dotnet build -c $(BuildConfiguration) /p:PublicRelease=true --no-restore /t:build,pack
displayName: Build NuGet package
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
##################################################
- task: DotNetCoreCLI@2
displayName: 'Run Solution Tests'
inputs:
command: test
projects: |
./nanoFirmwareFlasher.Tests/nanoFirmwareFlasher.Tests.csproj
arguments: '--configuration $(BuildConfiguration) --collect "XPlat Code coverage"'
# 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)/coverlet/Cobertura.xml'
condition: always()
##################################################
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false'),
ne(variables['System.PullRequest.PullRequestId'], '')
)
displayName: Restore NuGet packages for Samples
inputs:
restoreSolution: '$(Build.SourcesDirectory)/Samples/Samples.sln'
feedsToUse: config
nugetConfigPath: '$(Build.SourcesDirectory)/Samples/nuget.config'
- task: VSBuild@1
displayName: Build Samples
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false'),
ne(variables['System.PullRequest.PullRequestId'], '')
)
inputs:
solution: '$(Build.SourcesDirectory)/Samples/Samples.sln'
platform: 'Any CPU'
configuration: '$(buildConfiguration)'
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
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)
{
$MyNuGetVersion = $MyNuGetVersion -replace "preview", "alpha"
}
Write-Host "NuGet build number is $MyNuGetVersion"
Write-Host "$("##vso[task.setvariable variable=MY_NUGET_VERSION]")$MyNuGetVersion"
# update cloud build number (only possible if this is not a PR from a fork)
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Update cloud build number
inputs:
targetType: 'inline'
script: Write-Host "$("##vso[build.updatebuildnumber]")$env:NBGV_NuGetPackageVersion"
- powershell: |
# 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 "***PUBLISH_RELEASE***")
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_DRAFT]")false"
Write-Host "Release draft: FALSE"
}
else
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_DRAFT]")true"
Write-Host "Release draft: TRUE"
}
displayName: set release draft var
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
- task: CopyFiles@1
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Collecting deployable artifacts
inputs:
sourceFolder: $(Agent.BuildDirectory)
Contents: |
**\*.nupkg
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: DotNetCoreCLI@2
displayName: Install SignTool tool
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
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 ".NET nanoFramework firmware flasher" `
--description ".NET nanoFramework firmware flasher" `
--descriptionUrl "https://github.com/$env:Build_Repository_Name"
displayName: Sign packages
continueOnError: true
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
# publish artifacts
- task: PublishBuildArtifacts@1
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Publish deployables artifacts
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: deployables
ArtifactType: Container
# push NuGet class lib package to NuGet (happens on all builds except PRs)
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Push nanoff NuGet package to NuGet
continueOnError: true
inputs:
command: push
feedsToUse: select
nuGetFeedType: external
allowPackageConflicts: true
packagesToPush: '$(Build.ArtifactStagingDirectory)\nanoff.$(NBGV_NuGetPackageVersion).nupkg'
publishFeedCredentials: 'NuGet-nanoFirmwareFlasher'
# push NuGet class lib package to NuGet (happens on all builds except PRs)
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Push library NuGet package to NuGet
continueOnError: true
inputs:
command: push
feedsToUse: select
nuGetFeedType: external
allowPackageConflicts: true
packagesToPush: '$(Build.ArtifactStagingDirectory)\nanoFramework.Tools.FirmwareFlasher.$(NBGV_NuGetPackageVersion).nupkg'
publishFeedCredentials: 'NuGet-nanoFirmwareFlasher'
# create or update GitHub release
- task: GithubRelease@1
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Create/Update GitHub stable release
inputs:
gitHubConnection: 'github.com_nano-$(System.TeamProject)'
tagSource: userSpecifiedTag
tag: v$(MY_NUGET_VERSION)
title: 'nano firmware flasher v$(MY_NUGET_VERSION)'
assets: '$(Build.ArtifactStagingDirectory)/*.nupkg'
isPreRelease: false
action: create
isDraft: false
addChangeLog: true
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" }
]
# update dependents
- task: PowerShell@2
condition: >-
or(
eq(variables['UPDATE_DEPENDENTS'], 'true'),
eq(variables['run_update_dependents'], 'true')
)
displayName: Update dependent tools
inputs:
targetType: filePath
filePath: azure-pipelines/update-dependents.ps1
env:
GH_TOKEN: $(GitHubToken)
##################################
# report build failure to Discord
- job: Report_Build_Failure
dependsOn:
- Check_Build_Options
- Build_tool
condition: >-
or(
failed('Check_Build_Options'),
failed('Build_tool')
)
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
# step from template @ nf-tools repo
- template: azure-pipelines-templates/discord-webhook.yml@templates
parameters:
status: 'failure'
webhookUrl: '$(DiscordWebhook)'
message: ''
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。