Skip to content
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
22 changes: 14 additions & 8 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ repositories used to do for one package tree each.
publish, the two on-premise engines that build a native library, and the
generated accessors. The other scripts loop over it rather than naming
folders themselves.
- [packages.json](packages.json) lists every published module as a package,
named by its artifactId, with its folder, the other folders its build takes
files from, and the packages it depends on, its parent included. A parent's
folder is its `pom.xml` alone, because the rest of the folder is its
modules. [build-project.ps1](build-project.ps1) fails a pull request whose
poms refer to a package that `DependsOn` does not name, or add a module
that has no entry.
- [packages.json](packages.json) lists every module of the published trees,
named by its artifactId, with its folder. Each published module is a
package, with the other folders its build takes files from and the packages
it depends on, its parent included. The example modules inside the
published trees have `Publish` false, so they are never released. A
parent's folder is its `pom.xml` alone, because the rest of the folder is
its modules. [build-project.ps1](build-project.ps1) fails a pull request
whose poms refer to a package that `DependsOn` does not name, whose
published poms refer to an unpublished module, or that adds a module with
no entry. Its Pester 5 tests are [packages.Tests.ps1](packages.Tests.ps1).
- The root `pom.xml` builds every tree in one reactor but is not their parent.
[build-package.ps1](build-package.ps1) writes each published module's own
version into its `pom.xml`, with the versions of its parent and of the
packages it depends on, and deploys only the modules being released. The
examples are built and tested but left out of the deploy.
examples are built and tested but left out of the deploy. The example
modules inside the published trees take the versions of the published
packages they refer to and keep their own, so the reactor still finds every
parent.
- [build-project.ps1](build-project.ps1) and
[run-unit-tests.ps1](run-unit-tests.ps1) use the `dev` profile, so a pull
request tests the examples against the libraries it changes. The publish
Expand Down
151 changes: 151 additions & 0 deletions ci/packages.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Pester 5 tests of the packages.json check in packages.ps1 and of
# Set-PomVersions in release.ps1, on a small published tree that holds an
# unpublished examples module, and of the check on this repository.

BeforeAll {
# release.ps1 finds common-ci's release plan two folders up, so the
# scripts are copied into a folder laid out that way, with a stub plan.
$Root = Join-Path ([IO.Path]::GetTempPath()) "packages-$PID"
$null = New-Item -ItemType Directory -Force (Join-Path $Root 'steps')
Copy-Item -Recurse $PSScriptRoot (Join-Path $Root 'scripts' 'ci')
Set-Content (Join-Path $Root 'steps' 'release-plan.ps1') `
'function Get-ReleasePlan([string]$RepoPath) { }'
. (Join-Path $Root 'scripts' 'ci' 'release.ps1')

$Development = '1.0.0-SNAPSHOT'

function New-Pom([string]$ArtifactId, [string]$Parent, [string[]]$Modules,
[string[]]$Dependencies) {
$lines = @(
'<?xml version="1.0" encoding="UTF-8"?>'
'<project xmlns="http://maven.apache.org/POM/4.0.0">'
' <modelVersion>4.0.0</modelVersion>')
if ($Parent) {
$lines += @(
' <parent>'
' <groupId>com.51degrees</groupId>'
" <artifactId>$Parent</artifactId>"
" <version>$Development</version>"
' </parent>')
} else {
$lines += ' <groupId>com.51degrees</groupId>'
}
$lines += " <artifactId>$ArtifactId</artifactId>"
if (-not $Parent) {
$lines += " <version>$Development</version>"
}
if ($Modules) {
$lines += ' <packaging>pom</packaging>'
$lines += ' <modules>'
$lines += @($Modules | ForEach-Object { " <module>$_</module>" })
$lines += ' </modules>'
}
if ($Dependencies) {
$lines += ' <dependencies>'
foreach ($dependency in $Dependencies) {
$lines += @(
' <dependency>'
' <groupId>com.51degrees</groupId>'
" <artifactId>$dependency</artifactId>"
' <version>${project.version}</version>'
' </dependency>')
}
$lines += ' </dependencies>'
}
$lines += '</project>'
return $lines -join "`n"
}

# A published tree with a published library, and an unpublished examples
# parent whose example uses the library. $LibraryUses makes the library
# refer to another module, and $Leave drops an entry from packages.json.
function New-Repo([string]$LibraryUses, [string]$Leave) {
$repo = Join-Path $TestDrive ([Guid]::NewGuid().ToString('N'))
$poms = [ordered]@{
'tree/pom.xml' = New-Pom 'tree' -Modules 'lib', 'examples'
'tree/lib/pom.xml' = New-Pom 'lib' 'tree' -Dependencies $LibraryUses
'tree/examples/pom.xml' = New-Pom 'examples' 'tree' -Modules 'example'
'tree/examples/example/pom.xml' = New-Pom 'example' 'examples' -Dependencies 'lib'
}
foreach ($path in $poms.Keys) {
$file = Join-Path $repo $path
$null = New-Item -ItemType Directory -Force (Split-Path $file)
Set-Content -LiteralPath $file -Value $poms[$path] -NoNewline
}
$libraryDependsOn = @('tree') + @($LibraryUses | Where-Object { $_ })
$entries = @(
[ordered]@{ Name = 'tree'; Path = 'tree/pom.xml'; DependsOn = @(); Publish = $true }
[ordered]@{ Name = 'lib'; Path = 'tree/lib'; DependsOn = $libraryDependsOn; Publish = $true }
[ordered]@{ Name = 'examples'; Path = 'tree/examples/pom.xml'; Publish = $false }
[ordered]@{ Name = 'example'; Path = 'tree/examples/example'; Publish = $false }
) | Where-Object { $_.Name -ne $Leave }
$null = New-Item -ItemType Directory -Force (Join-Path $repo 'ci')
ConvertTo-Json -InputObject @($entries) -Depth 4 |
Set-Content (Join-Path $repo 'ci' 'packages.json')
return $repo
}

function Get-Version([string]$Repo, [string]$Path, [string]$XPath) {
$pom = Read-Pom (Join-Path $Repo $Path)
return $pom.Xml.SelectSingleNode($XPath, $pom.Ns).InnerText
}

$RealTrees = $Trees
$Trees = @(@{ Path = 'tree'; Publish = $true })
}

AfterAll {
Remove-Item -Recurse -Force $Root
}

Describe 'Get-PackagesJsonGaps' {
It 'accepts unpublished modules in a published tree' {
Get-PackagesJsonGaps (New-Repo) | Should -BeNullOrEmpty
}

It 'names a published module that refers to an unpublished one' {
$gaps = @(Get-PackagesJsonGaps (New-Repo -LibraryUses 'example'))
$gaps | Should -Be @(
'tree/lib/pom.xml refers to example, which ci/packages.json does not publish')
}

It 'names a module of a published tree with no entry' {
$gaps = @(Get-PackagesJsonGaps (New-Repo -Leave 'example'))
$gaps | Should -Be @(
'tree/examples/example/pom.xml is a module of a published tree with no entry in ci/packages.json')
}

It 'finds nothing missing in this repository, whose examples are not published' {
$Trees = $RealTrees
$repo = Join-Path $PSScriptRoot '..'
Get-PackagesJsonGaps $repo | Should -BeNullOrEmpty
$examples = @(Get-PackageEntries $repo | Where-Object { $_.Path -match 'example' })
$examples.Count | Should -BeGreaterThan 0
$examples | Where-Object { $_.Publish -eq $true } | Should -BeNullOrEmpty
}
}

Describe 'Set-PomVersions' {
BeforeAll {
$repo = New-Repo
Set-PomVersions $repo @{ tree = '4.6.2'; lib = '4.6.2' }
}

It 'gives each published module its version and its parent''s' {
Get-Version $repo 'tree/pom.xml' '/m:project/m:version' | Should -Be '4.6.2'
Get-Version $repo 'tree/lib/pom.xml' '/m:project/m:version' | Should -Be '4.6.2'
Get-Version $repo 'tree/lib/pom.xml' '/m:project/m:parent/m:version' | Should -Be '4.6.2'
}

It 'gives an unpublished module its published parent''s version and keeps its own' {
Get-Version $repo 'tree/examples/pom.xml' '/m:project/m:parent/m:version' | Should -Be '4.6.2'
Get-Version $repo 'tree/examples/pom.xml' '/m:project/m:version' | Should -Be $Development
}

It 'leaves an unpublished parent''s version for its modules, and gives them the published versions they use' {
$path = 'tree/examples/example/pom.xml'
Get-Version $repo $path '/m:project/m:parent/m:version' | Should -Be $Development
Get-Version $repo $path '/m:project/m:version' | Should -Be $Development
Get-Version $repo $path '//m:dependency/m:version' | Should -Be '4.6.2'
}
}
30 changes: 15 additions & 15 deletions ci/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
{"Name": "pipeline.web", "Path": "pipeline/pipeline.web.packages/pipeline.web", "DependsOn": ["pipeline.web.packages", "pipeline.web.shared", "pipeline.core"], "Publish": true},
{"Name": "pipeline.web.mvc", "Path": "pipeline/pipeline.web.packages/pipeline.web.mvc", "DependsOn": ["pipeline.web.packages", "pipeline.web", "pipeline.core"], "Publish": true},
{"Name": "pipeline-aggregate", "Path": "pipeline/pipeline.aggregate", "DependsOn": ["pipeline", "pipeline.web", "pipeline.javascriptbuilder", "pipeline.cloudrequestengine"], "Publish": true},
{"Name": "pipeline.developer-examples", "Path": "pipeline/pipeline.developer-examples/pom.xml", "DependsOn": ["pipeline"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.web.shared", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.web.shared", "DependsOn": ["pipeline.developer-examples"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.flowelement", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement", "DependsOn": ["pipeline.developer-examples", "pipeline.core"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.onpremiseengine", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine", "DependsOn": ["pipeline.developer-examples", "pipeline.engines"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.cloudengine", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine", "DependsOn": ["pipeline.developer-examples", "pipeline.cloudrequestengine"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.clientsideelement", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.clientside-element", "DependsOn": ["pipeline.developer-examples", "pipeline.engines"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.clientsideelement.mvc", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.clientside-element-mvc", "DependsOn": ["pipeline.developer-examples", "pipeline.developerexamples.clientsideelement", "pipeline.web.mvc", "pipeline.developerexamples.web.shared"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.usagesharing", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing", "DependsOn": ["pipeline.developer-examples", "pipeline.engines.fiftyone"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.fodid", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid", "DependsOn": ["pipeline.developer-examples", "pipeline.did"], "Publish": true, "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developerexamples.derivedproperty", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.derivedproperty", "DependsOn": ["pipeline.developer-examples", "pipeline.derivedproperty"], "Publish": true, "FirstVersion": "4.6.2", "Ignore": ["pipeline/pipeline.developer-examples/**"]},
{"Name": "pipeline.developer-examples", "Path": "pipeline/pipeline.developer-examples/pom.xml", "Publish": false},
{"Name": "pipeline.developerexamples.web.shared", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.web.shared", "Publish": false},
{"Name": "pipeline.developerexamples.flowelement", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.flowelement", "Publish": false},
{"Name": "pipeline.developerexamples.onpremiseengine", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.onpremise-engine", "Publish": false},
{"Name": "pipeline.developerexamples.cloudengine", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.cloud-engine", "Publish": false},
{"Name": "pipeline.developerexamples.clientsideelement", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.clientside-element", "Publish": false},
{"Name": "pipeline.developerexamples.clientsideelement.mvc", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.clientside-element-mvc", "Publish": false},
{"Name": "pipeline.developerexamples.usagesharing", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.usage-sharing", "Publish": false},
{"Name": "pipeline.developerexamples.fodid", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.fodid", "Publish": false},
{"Name": "pipeline.developerexamples.derivedproperty", "Path": "pipeline/pipeline.developer-examples/pipeline.developer-examples.derivedproperty", "Publish": false},
{"Name": "pipeline.device-detection", "Path": "device-detection/pom.xml", "DependsOn": ["pipeline-aggregate"], "Publish": true},
{"Name": "device-detection.shared", "Path": "device-detection/device-detection.shared", "DependsOn": ["pipeline.device-detection", "pipeline.engines.fiftyone"], "Publish": true},
{"Name": "device-detection.hash.engine.on-premise", "Path": "device-detection/device-detection.hash.engine.on-premise", "ExtraPaths": ["cxx"], "DependsOn": ["pipeline.device-detection", "device-detection.shared"], "Publish": true},
Expand All @@ -41,9 +41,9 @@
{"Name": "geo-location.core", "Path": "location/geo-location.core", "DependsOn": ["pipeline.geo-location", "pipeline.cloudrequestengine"], "Publish": true},
{"Name": "geo-location.cloud", "Path": "location/geo-location.cloud", "DependsOn": ["pipeline.geo-location", "geo-location.core", "pipeline.cloudrequestengine", "pipeline.engines.fiftyone"], "Publish": true},
{"Name": "geo-location", "Path": "location/geo-location", "DependsOn": ["pipeline.geo-location", "geo-location.cloud", "pipeline.cloudrequestengine", "pipeline.common"], "Publish": true},
{"Name": "geo-location.examples", "Path": "location/geo-location.shell.examples", "DependsOn": ["pipeline.geo-location", "geo-location", "device-detection", "pipeline.engines"], "Publish": true, "Ignore": ["location/geo-location.shell.examples/**"]},
{"Name": "geo-location.web.examples", "Path": "location/geo-location.web.examples/pom.xml", "DependsOn": ["pipeline.geo-location"], "Publish": true, "Ignore": ["location/geo-location.web.examples/**"]},
{"Name": "geo-location.web.examples.mvc", "Path": "location/geo-location.web.examples/geo-location.web.examples.mvc", "DependsOn": ["geo-location.web.examples", "pipeline.web.mvc", "geo-location.cloud", "geo-location.web.examples.shared"], "Publish": true, "Ignore": ["location/geo-location.web.examples/**"]},
{"Name": "geo-location.web.examples.servlet", "Path": "location/geo-location.web.examples/geo-location.web.examples.servlet", "DependsOn": ["geo-location.web.examples", "pipeline.web", "geo-location.cloud", "geo-location.web.examples.shared"], "Publish": true, "Ignore": ["location/geo-location.web.examples/**"]},
{"Name": "geo-location.web.examples.shared", "Path": "location/geo-location.web.examples/geo-location.web.examples.shared", "DependsOn": ["geo-location.web.examples"], "Publish": true, "Ignore": ["location/geo-location.web.examples/**"]}
{"Name": "geo-location.examples", "Path": "location/geo-location.shell.examples", "Publish": false},
{"Name": "geo-location.web.examples", "Path": "location/geo-location.web.examples/pom.xml", "Publish": false},
{"Name": "geo-location.web.examples.mvc", "Path": "location/geo-location.web.examples/geo-location.web.examples.mvc", "Publish": false},
{"Name": "geo-location.web.examples.servlet", "Path": "location/geo-location.web.examples/geo-location.web.examples.servlet", "Publish": false},
{"Name": "geo-location.web.examples.shared", "Path": "location/geo-location.web.examples/geo-location.web.examples.shared", "Publish": false}
]
Loading
Loading