|
| 1 | +function Save-ChocoPackage { |
| 2 | + param ( |
| 3 | + $PackageName |
| 4 | + ) |
| 5 | + Rename-Item -Path "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nupkg" -NewName "$PackageName.nupkg.zip" -ErrorAction:SilentlyContinue |
| 6 | + Expand-Archive -LiteralPath "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nupkg.zip" -DestinationPath "$env:ChocolateyInstall\lib\$PackageName" -Force |
| 7 | + Remove-Item "$env:ChocolateyInstall\lib\$PackageName\_rels" -Recurse |
| 8 | + Remove-Item "$env:ChocolateyInstall\lib\$PackageName\package" -Recurse |
| 9 | + Remove-Item "$env:ChocolateyInstall\lib\$PackageName\[Content_Types].xml" |
| 10 | + New-Item -Path "${PSScriptRoot}\..\tmp\chocolatey\$PackageName" -ItemType "directory" -ErrorAction:SilentlyContinue |
| 11 | + choco pack "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nuspec" --outdir "${PSScriptRoot}\..\tmp\chocolatey\$PackageName" |
| 12 | +} |
| 13 | + |
| 14 | +# Check for existence of required environment variables |
| 15 | +if ( $null -eq $env:ChocolateyInstall ) { |
| 16 | + [Console]::Error.WriteLine('Missing $env:ChocolateyInstall environment variable') |
| 17 | + exit 1 |
| 18 | +} |
| 19 | + |
| 20 | +# Add the cached packages with source priority 1 (Chocolatey community is 0) |
| 21 | +New-Item -Path "${PSScriptRoot}\..\tmp\chocolatey" -ItemType "directory" -ErrorAction:SilentlyContinue |
| 22 | +choco source add --name="cache" --source="${PSScriptRoot}\..\tmp\chocolatey" --priority=1 |
| 23 | + |
| 24 | +# Install nodejs v16.15.1 (will use cache if exists) |
| 25 | +$nodejs = "nodejs.install" |
| 26 | +choco install "$nodejs" --version="16.15.1" --require-checksums -y |
| 27 | +# Internalise nodejs to cache if doesn't exist |
| 28 | +if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$nodejs\$nodejs.16.15.1.nupkg" -PathType Leaf) ) { |
| 29 | + Save-ChocoPackage -PackageName $nodejs |
| 30 | +} |
| 31 | + |
| 32 | +# Install python v3.9.12 (will use cache if exists) |
| 33 | +$python = "python3" |
| 34 | +choco install $python --version="3.9.12" --require-checksums -y |
| 35 | +# Internalise python to cache if doesn't exist |
| 36 | +if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$python\$python.3.9.12.nupkg" -PathType Leaf) ) { |
| 37 | + Save-ChocoPackage -PackageName $python |
| 38 | +} |
0 commit comments