Created
July 15, 2021 12:50
-
-
Save peerpalo/40dab9553bb6ac6ccd37144d2ae4dae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger: | |
branches: | |
include: | |
- '*' | |
tags: | |
include: | |
- '*' | |
pr: | |
branches: | |
include: | |
- '*' | |
pool: | |
vmImage: 'ubuntu-latest' | |
variables: | |
solution: '**/*.csproj' | |
buildPlatform: 'AnyCPU' | |
buildConfiguration: 'Release' | |
steps: | |
- task: NuGetToolInstaller@1 | |
displayName: 'NuGet installer' | |
- task: UseDotNet@2 | |
displayName: 'Use .NET Core SDK' | |
inputs: | |
packageType: sdk | |
version: 5.x | |
- task: DotNetCoreCLI@2 | |
displayName: "dotnet restore" | |
inputs: | |
command: 'restore' | |
projects: '$(solution)' | |
- task: DotNetCoreCLI@2 | |
displayName: "dotnet build" | |
inputs: | |
command: 'build' | |
projects: '$(solution)' | |
arguments: '/p:Configuration=$(buildConfiguration) /p:Platform="$(buildPlatform)"' | |
- task: PowerShell@2 | |
displayName: 'Tag and SemVer checks' | |
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/') | |
inputs: | |
pwsh: true | |
targetType: 'inline' | |
script: | | |
$tag = "$(build.sourceBranch)".Replace("refs/tags/","") | |
$regexString = "^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$" | |
$regex = new-object System.Text.RegularExpressions.Regex ($regexString,[System.Text.RegularExpressions.RegexOptions]::MultiLine) | |
Write-Host "Pushed tag is $tag" | |
if ($tag -match $regex) | |
{ | |
Write-Host "##vso[task.setvariable variable=PACKAGE_VERSION;isOutput=false]$tag" | |
Write-Host "PACKAGE_VERSION set to $tag" | |
} | |
else | |
{ | |
Write-Error "$tag does not conform to SemVer" | |
exit 1 | |
} | |
- task: DotNetCoreCLI@2 | |
displayName: "dotnet pack" | |
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/') | |
inputs: | |
command: pack | |
packagesToPack: '$(solution)' | |
configuration: '$(buildConfiguration)' | |
includeSymbols: true | |
nobuild: true | |
versioningScheme: 'byEnvVar' | |
versionEnvVar: 'PACKAGE_VERSION' | |
- task: DotNetCoreCLI@2 | |
displayName: "dotnet push" | |
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/') | |
inputs: | |
command: 'push' | |
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' | |
publishPackageMetadata: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment