Skip to content
Draft
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
58 changes: 56 additions & 2 deletions ci/packages.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,28 @@ Source = "https://github.com/51Degrees/51degrees-python"
}

Describe 'Get-BuildPlan' {
It 'is the release plan when a package is to be released' {
It 'is the release plan and every other package at its released version' {
$script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0')
Add-Commit $script:Repo @('pipeline/engines/a.py')
@(Get-ReleasePlan $script:Repo $script:Graph).Name |
Should -Be @('engines', 'dd', 'ipi')
$plan = @(Get-BuildPlan $script:Repo $script:Graph)
$plan.Name | Should -Be @('engines', 'dd', 'ipi')
$plan.Name | Should -Be @('core', 'did', 'engines', 'location', 'dd', 'ipi')
($plan | Where-Object Name -eq 'engines').Version | Should -Be '4.5.39'
($plan | Where-Object Name -eq 'core').Version | Should -Be '4.5.38'
($plan | Where-Object Name -eq 'core').Reason |
Should -Be 'already released, built for the tests'
($plan | Where-Object Name -eq 'location').Version | Should -Be '4.5.4'
}

It 'builds every package when only one is to be released' {
$script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0')
Add-Commit $script:Repo @('location/a.py')
@(Get-ReleasePlan $script:Repo $script:Graph).Name | Should -Be @('location')
$plan = @(Get-BuildPlan $script:Repo $script:Graph)
$plan.Count | Should -Be 6
($plan | Where-Object Name -eq 'location').Version | Should -Be '4.5.5'
($plan | Where-Object Name -eq 'dd').Version | Should -Be '4.5.96'
}

It 'builds every published package at its released version when nothing changed' {
Expand All @@ -346,6 +362,44 @@ Describe 'Get-BuildPlan' {
}
}

Describe 'Get-UnplannedDistributions' {
BeforeAll {
$script:Dir = Join-Path $TestDrive 'package'
New-Item -ItemType Directory -Path $script:Dir -Force | Out-Null
@(
'fiftyone_pipeline_did-4.6.3.tar.gz',
'fiftyone_pipeline_did-4.6.3-py3-none-any.whl',
'fiftyone_pipeline_core-4.6.2.tar.gz',
'fiftyone_pipeline_core-4.6.2-py3-none-any.whl',
'fiftyone_pipeline_did-4.6.2.tar.gz',
'fiftyone_pipeline_did_extra-4.6.3.tar.gz',
'fiftyone_pipeline_did-4.6.30.tar.gz',
'fiftyone_pipeline_did-4.6.3-1-py3-none-any.whl',
'pre-publish-requirements.txt',
'fiftyone_devicedetection-4.6.3.tar.gz'
) | ForEach-Object { New-Item -ItemType File -Path (Join-Path $script:Dir $_) | Out-Null }
}

It 'gives every file that is not a planned package at its planned version' {
$plan = @(
[pscustomobject]@{ Name = 'fiftyone_pipeline_did'; Version = '4.6.3' },
[pscustomobject]@{ Name = 'fiftyone-devicedetection'; Version = '4.6.3' }
)
@(Get-UnplannedDistributions $script:Dir $plan).Name | Sort-Object |
Should -Be (@(
'fiftyone_pipeline_core-4.6.2-py3-none-any.whl',
'fiftyone_pipeline_core-4.6.2.tar.gz',
'fiftyone_pipeline_did-4.6.2.tar.gz',
'fiftyone_pipeline_did-4.6.30.tar.gz',
'fiftyone_pipeline_did_extra-4.6.3.tar.gz',
'pre-publish-requirements.txt') | Sort-Object)
}

It 'gives every file when nothing is planned' {
@(Get-UnplannedDistributions $script:Dir @()).Count | Should -Be 10
}
}

Describe 'the real packages.json' {
BeforeAll {
$script:Real = Get-Packages (Split-Path $PSScriptRoot)
Expand Down
35 changes: 28 additions & 7 deletions ci/packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,24 @@ function Get-AffectedProducts([string]$RepoPath, [string]$Branch = 'main') {
return Resolve-AffectedProducts $packages $changed
}

# What a build of HEAD makes: the release plan, or, when nothing changed since
# the last release, every published package at its released version. Nothing
# is published then, because package-update-required.ps1 finds the release
# plan empty, but the publish's tests still have the packages to install.
# What a build of HEAD makes: the release plan, and every other published
# package at its released version. The integration tests install every
# package from the build, whichever product they test, so a package left out
# would leave its own tests nothing to import. When the release plan is empty
# nothing is published, because package-update-required.ps1 finds it empty,
# and when it isn't, publish-package.ps1 uploads only the packages it plans.
function Get-BuildPlan([string]$RepoPath, $Packages = $null) {
if ($null -eq $Packages) {
$Packages = Get-Packages $RepoPath
}
$plan = @(Get-ReleasePlan $RepoPath $Packages)
if ($plan.Count -gt 0) {
return $plan
}
$published = @($Packages | Where-Object { $_.Publish -eq $true })
foreach ($name in (Sort-ByDependency $published @($published.Name))) {
$release = $plan | Where-Object { $_.Name -eq $name }
if ($null -ne $release) {
$release
continue
}
$package = $published | Where-Object { $_.Name -eq $name }
$last = @(Get-ReleasedVersions $RepoPath $name)[-1]
[pscustomobject]@{
Expand All @@ -152,3 +156,20 @@ function Get-BuildPlan([string]$RepoPath, $Packages = $null) {
}
}
}

# The files in $PackageDir that aren't a distribution of a package in $Plan
# at its planned version. The build makes every package, so that the tests
# have them all, and these are the ones not to upload. A distribution's file
# name starts with the package name, with - . and _ written as _, then a -
# and the version.
function Get-UnplannedDistributions([string]$PackageDir, $Plan) {
$planned = @($Plan | ForEach-Object {
(($_.Name -replace '[-_.]+', '_').ToLowerInvariant()) + '-' + $_.Version
})
Get-ChildItem -Path $PackageDir -File | Where-Object {
$file = $_.Name.ToLowerInvariant()
-not ($planned | Where-Object {
$file.StartsWith("$_.") -or $file.StartsWith("$_-")
})
}
}
10 changes: 10 additions & 0 deletions ci/publish-package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ $PSNativeCommandUseErrorActionPreference = $true
# change what the plan would say.
$plan = @(Get-ReleasePlan $RepoName)

# The build makes every package, at its released version where it isn't
# planned, so that the tests have them all. Only the planned ones go up. With
# no plan, which happens only if another run released HEAD first, every file
# is a released version, which --skip-existing skips, as before.
$unplanned = $plan.Count -gt 0 ? @(Get-UnplannedDistributions 'package' $plan) : @()
foreach ($file in $unplanned) {
Write-Output "Not uploading $($file.Name), built only for the tests"
Remove-Item $file.FullName
}

./python/publish-package-pypi.ps1 -DryRun $DryRun

# One tag and one GitHub release per package, '<package>/<version>', in place
Expand Down
Loading