Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix reproducibility tests after release #76

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 100 additions & 100 deletions src/header.ps1
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
$ErrorActionPreference = "Stop"
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
$tempDir = New-Item -ItemType Directory -Path (Join-Path $parent $name)
return $tempDir.FullName
}
$TEMPDIR = New-TemporaryDirectory
$USAGE = @"
Usage: $($MyInvocation.MyCommand.Name) [OPTIONS]
Arguments:
Path to an environment packed using pixi-pack
Options:
-o, --output-directory <DIR> Where to unpack the environment. The environment will be unpacked into a subdirectory of this path [default: env]
-e, --env-name <NAME> Name of the environment [default: env]
-s, --shell <SHELL> Sets the shell [options: bash, zsh, xonsh, cmd, powershell, fish, nushell]
-v, --verbose Increase logging verbosity
-q, --quiet Decrease logging verbosity
-h, --help Print help
"@
foreach ($arg in $args) {
if ($arg -eq "-h" -or $arg -eq "--help") {
Write-Output $USAGE
exit 0
}
}
# Extract the archive and pixi-pack executable, and decode them
$scriptContent = Get-Content -Raw -Path $MyInvocation.MyCommand.Path
$lines = $scriptContent -split "`r?`n"
$headerLine = $null
$archiveLine = $null
# Find the lines where __END_HEADER__ and __END_ARCHIVE__ occur
for ($i = 0; $i -lt $lines.Count; $i++) {
if ($lines[$i] -like "*__END_HEADER__*") {
$headerLine = $i + 2
}
if ($lines[$i] -like "*__END_ARCHIVE__*") {
$archiveLine = $i + 1
}
}
if (-not $headerLine -or -not $archiveLine) {
Write-Error "ERROR: Markers __END_HEADER__ or __END_ARCHIVE__ not found."
exit 1
}
# Extract Base64 content for the tar archive
$archiveContent = $lines[($headerLine)..($archiveLine - 2)] -join ""
$archiveContent = $archiveContent.Trim()
# Decode Base64 content into tar file
try {
$decodedArchive = [System.Convert]::FromBase64String($archiveContent)
$archivePath = "$TEMPDIR\archive.tar"
[System.IO.File]::WriteAllBytes($archivePath, $decodedArchive)
} catch {
Write-Error "ERROR: Failed to decode Base64 archive content: $_"
exit 1
}
# Extract Base64 content for pixi-pack executable
$pixiPackContent = $lines[($archiveLine)..($lines.Count - 1)] -join ""
$pixiPackContent = $pixiPackContent.Trim()
# Decode Base64 content into the pixi-pack executable file
try {
$decodedPixiPack = [System.Convert]::FromBase64String($pixiPackContent)
$pixiPackPath = "$TEMPDIR\pixi-pack.exe"
[System.IO.File]::WriteAllBytes($pixiPackPath, $decodedPixiPack)
} catch {
Write-Error "Failed to decode Base64 pixi-pack content: $_"
exit 1
}
# Build the command with flags
$arguments = @("unpack")
$arguments += $args
# Add the path to the archive
$arguments += $archivePath
& $pixiPackPath $arguments
if ($LASTEXITCODE -ne 0) {
Remove-Item -Path $TEMPDIR -Recurse -Force
exit $LASTEXITCODE
}
Remove-Item -Path $TEMPDIR -Recurse -Force
exit 0
__END_HEADER__
$ErrorActionPreference = "Stop"

function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
$tempDir = New-Item -ItemType Directory -Path (Join-Path $parent $name)
return $tempDir.FullName
}

$TEMPDIR = New-TemporaryDirectory
$USAGE = @"
Usage: $($MyInvocation.MyCommand.Name) [OPTIONS]

Arguments:
Path to an environment packed using pixi-pack

Options:
-o, --output-directory <DIR> Where to unpack the environment. The environment will be unpacked into a subdirectory of this path [default: env]
-e, --env-name <NAME> Name of the environment [default: env]
-s, --shell <SHELL> Sets the shell [options: bash, zsh, xonsh, cmd, powershell, fish, nushell]
-v, --verbose Increase logging verbosity
-q, --quiet Decrease logging verbosity
-h, --help Print help
"@

foreach ($arg in $args) {
if ($arg -eq "-h" -or $arg -eq "--help") {
Write-Output $USAGE
exit 0
}
}

# Extract the archive and pixi-pack executable, and decode them
$scriptContent = Get-Content -Raw -Path $MyInvocation.MyCommand.Path
$lines = $scriptContent -split "`r?`n"

$headerLine = $null
$archiveLine = $null

# Find the lines where __END_HEADER__ and __END_ARCHIVE__ occur
for ($i = 0; $i -lt $lines.Count; $i++) {
if ($lines[$i] -like "*__END_HEADER__*") {
$headerLine = $i + 2
}
if ($lines[$i] -like "*__END_ARCHIVE__*") {
$archiveLine = $i + 1
}
}

if (-not $headerLine -or -not $archiveLine) {
Write-Error "ERROR: Markers __END_HEADER__ or __END_ARCHIVE__ not found."
exit 1
}

# Extract Base64 content for the tar archive
$archiveContent = $lines[($headerLine)..($archiveLine - 2)] -join ""
$archiveContent = $archiveContent.Trim()

# Decode Base64 content into tar file
try {
$decodedArchive = [System.Convert]::FromBase64String($archiveContent)
$archivePath = "$TEMPDIR\archive.tar"
[System.IO.File]::WriteAllBytes($archivePath, $decodedArchive)
} catch {
Write-Error "ERROR: Failed to decode Base64 archive content: $_"
exit 1
}

# Extract Base64 content for pixi-pack executable
$pixiPackContent = $lines[($archiveLine)..($lines.Count - 1)] -join ""
$pixiPackContent = $pixiPackContent.Trim()

# Decode Base64 content into the pixi-pack executable file
try {
$decodedPixiPack = [System.Convert]::FromBase64String($pixiPackContent)
$pixiPackPath = "$TEMPDIR\pixi-pack.exe"
[System.IO.File]::WriteAllBytes($pixiPackPath, $decodedPixiPack)
} catch {
Write-Error "Failed to decode Base64 pixi-pack content: $_"
exit 1
}

# Build the command with flags
$arguments = @("unpack")
$arguments += $args

# Add the path to the archive
$arguments += $archivePath

& $pixiPackPath $arguments
if ($LASTEXITCODE -ne 0) {
Remove-Item -Path $TEMPDIR -Recurse -Force
exit $LASTEXITCODE
}

Remove-Item -Path $TEMPDIR -Recurse -Force

exit 0

__END_HEADER__
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration_test.rs
assertion_line: 352
assertion_line: 358
expression: "&sha256_digest"
snapshot_kind: text
---
5A797AC80010BCFCE103F53892CDEA582C82364264CE6C4FF8EF5643F23CD3BD
00FFF8329F4CCECC1BC5D5210770ABDF61DFA471288A5265D6C171BE705E416E
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration_test.rs
assertion_line: 352
assertion_line: 358
expression: "&sha256_digest"
snapshot_kind: text
---
2D9DACCC1641D534A8B4003F121296F37D550C07B87108DFBE135D06FDD5D8A2
A54DBE60FBFE8FAC7D5334D899092DDAE7154E829F4E817ED38442FBEDC710AE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration_test.rs
assertion_line: 352
assertion_line: 358
expression: "&sha256_digest"
snapshot_kind: text
---
5D75D036EA7C29A43E15755D79381827A34B3160026776AC3D5A53B2073082B8
5DD69B8319D10E1B210404C096FC2621F701EEBFAA1DB047922A249D6D34B80C
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration_test.rs
assertion_line: 352
assertion_line: 358
expression: "&sha256_digest"
snapshot_kind: text
---
906049EA301E1E033E5AF4E12630B0A0C4BDD60D7F6F05741F0A10F3638214A6
DA8DCC36D8F284F7CB4882F32C6AB7BE34A9A59BDC18839109C9F10C737B0CEE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration_test.rs
assertion_line: 366
assertion_line: 358
expression: "&sha256_digest"
snapshot_kind: text
---
D651688B08263EA415C95AF1298D337088953CD260BFFC1AB287D75E2F467D2A
66EE65C5068E586279361987E7F3921F9159619827439946FE32A61C2A8B5C39