-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3158 from andreaTP/verify-idempotency
Verify idempotency
- Loading branch information
Showing
21 changed files
with
368 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,3 +448,5 @@ reports/ | |
|
||
samples/ | ||
it/openapi.yaml | ||
|
||
idempotency*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env pwsh | ||
|
||
param( | ||
[Parameter(Mandatory = $true)][string]$descriptionUrl, | ||
[Parameter(Mandatory = $true)][string]$language, | ||
[Parameter(Mandatory = $false)][switch]$dev, | ||
[Parameter(Mandatory = $false)][switch]$preserveOutput | ||
) | ||
|
||
if ([string]::IsNullOrEmpty($descriptionUrl)) { | ||
Write-Error "Description URL is empty" | ||
exit 1 | ||
} | ||
|
||
if ([string]::IsNullOrEmpty($language)) { | ||
Write-Error "Language is empty" | ||
exit 1 | ||
} | ||
|
||
function New-TemporaryDirectory { | ||
$parent = [System.IO.Path]::GetTempPath() | ||
[string] $name = [System.Guid]::NewGuid() | ||
New-Item -ItemType Directory -Path (Join-Path $parent $name) | ||
} | ||
|
||
$rootPath = Join-Path -Path $PSScriptRoot -ChildPath ".." | ||
|
||
$Env:KIOTA_TUTORIAL_ENABLED = "false" | ||
$executableName = "kiota" | ||
if ($IsWindows) { | ||
$executableName = "kiota.exe" | ||
} | ||
|
||
switch ($dev) { | ||
$true { | ||
Write-Warning "Using kiota in dev mode" | ||
$kiotaExec = Join-Path -Path $rootPath -ChildPath "src" -AdditionalChildPath "kiota", "bin", "Debug", "net7.0", $executableName | ||
break | ||
} | ||
default { | ||
$kiotaExec = Join-Path -Path $rootPath -ChildPath "publish" -AdditionalChildPath $executableName | ||
break | ||
} | ||
} | ||
|
||
$targetOpenapiPath = Join-Path -Path $PSScriptRoot -ChildPath "openapi.yaml" | ||
if (Test-Path $targetOpenapiPath) { | ||
Remove-Item $targetOpenapiPath | ||
} | ||
|
||
if ($descriptionUrl.StartsWith("./")) { | ||
Copy-Item -Path $descriptionUrl -Destination $targetOpenapiPath -Force | ||
} | ||
elseif ($descriptionUrl.StartsWith("http")) { | ||
Invoke-WebRequest -Uri $descriptionUrl -OutFile $targetOpenapiPath | ||
} | ||
else { | ||
Start-Process "$kiotaExec" -ArgumentList "download ${descriptionUrl} --clean-output --output $targetOpenapiPath" -Wait -NoNewWindow | ||
} | ||
|
||
$tmpFolder1 = New-TemporaryDirectory | ||
$tmpFolder2 = New-TemporaryDirectory | ||
|
||
Start-Process "$kiotaExec" -ArgumentList "generate --clean-output --language ${language} --openapi ${targetOpenapiPath} --dvr all --output $tmpFolder1" -Wait -NoNewWindow | ||
Start-Process "$kiotaExec" -ArgumentList "generate --clean-output --language ${language} --openapi ${targetOpenapiPath} --dvr all --output $tmpFolder2" -Wait -NoNewWindow | ||
|
||
# Remove variable output files | ||
Remove-Item (Join-Path -Path $tmpFolder1 -ChildPath "kiota-lock.json") | ||
if (Test-Path (Join-Path -Path $tmpFolder1 -ChildPath ".kiota.log")) { | ||
Remove-Item -Force (Join-Path -Path $tmpFolder1 -ChildPath ".kiota.log") | ||
} | ||
Remove-Item (Join-Path -Path $tmpFolder2 -ChildPath "kiota-lock.json") | ||
if (Test-Path (Join-Path -Path $tmpFolder2 -ChildPath ".kiota.log")) { | ||
Remove-Item -Force (Join-Path -Path $tmpFolder2 -ChildPath ".kiota.log") | ||
} | ||
|
||
# Compare hashes | ||
$HashString1 = (Get-ChildItem $tmpFolder1 -Recurse | where { ! $_.PSIsContainer } | Get-FileHash -Algorithm MD5).Hash | Out-String | ||
Get-FileHash -InputStream ([IO.MemoryStream]::new([char[]]$HashString1)) | ||
|
||
$HashString2 = (Get-ChildItem $tmpFolder2 -Recurse | where { ! $_.PSIsContainer } | Get-FileHash -Algorithm MD5).Hash | Out-String | ||
Get-FileHash -InputStream ([IO.MemoryStream]::new([char[]]$HashString2)) | ||
|
||
Write-Output "Folder 1: $tmpFolder1" | ||
Write-Output "Folder 2: $tmpFolder2" | ||
|
||
if ($HashString1 -eq $HashString2) { | ||
Write-Output "The content of the folders is identical" | ||
|
||
if (!$preserveOutput) { | ||
Remove-Item $tmpFolder1 -Force -Recurse | ||
Remove-Item $tmpFolder2 -Force -Recurse | ||
} | ||
|
||
Exit 0 | ||
} | ||
else { | ||
Write-Error "The content of the folders is NOT identical" | ||
$archivePath1 = Join-Path $rootPath -ChildPath "idempotency-folder1.zip" | ||
$archivePath2 = Join-Path $rootPath -ChildPath "idempotency-folder2.zip" | ||
|
||
if (Test-Path $archivePath1) { | ||
Remove-Item $archivePath1 -Force -Verbose | ||
} | ||
if (Test-Path $archivePath2) { | ||
Remove-Item $archivePath2 -Force -Verbose | ||
} | ||
|
||
if ($dev -eq $false) { | ||
Write-Host "Creating archives at location $archivePath1 and $archivePath2" | ||
Compress-Archive -Path $tmpFolder1 -DestinationPath $archivePath1 | ||
Compress-Archive -Path $tmpFolder1 -DestinationPath $archivePath2 | ||
} | ||
Exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.