1- param ($sourcesDirectory )
2-
3- [xml ]$versionProps = Get-Content " $env: BUILD_SOURCESDIRECTORY \scripts\version\Version.props"
4- $version = $versionProps.Project.PropertyGroup.MainVersion + $versionProps.Project.PropertyGroup.PrereleaseSuffix
5-
6- $artifactsFolder = " $env: BUILD_SOURCESDIRECTORY \\build"
7-
8- $netFrameworkScannerZipPath = Get-Item " $artifactsFolder \\sonarscanner-net-framework.zip"
9- $netScannerZipPath = Get-Item " $artifactsFolder \\sonarscanner-net.zip"
10- $netScannerGlobalToolPath = Get-Item " $artifactsFolder \\dotnet-sonarscanner.$version .nupkg"
11- $sbomJsonPath = Get-Item " $sourcesDirectory \build\bom.json"
12-
13- Write-Host " Generating the chocolatey packages"
14- $netFrameworkZipPath = (Get-FileHash $netFrameworkScannerZipPath - Algorithm SHA256).hash
15- $netFrameworkPs1 = " nuspec\chocolatey\chocolateyInstall-net-framework.ps1"
16- (Get-Content $netFrameworkPs1 ) `
17- -Replace ' -Checksum "not-set"' , " -Checksum $netFrameworkZipPath " `
18- -Replace " __PackageVersion__" , " $version " `
19- | Set-Content $netFrameworkPs1
20-
21- $netZipHash = (Get-FileHash $netScannerZipPath - Algorithm SHA256).hash
22- $netPs1 = " nuspec\chocolatey\chocolateyInstall-net.ps1"
23- (Get-Content $netPs1 ) `
24- -Replace ' -Checksum "not-set"' , " -Checksum $netZipHash " `
25- -Replace " __PackageVersion__" , " $version " `
26- | Set-Content $netPs1
27-
28- choco pack nuspec\chocolatey\sonarscanner- net- framework.nuspec `
29- -- outputdirectory $artifactsFolder `
30- -- version $version
31-
32- choco pack nuspec\chocolatey\sonarscanner- net.nuspec `
33- -- outputdirectory $artifactsFolder `
34- -- version $version
35-
36- Write-Host " Update artifacts locations in pom.xml"
37- $pomFile = " .\pom.xml"
38- (Get-Content $pomFile ) `
39- -Replace ' netFrameworkScannerZipPath' , " $netFrameworkScannerZipPath " `
40- -Replace ' netScannerZipPath' , " $netScannerZipPath " `
41- -Replace ' netScannerGlobalToolPath' , " $netScannerGlobalToolPath " `
42- -Replace ' netFrameworkScannerChocoPath' , " $artifactsFolder \\sonarscanner-net-framework.$version .nupkg" `
43- -Replace ' netScannerChocoPath' , " $artifactsFolder \\sonarscanner-net.$version .nupkg" `
44- -Replace ' sbomPath' , " $sbomJsonPath " `
45- | Set-Content $pomFile
1+ # This script generates the chocolatey packages for the .NET Scanner and the .NET Framework Scanner and updates the pom.xml file with the new artifacts locations.
2+
3+ # The chocolatey packages are generated from the nuspec files located in the nuspec\chocolatey folder and they point to GitHub artifacts that have the following format:
4+ # Release candidates:
5+ # - https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/9.0.0-rc.99116/sonar-scanner-9.0.0-rc.99116-net.zip
6+ # - https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/9.0.0-rc.99116/sonar-scanner-9.0.0-rc.99116-net-framework.zip
7+ # Normal releases:
8+ # - https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/8.0.3.99785/sonar-scanner-8.0.3.99785-net.zip
9+ # - https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/8.0.3.99785/sonar-scanner-8.0.3.99785-net-framework.zip
10+
11+ # In the case of pre-releases, the full version is following the Sem 2 versioning format: 9.0.0-rc.99116.
12+ # Unfortunatelly Choco only supports Sem 1 versioning format, which does not allow anything except for [0-9A-Za-z-] after the dash in `-rc`.
13+ # Due to this, when calling `choco pack` the version should not contain the build number (9.0.0-rc).
14+ # At the same time the the url inside the ps1 file that downloads the scanner should be correct and contain the build number.
15+
16+ param (
17+ [string ] $sourcesDirectory = $env: BUILD_SOURCESDIRECTORY ,
18+ [string ] $buildId = $env: BUILD_BUILDID
19+ )
20+
21+ function Update-Choco-Package ([string ] $scannerZipFileName , [string ] $runtimeSuffix ) {
22+ Write-Host " Generating the chocolatey package from $scannerZipFileName "
23+
24+ $hash = (Get-FileHash $scannerZipFileName - Algorithm SHA256).hash
25+ $powershellScriptPath = " nuspec/chocolatey/chocolateyInstall-$runtimeSuffix .ps1"
26+ Write-Host (Get-Item $powershellScriptPath ).FullName
27+ (Get-Content $powershellScriptPath ) `
28+ -Replace ' -Checksum "not-set"' , " -Checksum $hash " `
29+ -Replace ' __PackageVersion__' , " $fullVersion " `
30+ | Set-Content $powershellScriptPath
31+
32+ choco pack " nuspec/chocolatey/sonarscanner-$runtimeSuffix .nuspec" -- outputdirectory $artifactsFolder -- version $shortVersion
33+ }
34+
35+ function Update-Pom-File () {
36+ Write-Host ' Update artifacts locations in pom.xml'
37+ $sbomJsonPath = Get-Item " $sourcesDirectory /build/bom.json"
38+ $netScannerGlobalToolPath = Get-Item " $artifactsFolder /dotnet-sonarscanner.$shortVersion .nupkg" # dotnet-sonarscanner.9.0.0-rc.nupkg or dotnet-sonarscanner.9.0.0.nupkg
39+ $pomFile = ' ./pom.xml'
40+ (Get-Content $pomFile ) `
41+ -Replace ' netFrameworkScannerZipPath' , " $netFrameworkScannerZipPath " `
42+ -Replace ' netScannerZipPath' , " $netScannerZipPath " `
43+ -Replace ' netScannerGlobalToolPath' , " $netScannerGlobalToolPath " `
44+ -Replace ' netFrameworkScannerChocoPath' , " $artifactsFolder /sonarscanner-net-framework.$shortVersion .nupkg" `
45+ -Replace ' netScannerChocoPath' , " $artifactsFolder /sonarscanner-net.$shortVersion .nupkg" `
46+ -Replace ' sbomPath' , " $sbomJsonPath " `
47+ | Set-Content $pomFile
48+ }
49+
50+ function Run () {
51+ Update-Choco - Package $netFrameworkScannerZipPath ' net-framework'
52+ Update-Choco - Package $netScannerZipPath ' net'
53+ Update-Pom - File
54+ }
55+
56+ # Read the version from the Version.props file and initialize the global variables.
57+ $artifactsFolder = " $sourcesDirectory /build"
58+ $netFrameworkScannerZipPath = Get-Item " $artifactsFolder /sonarscanner-net-framework.zip"
59+ $netScannerZipPath = Get-Item " $artifactsFolder /sonarscanner-net.zip"
60+
61+ Write-Host ' Reading version information from Version.props file'
62+ [xml ] $versionProps = Get-Content " $sourcesDirectory /scripts/version/Version.props"
63+ $shortVersion = $versionProps.Project.PropertyGroup.MainVersion + $versionProps.Project.PropertyGroup.PrereleaseSuffix # 9.0.0-rc for release candidates or 9.0.0 for normal releases.
64+ $fullVersion = $shortVersion + ' .' + $buildId # 9.0.0-rc.99116 for release candidates or 9.0.0.99116 for normal releases.
65+ Write-Host " Short version is $shortVersion , Full version is $fullVersion "
0 commit comments