Skip to content

Commit

Permalink
Update azure devops pipeline (#140)
Browse files Browse the repository at this point in the history
* Update pipeline

* Rename

* Fix pipeline:

* Use yaml instead of yml

* Fix indent in yaml file

* cleanup and improve yaml

* cleanup

* fix release dependencies

* Added icons|

* Fix

* minor update|

* update icons
  • Loading branch information
coenm authored Sep 2, 2024
1 parent 4530692 commit 719c1ce
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 160 deletions.
34 changes: 34 additions & 0 deletions .azuredevops/Pipelines/Templates/create-installer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
steps:

- task: DeleteFiles@1
displayName: Remove unneeded files
inputs:
contents: |
_output/**/*.xlm
_output/**/*.config
_output/**/*.pdb
_output/Win/Assemblies/runtimes/!(win*)/**/*.*
_output/Win/Assemblies/!(runtimes)/*.resources.dll
- pwsh: |
Get-ChildItem -Path "_output\Win\Assemblies" -Recurse | Where-Object { $_.PSIsContainer -and @(Get-ChildItem -LiteralPath $_.FullName -Recurse -Force).Count -eq 0 } | Remove-Item -Recurse
Get-ChildItem -Path "_output\Win\Assemblies\runtimes" -Recurse | Where-Object { $_.PSIsContainer -and @(Get-ChildItem -LiteralPath $_.FullName -Recurse -Force).Count -eq 0 } | Remove-Item -Recurse
displayName: Remove empty directories

- pwsh: |
nuget install NSIS -OutputDirectory ./packages
makensis.exe /DPRODUCT_VERSION=$Env:NBGV_SEMVER2 _setup/RepoM.nsi
displayName: ⚙️ Create installer

- task: DeleteFiles@1
displayName: Remove binaries
inputs:
contents: |
_output/win
- task: PublishBuildArtifacts@1
displayName: 📢 Publish artifact
inputs:
# PathtoPublish: "$(Build.ArtifactStagingDirectory)"
PathtoPublish: "_output"
ArtifactName: installer
16 changes: 16 additions & 0 deletions .azuredevops/Pipelines/Templates/dotnet-sdk-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
steps:

- powershell: .azuredevops/Variables/_pipelines.ps1
failOnStderr: true
displayName: ⚙️ Set pipeline variables based on source
name: SetPipelineVariables

- task: UseDotNet@2
displayName: ⚙️ Use specified dotnet sdk version
inputs:
version: $(DOTNETSDKVERSION)
includePreviewVersions: false
condition: and(succeeded(), ne(variables['DOTNETSDKVERSION'], ''))

- script: dotnet --info
displayName: Show dotnet SDK info
12 changes: 12 additions & 0 deletions .azuredevops/Pipelines/Templates/prepare-code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
steps:

- task: SonarCloudPrepare@2
displayName: Prepare analysis on SonarCloud
inputs:
SonarCloud: SonarCloudGithub
organization: coenm-github
projectKey: RepoM
projectName: RepoM
extraProperties: |
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/*.trx
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/*.opencover.xml
19 changes: 19 additions & 0 deletions .azuredevops/Pipelines/Templates/publish-code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:

- task: SonarCloudAnalyze@2
displayName: ⚙️ Run Code Analysis

- task: SonarCloudPublish@2
displayName: 📢 Publish Quality Gate Result

- pwsh: |
dotnet tool install --tool-path . dotnet-reportgenerator-globaltool
./reportgenerator "-reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml" "-targetdir:$(Agent.TempDirectory)" "-reporttypes:Cobertura"
displayName: Merge coverage reports
name: MergeCoverageReports

- task: PublishCodeCoverageResults@2
displayName: 📢 Publish code coverage to devops
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Agent.TempDirectory)/Cobertura.xml'
13 changes: 13 additions & 0 deletions .azuredevops/Pipelines/Templates/publish-release-dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
steps:

- task: CopyFiles@2
displayName: 🗃️ Copy release dependencies
inputs:
contents: 'dotnet-releaser.toml'
targetFolder: _output_release_dependencies

- task: PublishBuildArtifacts@1
displayName: 📢 Publish release dependencies
inputs:
PathtoPublish: "_output_release_dependencies"
ArtifactName: release-dependencies
87 changes: 15 additions & 72 deletions .azuredevops/Pipelines/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,25 @@ stages:

steps:

- script: git submodule update --init --recursive
displayName: Update git submodules
- checkout: self
fetchDepth: 0 # avoid shallow clone so nbgv can do its work.
clean: true

- task: UseDotNet@2
displayName: "Use dotnet sdk 8.0.401"
inputs:
version: 8.0.401
includePreviewVersions: false
- script: git submodule update --init --recursive
displayName: 🔄 Update git submodules

- script: dotnet --info
displayName: Show dotnet SDK info
- template: Templates/dotnet-sdk-install.yaml

- task: NuGetToolInstaller@1
displayName: Install Nuget 5x
displayName: ⬇️ Install Nuget 5x
inputs:
versionSpec: '5.*'
checkLatest: true

- pwsh: |
dotnet tool install --tool-path . nbgv
./nbgv cloud -a
displayName: Set build number
displayName: 4️⃣2️⃣ Set build number
name: Nbgv
- task: PowerShell@2
Expand Down Expand Up @@ -102,32 +99,23 @@ stages:
# name: mdsnippets

- task: DotNetCoreCLI@2
displayName: DotNet Restore
displayName: 🛠️ DotNet Restore
inputs:
command: restore
projects: '**/*.csproj'

- task: SonarCloudPrepare@2
displayName: Prepare analysis on SonarCloud
inputs:
SonarCloud: SonarCloudGithub
organization: coenm-github
projectKey: RepoM
projectName: RepoM
extraProperties: |
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/*.trx
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/*.opencover.xml
- template: Templates/prepare-code-analysis.yaml

- task: DotNetCoreCLI@2
displayName: DotNet Build
displayName: 🛠️ DotNet Build
inputs:
command: build
projects: '**/*.sln'
arguments: '--configuration $(BuildConfiguration)'

# https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops&tabs=dotnetfive
- task: DotNetCoreCLI@2
displayName: Dotnet Test
displayName: 🧪 Dotnet Test
inputs:
command: test
projects: 'tests/**/*.csproj'
Expand All @@ -138,23 +126,7 @@ stages:
/p:ExcludeByAttribute=CompilerGenerated
publishTestResults: true

- task: SonarCloudAnalyze@2
displayName: Run Code Analysis

- task: SonarCloudPublish@2
displayName: Publish Quality Gate Result

- pwsh: |
dotnet tool install --tool-path . dotnet-reportgenerator-globaltool
./reportgenerator "-reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml" "-targetdir:$(Agent.TempDirectory)" "-reporttypes:Cobertura"
displayName: Merge coverage reports
name: MergeCoverageReports
- task: PublishCodeCoverageResults@2
displayName: Publish code coverage to devops
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Agent.TempDirectory)/Cobertura.xml'
- template: Templates/publish-code-analysis.yaml

- task: DotNetCoreCLI@2
displayName: Dotnet Publish RepoM
Expand All @@ -166,36 +138,7 @@ stages:
modifyOutputPath: false
zipAfterPublish: false

- task: DeleteFiles@1
displayName: Remove unneeded files
inputs:
contents: |
_output/**/*.xlm
_output/**/*.config
_output/**/*.pdb
_output/Win/Assemblies/runtimes/!(win*)/**/*.*
_output/Win/Assemblies/!(runtimes)/*.resources.dll
- pwsh: |
Get-ChildItem -Path "_output\Win\Assemblies" -Recurse | Where-Object { $_.PSIsContainer -and @(Get-ChildItem -LiteralPath $_.FullName -Recurse -Force).Count -eq 0 } | Remove-Item -Recurse
Get-ChildItem -Path "_output\Win\Assemblies\runtimes" -Recurse | Where-Object { $_.PSIsContainer -and @(Get-ChildItem -LiteralPath $_.FullName -Recurse -Force).Count -eq 0 } | Remove-Item -Recurse
displayName: Remove empty directories
- pwsh: |
nuget install NSIS -OutputDirectory ./packages
makensis.exe /DPRODUCT_VERSION=$Env:NBGV_SEMVER2 _setup/RepoM.nsi
displayName: Create installer
- task: DeleteFiles@1
displayName: Remove binaries
inputs:
contents: |
_output/win
- template: Templates/create-installer.yaml

- task: PublishBuildArtifacts@1
displayName: Publish artifact
inputs:
# PathtoPublish: "$(Build.ArtifactStagingDirectory)"
PathtoPublish: "_output"
ArtifactName: installer
- template: Templates/publish-release-dependencies.yaml

131 changes: 75 additions & 56 deletions .azuredevops/Pipelines/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,87 @@ resources:
pipelines:
- pipeline: CI
source: RepoM.Build
trigger:
tags:
- auto-release
trigger: true

variables:
- group: Publishing secrets

stages:
- stage: GitHubRelease
displayName: GitHub Release
- stage: UpdateBuildNumber
displayName: Set build number
jobs:
- deployment: create
- job: SetBuildNumber
displayName: Set build number
pool:
vmImage: ubuntu-latest
environment: No-Approval
strategy:
runOnce:
deploy:
steps:
- download: none
- powershell: |
Write-Host "##vso[build.updatebuildnumber]$(resources.pipeline.CI.runName)"
displayName: Set pipeline name
- task: GitHubRelease@1
displayName: GitHub release (create)
inputs:
gitHubConnection: github_coenm_pan
repositoryName: $(Build.Repository.Name)
target: $(resources.pipeline.CI.sourceCommit)
tagSource: userSpecifiedTag
tag: v$(resources.pipeline.CI.runName)
title: v$(resources.pipeline.CI.runName)
isDraft: true
changeLogCompareToRelease: lastNonDraftRelease
changeLogType: issueBased
changeLogLabels: |
[
{ "label" : "bug", "displayName" : "Fixes", "state" : "closed" },
{ "label" : "enhancement", "displayName": "Enhancements", "state" : "closed" }
]
steps:
- checkout: none
- powershell: |
Write-Host "##vso[build.updatebuildnumber]$(resources.pipeline.CI.runName)"
displayName: ⚙️ Set up pipeline
- stage: ManualValidation
displayName: "Manual Validation"
jobs:
- job: WaitForValidation
pool: server
timeoutInMinutes: 1441
displayName: Wait for validation
steps:
- task: ManualValidation@0
displayName: 🧐 Manual validation
timeoutInMinutes: 1440
inputs:
notifyUsers:
instructions: 'Please approve or reject the deployment.'
onTimeout: 'reject'

- stage: nuget_org
displayName: nuget.org
dependsOn: GitHubRelease
- stage: GithubRelease
displayName: Github Release
jobs:
- deployment: push
- job: release
displayName: Github Release
pool:
vmImage: ubuntu-latest
environment: No-Approval
strategy:
runOnce:
deploy:
steps:
- download: CI
artifact: packages
displayName: Download nuget packages artifact
patterns: 'packages/*'
- task: NuGetToolInstaller@1
displayName: Use NuGet 5.x
inputs:
versionSpec: 5.x
- task: NuGetCommand@2
displayName: NuGet push nupkg
inputs:
command: push
packagesToPush: '$(Pipeline.Workspace)/CI/packages/*.nupkg;!$(Pipeline.Workspace)/**/*.symbols.nupkg'
nuGetFeedType: external
publishFeedCredentials: nuget.org
steps:
- checkout: none
- powershell: |
if ('$(resources.pipeline.CI.runName)'.Contains('-')) {
Write-Host "##vso[task.setvariable variable=IsPrerelease]true"
} else {
Write-Host "##vso[task.setvariable variable=IsPrerelease]false"
}
displayName: ⚙️ Set up pipeline
- download: CI
artifact: installer
displayName: 🔻 Download installer artifact
patterns: 'installer/*'
- download: CI
artifact: release-dependencies
displayName: 🔻 Download publisher artifact
patterns: 'release-dependencies/*'
- task: GitHubRelease@1
displayName: 📢 Create GitHub release
inputs:
gitHubConnection: github_coenm_pan
repositoryName: $(Build.Repository.Name)
target: $(resources.pipeline.CI.sourceCommit)
tagSource: userSpecifiedTag
tag: v$(resources.pipeline.CI.runName)
title: v$(resources.pipeline.CI.runName)
isDraft: false
isPreRelease: $(IsPrerelease)
assets: $(Pipeline.Workspace)/CI/installer/*Setup.exe
changeLogCompareToRelease: lastNonDraftRelease
changeLogType: issueBased
changeLogLabels: |
[
{ "label" : "breaking change", "displayName" : "Breaking changes", "state" : "closed" },
{ "label" : "bug", "displayName" : "Fixes", "state" : "closed" },
{ "label" : "enhancement", "displayName": "Enhancements", "state" : "closed" }
]
- powershell: |
dotnet tool install --global dotnet-releaser
dotnet-releaser changelog --update --github-token $(GITHUB_TOKEN) $(Pipeline.Workspace)/CI/release-dependencies/dotnet-releaser.toml $(resources.pipeline.CI.runName)
displayName: 📢 Update GitHub release using Releaser
Loading

0 comments on commit 719c1ce

Please sign in to comment.