|
| 1 | +trigger: |
| 2 | + branches: |
| 3 | + include: |
| 4 | + - 'v2/*' |
| 5 | + - 'v3/*' |
| 6 | + - 'v4/*' |
| 7 | + tags: |
| 8 | + include: |
| 9 | + - release-2.* |
| 10 | + - release-3.* |
| 11 | + - release-4.* |
| 12 | + |
| 13 | +pr: |
| 14 | + branches: |
| 15 | + include: |
| 16 | + - 'v2/*' |
| 17 | + - 'v3/*' |
| 18 | + - 'v4/*' |
| 19 | + |
| 20 | +parameters: |
| 21 | + - name: cache_nuget |
| 22 | + displayName: Cache NuGet packages |
| 23 | + type: boolean |
| 24 | + default: false # As long as we're overwriting versions on MyGet, we can't cache NuGet packages by default |
| 25 | + - name: release_myget |
| 26 | + displayName: Release to pre-release/nightly MyGet feed |
| 27 | + type: boolean |
| 28 | + default: false |
| 29 | + - name: release_myget_nightly |
| 30 | + displayName: Release to nightly MyGet feed (instead of pre-release) |
| 31 | + type: boolean |
| 32 | + default: false |
| 33 | + - name: release_nuget |
| 34 | + displayName: Release to public NuGet feed |
| 35 | + type: boolean |
| 36 | + default: false |
| 37 | + |
| 38 | +variables: |
| 39 | + solution: Umbraco.Deploy.Contrib.sln |
| 40 | + buildConfiguration: Release |
| 41 | + DOTNET_NOLOGO: true |
| 42 | + DOTNET_GENERATE_ASPNET_CERTIFICATE: false |
| 43 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 44 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 45 | + |
| 46 | +stages: |
| 47 | + - stage: Build |
| 48 | + variables: |
| 49 | + NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages |
| 50 | + jobs: |
| 51 | + - job: Build |
| 52 | + pool: |
| 53 | + vmImage: 'windows-latest' # Required for .NET Framework projects |
| 54 | + steps: |
| 55 | + # Checkout source (avoid shallow clone to calculate version height) |
| 56 | + - checkout: self |
| 57 | + fetchDepth: 0 |
| 58 | + |
| 59 | + # Setup build environment |
| 60 | + - task: UseDotNet@2 |
| 61 | + displayName: Use .NET SDK from global.json |
| 62 | + inputs: |
| 63 | + useGlobalJson: true |
| 64 | + |
| 65 | + # Cache and restore NuGet packages |
| 66 | + - task: Cache@2 |
| 67 | + condition: ${{ parameters.cache_nuget }} |
| 68 | + displayName: Cache NuGet packages |
| 69 | + inputs: |
| 70 | + key: 'nuget | "$(Agent.OS)" | **/packages.lock.json, !**/bin/**, !**/obj/**' |
| 71 | + restoreKeys: | |
| 72 | + nuget | "$(Agent.OS)" |
| 73 | + nuget |
| 74 | + path: $(NUGET_PACKAGES) |
| 75 | + |
| 76 | + - script: dotnet restore $(solution) --locked-mode |
| 77 | + displayName: Restore NuGet packages |
| 78 | + |
| 79 | + # Build |
| 80 | + - script: dotnet build $(solution) --configuration $(buildConfiguration) --no-restore -p:ContinuousIntegrationBuild=true |
| 81 | + displayName: Run dotnet build |
| 82 | + |
| 83 | + # Pack |
| 84 | + - script: dotnet pack $(solution) --configuration $(buildConfiguration) --no-build --output $(Build.ArtifactStagingDirectory)/nupkg |
| 85 | + displayName: Run dotnet pack |
| 86 | + |
| 87 | + # Publish |
| 88 | + - task: PublishPipelineArtifact@1 |
| 89 | + displayName: Publish NuGet packages |
| 90 | + inputs: |
| 91 | + targetPath: $(Build.ArtifactStagingDirectory)/nupkg |
| 92 | + artifactName: nupkg |
| 93 | + |
| 94 | + - task: PublishPipelineArtifact@1 |
| 95 | + displayName: Publish build output |
| 96 | + inputs: |
| 97 | + targetPath: $(Build.SourcesDirectory) |
| 98 | + artifactName: build_output |
| 99 | + |
| 100 | + - stage: Test |
| 101 | + dependsOn: Build |
| 102 | + jobs: |
| 103 | + - job: UnitTests |
| 104 | + displayName: Unit Tests |
| 105 | + pool: |
| 106 | + vmImage: 'windows-latest' |
| 107 | + steps: |
| 108 | + # Setup test environment |
| 109 | + - task: DownloadPipelineArtifact@2 |
| 110 | + displayName: Download build artifacts |
| 111 | + inputs: |
| 112 | + artifact: build_output |
| 113 | + path: $(Build.SourcesDirectory) |
| 114 | + |
| 115 | + - task: UseDotNet@2 |
| 116 | + displayName: Use .NET SDK from global.json |
| 117 | + inputs: |
| 118 | + useGlobalJson: true |
| 119 | + |
| 120 | + # Test |
| 121 | + - script: dotnet test $(solution) --configuration $(buildConfiguration) --no-build --logger trx --results-directory $(Build.ArtifactStagingDirectory)/tests |
| 122 | + displayName: Run dotnet test |
| 123 | + |
| 124 | + # Publish |
| 125 | + - task: PublishTestResults@2 |
| 126 | + displayName: Publish test results |
| 127 | + condition: succeededOrFailed() |
| 128 | + inputs: |
| 129 | + testResultsFormat: VSTest |
| 130 | + testResultsFiles: '*.trx' |
| 131 | + searchFolder: $(Build.ArtifactStagingDirectory)/tests |
| 132 | + testRunTitle: Unit Tests |
| 133 | + configuration: $(buildConfiguration) |
| 134 | + |
| 135 | + - stage: ReleaseMyGet |
| 136 | + displayName: MyGet release |
| 137 | + dependsOn: Test |
| 138 | + condition: and(succeeded(), or(eq(dependencies.Build.outputs['Build.build.NBGV_PublicRelease'], 'True'), ${{ parameters.release_myget }})) |
| 139 | + jobs: |
| 140 | + - job: |
| 141 | + displayName: Release to pre-release/nightly MyGet feed |
| 142 | + steps: |
| 143 | + - checkout: none |
| 144 | + - task: DownloadPipelineArtifact@2 |
| 145 | + displayName: Download nupkg |
| 146 | + inputs: |
| 147 | + artifact: nupkg |
| 148 | + path: $(Build.ArtifactStagingDirectory)/nupkg |
| 149 | + - task: NuGetCommand@2 |
| 150 | + displayName: NuGet push |
| 151 | + inputs: |
| 152 | + command: 'push' |
| 153 | + packagesToPush: $(Build.ArtifactStagingDirectory)/nupkg/*.nupkg |
| 154 | + nuGetFeedType: 'external' |
| 155 | + ${{ if eq(parameters.release_myget_nightly, true) }}: |
| 156 | + publishFeedCredentials: 'MyGet - Nightly' |
| 157 | + ${{ else }}: |
| 158 | + publishFeedCredentials: 'MyGet - Pre-releases' |
| 159 | + |
| 160 | + - stage: ReleaseNuGet |
| 161 | + displayName: NuGet release |
| 162 | + dependsOn: ReleaseMyGet |
| 163 | + condition: and(succeeded(), or(eq(dependencies.Build.outputs['Build.build.NBGV_PublicRelease'], 'True'), ${{ parameters.release_nuget }})) |
| 164 | + jobs: |
| 165 | + - job: |
| 166 | + displayName: Release to public NuGet feed |
| 167 | + steps: |
| 168 | + - checkout: none |
| 169 | + - task: DownloadPipelineArtifact@2 |
| 170 | + displayName: Download nupkg |
| 171 | + inputs: |
| 172 | + artifact: nupkg |
| 173 | + path: $(Build.ArtifactStagingDirectory)/nupkg |
| 174 | + - task: NuGetCommand@2 |
| 175 | + displayName: NuGet push |
| 176 | + inputs: |
| 177 | + command: 'push' |
| 178 | + packagesToPush: $(Build.ArtifactStagingDirectory)/nupkg/*.nupkg |
| 179 | + nuGetFeedType: 'external' |
| 180 | + publishFeedCredentials: 'NuGet' |
0 commit comments