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

(fix) Enable Sources before Pushing #288

Merged
merged 1 commit into from
Jan 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,28 @@
powershell '''
$temp = Join-Path -Path $env:TEMP -ChildPath ([GUID]::NewGuid()).Guid
$null = New-Item -Path $temp -ItemType Directory
$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
$_.Uri -eq $env:P_DST_URL
}[0]

Write-Output "Created temporary directory '$temp'."
($env:P_PKG_LIST).split(';,') | ForEach-Object {
choco download $_ --no-progress --internalize --force --internalize-all-urls --append-use-original-location --output-directory=$temp --source='https://community.chocolatey.org/api/v2/'
if ($LASTEXITCODE -eq 0) {
(Get-Item -Path (Join-Path -Path $temp -ChildPath "*.nupkg")).fullname | ForEach-Object {
choco push $_ --source "$($env:P_DST_URL)" --api-key "$($env:P_API_KEY)" --force
if ($LASTEXITCODE -eq 0) {
Write-Verbose "Package '$_' pushed to '$($env:P_DST_URL)'.";
}
else {
Write-Verbose "Package '$_' could not be pushed to '$($env:P_DST_URL)'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
}
}
try {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
(Get-Item -Path (Join-Path -Path $temp -ChildPath "*.nupkg")).fullname | ForEach-Object {
choco push $_ --source "$($env:P_DST_URL)" --api-key "$($env:P_API_KEY)" --force
if ($LASTEXITCODE -eq 0) {
Write-Verbose "Package '$_' pushed to '$($env:P_DST_URL)'.";
}
else {
Write-Verbose "Package '$_' could not be pushed to '$($env:P_DST_URL)'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
}
}
} finally {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
}
}
else {
Write-Output "Failed to download package '$_'"
Expand Down
27 changes: 19 additions & 8 deletions jenkins/scripts/Get-UpdatedPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ if (([version] (choco --version).Split('-')[0]) -ge [version] '2.1.0') {
choco cache remove
}

$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
$_.Uri -eq $LocalRepo -or
$_.Name -eq $LocalRepo
}[0]

Write-Verbose "Getting list of local packages from '$LocalRepo'."
$localPkgs = choco search --source $LocalRepo -r | ConvertTo-ChocoObject
Write-Verbose "Retrieved list of $(($localPkgs).count) packages from '$Localrepo'."
Expand All @@ -34,15 +39,21 @@ $localPkgs | ForEach-Object {
choco download $_.name --no-progress --internalize --force --internalize-all-urls --append-use-original-location --output-directory=$tempPath --source=$RemoteRepo

if ($LASTEXITCODE -eq 0) {
Write-Verbose "Pushing package '$($_.name)' to local repository '$LocalRepo'."
(Get-Item -Path (Join-Path -Path $tempPath -ChildPath "*.nupkg")).fullname | ForEach-Object {
choco push $_ --source $LocalRepo --api-key $LocalRepoApiKey --force
if ($LASTEXITCODE -eq 0) {
Write-Verbose "Package '$_' pushed to '$LocalRepo'."
}
else {
Write-Verbose "Package '$_' could not be pushed to '$LocalRepo'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
try {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}

Write-Verbose "Pushing package '$($_.name)' to local repository '$LocalRepo'."
(Get-Item -Path (Join-Path -Path $tempPath -ChildPath "*.nupkg")).fullname | ForEach-Object {
choco push $_ --source $LocalRepo --api-key $LocalRepoApiKey --force
if ($LASTEXITCODE -eq 0) {
Write-Verbose "Package '$_' pushed to '$LocalRepo'."
}
else {
Write-Verbose "Package '$_' could not be pushed to '$LocalRepo'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
}
}
} finally {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
}
}
else {
Expand Down
16 changes: 13 additions & 3 deletions jenkins/scripts/Invoke-ChocolateyInternalizer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ begin {
Join-Path -ChildPath $Guid |
New-Item -ItemType Directory -Path { $_ } |
Select-Object -ExpandProperty FullName

$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
$_.Uri -eq $RepositoryUrl
}[0]
}
process {
foreach ($item in $Package) {
choco download $item --internalize --output-directory="'$TempFolder'" --no-progress --internalize-all-urls --append-use-original-location --source="'$RemoteRepo'"
Get-ChildItem -Path $TempFolder -Filter *.nupkg -Recurse -File | ForEach-Object {
choco push $_.Fullname --source="'$RepositoryUrl'" --api-key="'$NexusApiKey'" --force
Remove-Item -Path $_.FullName -Force
try {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}

Get-ChildItem -Path $TempFolder -Filter *.nupkg -Recurse -File | ForEach-Object {
choco push $_.Fullname --source="'$RepositoryUrl'" --api-key="'$NexusApiKey'" --force
Remove-Item -Path $_.FullName -Force
}
} finally {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions jenkins/scripts/Update-ProdRepoFromTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ if (([version] (choco --version).Split('-')[0]) -ge [version] '2.1.0') {
choco cache remove
}

$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
$_.Uri -eq $TestRepo -or
$_.Name -eq $TestRepo
}[0]

Write-Verbose "Checking the list of packages available in the test and prod repositories"
$testPkgs = choco search --source $TestRepo --all-versions --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Version
try {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
$testPkgs = choco search --source $TestRepo --all-versions --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Version
} finally {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
}
$prodPkgs = choco search --source $ProdRepo --all-versions --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Version
$tempPath = Join-Path -Path $env:TEMP -ChildPath ([GUID]::NewGuid()).GUID

Expand All @@ -35,7 +45,12 @@ else {

$Packages | ForEach-Object {
Write-Verbose "Downloading package '$($_.Name)' v$($_.Version) to '$tempPath'."
choco download $_.Name --version $_.Version --no-progress --output-directory=$tempPath --source=$TestRepo --ignore-dependencies
try {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
choco download $_.Name --version $_.Version --no-progress --output-directory=$tempPath --source=$TestRepo --ignore-dependencies
} finally {
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
}

if ($LASTEXITCODE -eq 0) {
$pkgPath = (Get-Item -Path (Join-Path -Path $tempPath -ChildPath '*.nupkg')).FullName
Expand Down
Loading