Skip to content

Commit

Permalink
SCAN4NET-101 Run tests for package generation script (#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource authored Sep 26, 2024
1 parent 0481189 commit 43dfcbb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 5 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ stages:
SM_API_KEY: $(SM_API_KEY)
SM_CERT: $(SM_CERT)
- powershell: .\scripts\promote-project-version.ps1
displayName: 'Promote project version'

Expand Down Expand Up @@ -225,6 +224,11 @@ stages:
inputs:
secureFile: 'maven-settings.xml'

- powershell: |
Install-Module -Name Pester -Force -SkipPublisherCheck # https://pester.dev/docs/introduction/installation#windows
Invoke-Pester -Output Detailed -CI -Script .\scripts\generate-packages.tests.ps1
displayName: 'Test package generation script'
- powershell: |
. .\scripts\generate-packages.ps1
Run
Expand Down
12 changes: 10 additions & 2 deletions scripts/generate-packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
# Due to this, when calling `choco pack` the version should not contain the build number (9.0.0-rc).
# At the same time the the url inside the ps1 file that downloads the scanner should be correct and contain the build number.

[CmdletBinding()]
param (
[string] $sourcesDirectory = $env:BUILD_SOURCESDIRECTORY,
[string] $buildId = $env:BUILD_BUILDID
[Parameter()]
[AllowNull()]
[string]
$sourcesDirectory = $env:BUILD_SOURCESDIRECTORY,

[Parameter()]
[AllowNull()]
[string]
$buildId = $env:BUILD_BUILDID
)

function Update-Choco-Package([string] $scannerZipFileName, [string] $runtimeSuffix) {
Expand Down
19 changes: 8 additions & 11 deletions scripts/generate-packages.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,19 @@ Describe 'Choco package generation' {
@{ Version = '1.2.3'; PreReleaseSuffix = '-rc'; ExpectedShortVersion = '1.2.3-rc'; ExpectedFullVersion = '1.2.3-rc.99116' }
@{ Version = '1.2.3'; PreReleaseSuffix = ''; ExpectedShortVersion = '1.2.3'; ExpectedFullVersion = '1.2.3.99116' }
) {
$unzipLocation = '$(Split-Path -parent $MyInvocation.MyCommand.Definition)'
$expectedChocoInstallContents = @('Install-ChocolateyZipPackage "sonarscanner-net-framework" `',
" -Url ""https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/$ExpectedFullVersion/sonar-scanner-$ExpectedFullVersion-net-framework.zip"" ``",
" -UnzipLocation ""$unzipLocation"" ``",
" -ChecksumType 'sha256' ``",
" -Checksum E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855")
Set-Version $Version $PreReleaseSuffix

. $PSScriptRoot/generate-packages.ps1 -sourcesDirectory . -buildId 99116

Update-Choco-Package $netFrameworkScannerZipPath 'net-framework'

$unzipLocation = '$(Split-Path -parent $MyInvocation.MyCommand.Definition)'
Get-Content -Raw 'nuspec/chocolatey/chocolateyInstall-net-framework.ps1' | Should -BeExactly "Install-ChocolateyZipPackage ""sonarscanner-net-framework"" ``
-Url ""https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/$ExpectedFullVersion/sonar-scanner-$ExpectedFullVersion-net-framework.zip"" ``
-UnzipLocation ""$unzipLocation"" ``
-ChecksumType 'sha256' ``
-Checksum E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
"
Update-Choco-Package "$PSScriptRoot/testcontext/build/sonarscanner-net-framework.zip" 'net-framework'

Get-Content 'nuspec/chocolatey/chocolateyInstall-net-framework.ps1' | Should -Be $expectedChocoInstallContents
"build/sonarscanner-net-framework.$ExpectedShortVersion.nupkg" | Should -Exist

CheckVersion "sonarscanner-net-framework.$ExpectedShortVersion.nupkg" 'sonarscanner-net-framework.nuspec' "<version>$ExpectedShortVersion</version>"
}
}
Expand Down

0 comments on commit 43dfcbb

Please sign in to comment.