|
| 1 | +trigger: |
| 2 | + branches: |
| 3 | + include: |
| 4 | + - develop |
| 5 | + |
| 6 | +pool: |
| 7 | + name: win2016-vs2017 |
| 8 | +# name: Azure Pipelines |
| 9 | + |
| 10 | +steps: |
| 11 | + - checkout: self |
| 12 | + clean: true |
| 13 | + lfs: true |
| 14 | + - task: AzureKeyVault@2 |
| 15 | + displayName: 'Azure Key Vault: keyvault-build-resources' |
| 16 | + inputs: |
| 17 | + ConnectedServiceName: 514ed7d6-3846-4422-8013-af27483dd22c |
| 18 | + KeyVaultName: keyvault-build-resources |
| 19 | + RunAsPreJob: true |
| 20 | + - task: PowerShell@2 |
| 21 | + displayName: PowerShell Script |
| 22 | + condition: and(succeeded(), eq('${{ variables.veracodeSCA }}', 'true')) |
| 23 | + inputs: |
| 24 | + targetType: inline |
| 25 | + script: > |
| 26 | + $Env:SRCCLR_API_TOKEN="$(SRCCLR_API_TOKEN)"; Set-ExecutionPolicy AllSigned -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://download.srcclr.com/ci.ps1')); srcclr scan .\Src\StackifyLib; |
| 27 | + - task: DownloadSecureFile@1 |
| 28 | + name: SNK |
| 29 | + displayName: Download Strong Name Key |
| 30 | + inputs: |
| 31 | + secureFile: 9d810a2d-d090-431c-9012-df939a4b1afe |
| 32 | + - task: PowerShell@2 |
| 33 | + displayName: Move Signing Key To Project Directory |
| 34 | + inputs: |
| 35 | + targetType: inline |
| 36 | + filePath: Src/StackifyLib |
| 37 | + script: | |
| 38 | + # Write your PowerShell commands here. |
| 39 | + ls |
| 40 | + Move-Item $(SNK.secureFilePath) Src/StackifyLib/Netreo.snk |
| 41 | + - task: PowerShell@2 |
| 42 | + displayName: Update csproj for .snk |
| 43 | + inputs: |
| 44 | + targetType: inline |
| 45 | + script: > |
| 46 | + (Get-Content -path Src\StackifyLib\StackifyLib.csproj -Raw) -replace '<PackageId>StackifyLib</PackageId>','<PackageId>StackifyLib.signed</PackageId>' | Set-Content -Path Src\StackifyLib\StackifyLib.csproj |
| 47 | + - task: PowerShell@2 |
| 48 | + displayName: 'Setup Code Signing' |
| 49 | + inputs: |
| 50 | + targetType: filePath |
| 51 | + filePath: ./Scripts/codesign.ps1 |
| 52 | + arguments: '$(codeSigning2023) $(codeSigning2023-pw)' |
| 53 | + workingDirectory: $(Build.SourcesDirectory) |
| 54 | + - task: DotNetCoreCLI@2 |
| 55 | + displayName: dotnet restore |
| 56 | + inputs: |
| 57 | + command: restore |
| 58 | + restoreArguments: .\Src |
| 59 | + - task: DotNetCoreCLI@2 |
| 60 | + displayName: dotnet build |
| 61 | + inputs: |
| 62 | + projects: | |
| 63 | + Src\StackifyLib\*.csproj |
| 64 | + Src\StackifyLib.AspNetCore\*.csproj |
| 65 | + Src\StackifyLib.CoreLogger\*.csproj |
| 66 | + Src\StackifyLib.log4net\*.csproj |
| 67 | + Src\Nlog.Targets.Stackify\*.csproj |
| 68 | + Src\NLog.Web.Stackify\*.csproj |
| 69 | + Src\StackifyLib.StackifyTraceListener\*.csproj |
| 70 | + arguments: '-c $(BuildConfiguration)' |
| 71 | + - task: DotNetCoreCLI@2 |
| 72 | + displayName: dotnet pack signed stackify lib |
| 73 | + inputs: |
| 74 | + command: pack |
| 75 | + searchPatternPack: Src\StackifyLib\*.csproj; |
| 76 | + nobuild: true |
| 77 | + - task: PowerShell@2 |
| 78 | + displayName: 'Sign Nuget Packages' |
| 79 | + inputs: |
| 80 | + targetType: inline |
| 81 | + script: dotnet nuget sign $(Build.ArtifactStagingDirectory)\*.nupkg --certificate-path $(Build.SourcesDirectory)/certificate.pfx --certificate-password $(codeSigning2023-pw) --timestamper http://timestamp.sectigo.com |
| 82 | + workingDirectory: $(Build.SourcesDirectory) |
| 83 | + - task: PowerShell@2 |
| 84 | + displayName: Rename signed assemblies |
| 85 | + enabled: False |
| 86 | + inputs: |
| 87 | + targetType: inline |
| 88 | + script: "$files = @(Get-ChildItem -Path . -File -Filter *.nupkg)\n\nforeach($file in $files) {\n $BaseFilename = $file.BaseName\n $BaseFilenameSplit = $file.BaseName.Split(\".\")\n $LastVersionDigit = \"\"\n $NewFilenameBase = \"\"\n $PackageVersion = \"\"\n $IsBeta = \"False\"\n if ($BaseFilename.contains(\"beta\")) {\n $IsBeta = \"True\"\n $LastVersionDigit = $file.BaseName.Substring($BaseFilename.length - 6,1)\n }\n else {\n $LastVersionDigit = $file.BaseName.Substring($BaseFilename.length - 1)\n }\n foreach($namePart in $BaseFilenameSplit) {\n if (!$namePart.contains(\"beta\") -and $namePart -notmatch \"^\\d+$\") {\n $NewFilenameBase = $NewFilenameBase + $namePart + \".\"\n } else {\n # check for beta\n if ($namePart.contains(\"beta\")) {\n $PackageVersion = $PackageVersion + $namePart.Substring(0,1)\n } else {\n $PackageVersion = $PackageVersion + $namePart\n }\n # check length to append a .\n if ($namePart -notmatch $LastVersionDigit) {\n $PackageVersion = $PackageVersion + \".\"\n }\n }\n }\n \n # check beta\n $FinalFilenameBase = \"\"\n if ($IsBeta -match \"True\") {\n $FinalFilenameBase = $NewFilenameBase + \"snk.\" + $PackageVersion + \"-beta\"\n } else {\n $FinalFilenameBase = $NewFilenameBase + \"snk.\" + $PackageVersion\n }\n $FinalFilename = $FinalFilenameBase + $file.Extension\n Rename-Item -Path $file -NewName $FinalFilename\n}" |
| 89 | + workingDirectory: $(Build.ArtifactStagingDirectory) |
| 90 | + - task: PublishPipelineArtifact@1 |
| 91 | + displayName: Publish Pipeline Artifact |
| 92 | + inputs: |
| 93 | + path: $(Build.ArtifactStagingDirectory) |
| 94 | + artifactName: Signed NuGet Packages |
| 95 | + - task: PowerShell@2 |
| 96 | + displayName: Delete signed assemblies |
| 97 | + enabled: true |
| 98 | + inputs: |
| 99 | + targetType: inline |
| 100 | + script: > |
| 101 | + Remove-Item *.signed*.nupkg |
| 102 | + workingDirectory: $(Build.ArtifactStagingDirectory) |
| 103 | + - task: PowerShell@2 |
| 104 | + displayName: Remove Sign Code |
| 105 | + enabled: false |
| 106 | + inputs: |
| 107 | + targetType: filePath |
| 108 | + arguments: '' |
| 109 | + filePath: Scripts/RemoveSignCode.ps1 |
| 110 | + workingDirectory: $(Build.SourcesDirectory) |
| 111 | + - task: PowerShell@2 |
| 112 | + displayName: Remove Sign Code Inline |
| 113 | + inputs: |
| 114 | + targetType: 'inline' |
| 115 | + script: | |
| 116 | + function Remove-SignCode { |
| 117 | + param ( |
| 118 | + $ASMFile |
| 119 | + ) |
| 120 | + Set-Content -Path $ASMFile -Value (Get-Content -Path $ASMFile | Select-String -Pattern AssemblyKeyFileAttribute -NotMatch ) |
| 121 | + } |
| 122 | + |
| 123 | + $files = @(Get-ChildItem -Path . -Directory -Filter Stackify*) |
| 124 | + |
| 125 | + foreach ($file in $files) { |
| 126 | + $asmInfo = Get-ChildItem -Path $file/Properties/AssemblyInfo.cs |
| 127 | + Remove-SignCode -ASMFile $asmInfo |
| 128 | + } |
| 129 | + - task: PowerShell@2 |
| 130 | + displayName: Update csproj for no .snk |
| 131 | + inputs: |
| 132 | + targetType: inline |
| 133 | + script: > |
| 134 | + (Get-Content -path Src\StackifyLib\StackifyLib.csproj -Raw) -replace '<PackageId>StackifyLib.signed</PackageId>','<PackageId>StackifyLib</PackageId>' | Set-Content -Path Src\StackifyLib\StackifyLib.csproj |
| 135 | + - task: DotNetCoreCLI@2 |
| 136 | + displayName: dotnet build [Unsigned] |
| 137 | + inputs: |
| 138 | + projects: | |
| 139 | + Src\StackifyLib\*.csproj |
| 140 | + Src\StackifyLib.AspNetCore\*.csproj |
| 141 | + Src\StackifyLib.CoreLogger\*.csproj |
| 142 | + Src\StackifyLib.log4net\*.csproj |
| 143 | + Src\Nlog.Targets.Stackify\*.csproj |
| 144 | + Src\NLog.Web.Stackify\*.csproj |
| 145 | + Src\StackifyLib.StackifyTraceListener\*.csproj |
| 146 | + arguments: '-c $(BuildConfiguration)' |
| 147 | + - task: DotNetCoreCLI@2 |
| 148 | + displayName: dotnet pack copy [Unsigned] |
| 149 | + inputs: |
| 150 | + command: pack |
| 151 | + searchPatternPack: 'Src\StackifyLib\*.csproj;Src\StackifyLib.AspNetCore\*.csproj;Src\StackifyLib.CoreLogger\*.csproj;Src\StackifyLib.log4net\*.csproj;Src\Nlog.Targets.Stackify\*.csproj;Src\NLog.Web.Stackify\*.csproj;Src\StackifyLib.StackifyTraceListener\*.csproj ' |
| 152 | + nobuild: true |
| 153 | + - task: PublishPipelineArtifact@1 |
| 154 | + displayName: Publish Pipeline Artifact [Unsigned] |
| 155 | + inputs: |
| 156 | + path: $(Build.ArtifactStagingDirectory) |
| 157 | + artifactName: Unsigned NuGet Packages |
| 158 | + - task: PowerShell@2 |
| 159 | + displayName: PowerShell Script |
| 160 | + inputs: |
| 161 | + targetType: inline |
| 162 | + script: | |
| 163 | + $xml = [Xml] (Get-Content .\Src\StackifyLib\StackifyLib.csproj) |
| 164 | + $version = $xml.Project.PropertyGroup.Version |
| 165 | + echo $version |
| 166 | + echo "##vso[task.setvariable variable=version]$version" |
| 167 | + echo "StackifyLib."$version".nupkg" |
| 168 | + workingDirectory: $(Build.SourcesDirectory) |
| 169 | + - task: Veracode@3 |
| 170 | + displayName: 'Upload and scan: $(Build.ArtifactStagingDirectory)/StackifyLib.$(BuildVersion).nupkg' |
| 171 | + enabled: False |
| 172 | + inputs: |
| 173 | + AnalysisService: 51003f89-58ab-463c-8e20-41484888d9c7 |
| 174 | + veracodeAppProfile: Retrace .Net StackifyLib |
| 175 | + version: AZ-Devops-Build-$(build.buildNumber) |
| 176 | + filepath: $(Build.ArtifactStagingDirectory)/StackifyLib.$(BuildVersion).nupkg |
0 commit comments