|
| 1 | +# Starter pipeline |
| 2 | +# Start with a minimal pipeline that you can customize to build and deploy your code. |
| 3 | +# Add steps that build, run tests, deploy, and more: |
| 4 | +# https://aka.ms/yaml |
| 5 | + |
| 6 | +trigger: |
| 7 | + branches: |
| 8 | + include: |
| 9 | + - main |
| 10 | + paths: |
| 11 | + exclude: |
| 12 | + - README.md |
| 13 | +pr: |
| 14 | + branches: |
| 15 | + include: |
| 16 | + - main |
| 17 | + paths: |
| 18 | + exclude: |
| 19 | + - README.md |
| 20 | + |
| 21 | +pool: |
| 22 | + vmImage: 'windows-latest' |
| 23 | + |
| 24 | +variables: |
| 25 | + isRelease: False |
| 26 | + isPrerelease: False |
| 27 | + projectVersion: |
| 28 | + |
| 29 | + ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}: |
| 30 | + isMain: true |
| 31 | + buildConfiguration: 'Release' |
| 32 | + ${{ if ne(variables['Build.SourceBranch'], 'refs/heads/main') }}: |
| 33 | + isMain: false |
| 34 | + buildConfiguration: 'Debug' |
| 35 | + |
| 36 | + ${{ if startsWith(variables['Build.SourceBranch'], 'refs/pull/') }}: |
| 37 | + releaseBuild: $[eq(variables['System.PullRequest.TargetBranch'], 'main')] |
| 38 | + isPullRequest: True |
| 39 | + isAlphaRelease: $[eq(variables['System.PullRequest.TargetBranch'], 'main')] |
| 40 | + ${{ if not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')) }}: |
| 41 | + releaseBuild: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')] |
| 42 | + isPullRequest: False |
| 43 | + isAlphaRelease: False |
| 44 | + |
| 45 | +steps: |
| 46 | + |
| 47 | +- task: Bash@3 |
| 48 | + displayName: 'Get Version from version.props' |
| 49 | + inputs: |
| 50 | + targetType: 'inline' |
| 51 | + script: | |
| 52 | + PROJECT_VERSION_PREFIX="$(grep '<VersionPrefix>' < version.props | sed 's/.*<VersionPrefix>\(.*\)<\/VersionPrefix>/\1/')" |
| 53 | + PROJECT_VERSION_SUFFIX="$(grep '<VersionSuffix>' < version.props | sed 's/.*<VersionSuffix>\(.*\)<\/VersionSuffix>/\1/')" |
| 54 | + echo "##vso[task.setvariable variable=projectVersionPrefix]$PROJECT_VERSION_PREFIX" |
| 55 | + echo "##vso[task.setvariable variable=projectVersionSuffix]$PROJECT_VERSION_SUFFIX" |
| 56 | + if [ $ISALPHARELEASE == "False" ]; then |
| 57 | + if [ -n "$PROJECT_VERSION_SUFFIX" ]; then |
| 58 | + echo "##vso[task.setvariable variable=isPrerelease]True" |
| 59 | + echo "##vso[task.setvariable variable=projectVersion]$PROJECT_VERSION_PREFIX-$PROJECT_VERSION_SUFFIX" |
| 60 | + else |
| 61 | + echo "##vso[task.setvariable variable=isRelease]True" |
| 62 | + echo "##vso[task.setvariable variable=projectVersion]$PROJECT_VERSION_PREFIX" |
| 63 | + fi |
| 64 | + else |
| 65 | + echo "##vso[task.setvariable variable=projectVersionSuffix]alpha-$(Build.BuildNumber)" |
| 66 | + echo "##vso[task.setvariable variable=projectVersion]$PROJECT_VERSION_PREFIX-alpha-$(Build.BuildNumber)" |
| 67 | + fi |
| 68 | + |
| 69 | +- task: Bash@3 |
| 70 | + condition: true |
| 71 | + displayName: 'Log pipeline configuration' |
| 72 | + inputs: |
| 73 | + targetType: 'inline' |
| 74 | + script: | |
| 75 | + echo "Source Branch: $(Build.SourceBranch)" |
| 76 | + echo "Is Pull Request: $(isPullRequest)" |
| 77 | + [ "$(isPullRequest)" == "True" ] && echo "Pull Request Source: $(System.PullRequest.SourceBranch)" && echo "Pull Request Target: $(System.PullRequest.TargetBranch)" |
| 78 | + echo "Release Build: $(releaseBuild)" |
| 79 | + echo "Stable release: $(isRelease)" |
| 80 | + echo "Prerelease: $(isPrerelease)" |
| 81 | + echo "Alpha: $(isAlphaRelease)" |
| 82 | + echo "Build Configuration: $(buildConfiguration)" |
| 83 | + echo "Build Version: $(projectVersion)" |
| 84 | + |
| 85 | + |
| 86 | +- task: DotNetCoreCLI@2 |
| 87 | + inputs: |
| 88 | + command: 'restore' |
| 89 | + projects: '**/*.sln' |
| 90 | + displayName: 'Restore packages' |
| 91 | + |
| 92 | +- task: DotNetCoreCLI@2 |
| 93 | + inputs: |
| 94 | + command: 'build' |
| 95 | + projects: '**/*.sln' |
| 96 | + arguments: '--configuration $(buildConfiguration) --no-restore /property:VersionSuffix="$(projectVersionSuffix)"' |
| 97 | + displayName: 'Build' |
| 98 | + |
| 99 | +- task: DotNetCoreCLI@2 |
| 100 | + inputs: |
| 101 | + command: test |
| 102 | + projects: '**/*.sln' |
| 103 | + arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/' |
| 104 | + publishTestResults: true |
| 105 | + nobuild: true |
| 106 | + displayName: 'Run Tests' |
| 107 | + |
| 108 | +- task: PublishCodeCoverageResults@1 |
| 109 | + displayName: 'Publish code coverage report' |
| 110 | + inputs: |
| 111 | + codeCoverageTool: 'Cobertura' |
| 112 | + summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage*.cobertura.xml' |
| 113 | + |
| 114 | +- task: DotNetCoreCLI@2 |
| 115 | + condition: and(succeeded(), eq(variables.releaseBuild, true)) |
| 116 | + inputs: |
| 117 | + command: 'custom' |
| 118 | + custom: 'pack' |
| 119 | + projects: '**/*.sln' |
| 120 | + arguments: '--configuration $(buildConfiguration) --no-restore --no-build --output $(Build.ArtifactStagingDirectory) --version-suffix="$(projectVersionSuffix)"' |
| 121 | + displayName: 'Create package' |
| 122 | + |
| 123 | +- task: GitHubRelease@1 |
| 124 | + displayName: Create Github release |
| 125 | + condition: and(succeeded(), eq(variables.releaseBuild, true), or(eq(variables.isRelease, true),eq(variables.isPrerelease, true))) |
| 126 | + inputs: |
| 127 | + gitHubConnection: 'github.com_nsarris' |
| 128 | + repositoryName: 'nsarris/ParallelTasks' |
| 129 | + action: 'create' |
| 130 | + target: '$(Build.SourceVersion)' |
| 131 | + tagSource: 'userSpecifiedTag' |
| 132 | + tag: 'v$(projectVersion)' |
| 133 | + title: 'v$(projectVersion)' |
| 134 | + releaseNotesSource: 'inline' |
| 135 | + isPreRelease: $(isPrerelease) |
| 136 | + addChangeLog: false |
| 137 | + |
| 138 | +- task: NuGetAuthenticate@0 |
| 139 | + condition: and(succeeded(), eq(variables.releaseBuild, true)) |
| 140 | + displayName: 'NuGet Authenticate' |
| 141 | + |
| 142 | +- task: NuGetCommand@2 |
| 143 | + displayName: Nuget Push (Alpha feed) |
| 144 | + condition: and(succeeded(), eq(variables.releaseBuild, true), eq(variables.isAlphaRelease, true)) |
| 145 | + inputs: |
| 146 | + command: 'push' |
| 147 | + packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' |
| 148 | + nuGetFeedType: 'internal' |
| 149 | + publishVstsFeed: '8bd3f470-a025-4709-944d-71b861c79f14/72a2a01e-ed8d-4409-8a57-aea04fca4b84' |
| 150 | + allowPackageConflicts: true |
| 151 | + |
| 152 | +- task: NuGetCommand@2 |
| 153 | + displayName: Nuget Push (Release feed) |
| 154 | + condition: and(succeeded(), eq(variables.releaseBuild, true), or(eq(variables.isRelease, true), eq(variables.isPrerelease, true))) |
| 155 | + inputs: |
| 156 | + command: 'push' |
| 157 | + packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' |
| 158 | + nuGetFeedType: 'external' |
| 159 | + publishFeedCredentials: 'nuget.org_nsarris' |
0 commit comments