Skip to content

Commit

Permalink
tools enhanced Edit-VcpkgRefAndHash
Browse files Browse the repository at this point in the history
 - added logging of SHA512 hash
 - added verification of replaced REF and SHA512
  • Loading branch information
silverqx committed Oct 18, 2023
1 parent ea93736 commit a4cba07
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tools/private/Common-Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,41 @@ function Test-RefAndHashLinesCountForVcpkg {
"expected occurrences must be '$ExpectedOccurrences'."
}

# Verify if the REF and SHA512 were correctly replaced in the given portfile
function Test-VcpkgRefAndHashReplaced {
[OutputType([void])]
Param(
[Parameter(Mandatory, HelpMessage = 'Specifies the portfile.cmake filepath to update.')]
[ValidateNotNullOrEmpty()]
[string] $PortFile,

[Parameter(Mandatory, HelpMessage = 'Specifies the REF in the portfile.cmake to update.')]
[ValidateNotNullOrEmpty()]
[string] $Ref,

[Parameter(Mandatory,
HelpMessage = 'Specifies the SHA512 hash in the portfile.cmake to update.')]
[ValidateNotNullOrEmpty()]
[string] $Hash
)

$refEscaped = [regex]::Escape($Ref)
$hashEscaped = [regex]::Escape($Hash)

$regexRef = "^(?: REF )(?:${refEscaped})$"
$regexHash = "^(?: SHA512 )(?:${hashEscaped})$"
$regexMatch = "$regexRef|$regexHash"

$fileContent = Get-Content -Path $portfilePath

$matchedLines = $fileContent -cmatch $regexMatch

# Verify if the portfile.cmake file contains the REF and SHA512 lines
$expectedOccurrences = 2
Test-RefAndHashLinesCountForVcpkg `
$matchedLines.Count $expectedOccurrences $regexMatch $portfilePath
}

# Update the REF and SHA512 in tinyorm and tinyorm-qt5 portfiles
function Edit-VcpkgRefAndHash {
[OutputType([void])]
Expand Down Expand Up @@ -114,6 +149,8 @@ function Edit-VcpkgRefAndHash {
& "$toolsFolder\Get-VcpkgHash.ps1" -Project $Project -Ref $Ref -TimeoutSec 15 @retries
Test-LastExitCode

Write-Output $vcpkgHash

foreach ($portfilePath in $PortFile) {
$regexRef = '^(?<ref> REF )(?:[0-9a-f]{40}|v\d+\.\d+\.\d+|[\w\d-_\/]+)$'
$regexHash = '^(?<sha512> SHA512 )(?:[0-9a-f]{128})$'
Expand All @@ -134,5 +171,8 @@ function Edit-VcpkgRefAndHash {

# Save to the file
($fileContentReplaced -join "`n") + "`n" | Set-Content -Path $portfilePath -NoNewline

# Verify if the REF and SHA512 were correctly replaced in the given portfile
Test-VcpkgRefAndHashReplaced -PortFile $portfilePath -Ref $Ref -Hash $vcpkgHash
}
}

0 comments on commit a4cba07

Please sign in to comment.