Skip to content

Commit

Permalink
Merge pull request #87 from theohbrothers/fix/fix-not-using-versions-…
Browse files Browse the repository at this point in the history
…from-version.json-before-opening-each-pr-in-update-dockerimagevariantsversions

Fix: Fix not using versions from `version.json` before opening each PR in `Update-DockerImageVariantsVersions`
  • Loading branch information
leojonathanoh authored Sep 21, 2023
2 parents b7db4d7 + 996b223 commit f639f35
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ function Update-DockerImageVariantsVersions {
}
$_pr = $null
$versionsConfig = Get-DockerImageVariantsVersions
foreach ($pkg in $versionsConfig.psobject.Properties.Name) {
$versions = $versionsConfig.$pkg.versions
$versionsNew = try {
Invoke-Command -ScriptBlock ([scriptblock]::Create($versionsConfig.$pkg.versionsNewScript))
}catch {
"Error in $pkg.versionsNewScript. Please review." | Write-Warning
throw
}
if ($null -eq $versionsNew) {
throw "$pkg.versionsNewScript returned null. It should return an array of versions (semver)."
foreach ($pkg in @( $versionsConfig.psobject.Properties.Name )) {
$versionsChanged = & {
$versions = $versionsConfig.$pkg.versions
$versionsNew = try {
Invoke-Command -ScriptBlock ([scriptblock]::Create($versionsConfig.$pkg.versionsNewScript))
}catch {
"Error in $pkg.versionsNewScript. Please review." | Write-Warning
throw
}
if ($null -eq $versionsNew) {
throw "$pkg.versionsNewScript returned null. It should return an array of versions (semver)."
}
Get-VersionsChanged -Versions $versions -VersionsNew $versionsNew -AsObject -Descending
}
$versionsChanged = Get-VersionsChanged -Versions $versions -VersionsNew $versionsNew -AsObject -Descending

$changedCount = ($versionsChanged.Values | ? { $_['kind'] -ne 'existing' } | Measure-Object).Count
if ($changedCount -eq 0) {
Expand All @@ -64,34 +66,33 @@ function Update-DockerImageVariantsVersions {
if ($PR) {
{ git checkout master } | Execute-Command | Write-Host
{ git pull origin master } | Execute-Command | Write-Host
$versionsConfig = Get-DockerImageVariantsVersions # Get the latest config
}

if ($vc['kind'] -eq 'new') {
if ($vc['to'] -notin $versions) {
if ($vc['to'] -notin $versionsConfig.$pkg.versions) {
"> New: $( $vc['to'] )" | Write-Host -ForegroundColor Green
$versionsUpdated = @(
$vc['to']
$versions
$versionsConfig.$pkg.versions
)
$versionsUpdated = $versionsUpdated | Select-Object -Unique | Sort-Object { [version]$_ } -Descending
$versionsConfig.$pkg.versions = $versionsUpdated
$versionsConfig.$pkg.versions = $versionsUpdated | Select-Object -Unique | Sort-Object { [version]$_ } -Descending
Set-DockerImageVariantsVersions -Versions $versionsConfig
if ($PR) {
$prs += $_pr = New-DockerImageVariantsPR -Package $pkg -Version $vc['to'] -Verb add -CommitPreScriptblock $CommitPreScriptblock
}
}
}elseif ($vc['kind'] -eq 'update') {
$versionsUpdated = [System.Collections.ArrayList]@()
foreach ($v in $versions) {
foreach ($v in $versionsConfig.$pkg.versions) {
if ($v -eq $vc['from']) {
"> Update: $( $vc['from'] ) to $( $vc['to'] )" | Write-Host -ForegroundColor Green
$versionsUpdated.Add($vc['to']) > $null
}else {
$versionsUpdated.Add($v) > $null
}
}
$versionsUpdated = $versionsUpdated | Select-Object -Unique | Sort-Object { [version]$_ } -Descending
$versionsConfig.$pkg.versions = $versionsUpdated
$versionsConfig.$pkg.versions = $versionsUpdated | Select-Object -Unique | Sort-Object { [version]$_ } -Descending
Set-DockerImageVariantsVersions -Versions $versionsConfig
if ($PR) {
$prs += $_pr = New-DockerImageVariantsPR -Package $pkg -Version $vc['from'] -VersionNew $vc['to'] -Verb update -CommitPreScriptblock $CommitPreScriptblock
Expand Down

0 comments on commit f639f35

Please sign in to comment.