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
45 changes: 21 additions & 24 deletions Module/Build/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
[string] $FailOnDiagnosticsSeverity
)

if (-not $JsonOnly) {
Remove-Item -Path (Join-Path $PSScriptRoot '../Lib') -Recurse -Force -ErrorAction SilentlyContinue
}

$repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
$moduleRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$artefactsRoot = Join-Path $moduleRoot 'Artefacts'
Expand Down Expand Up @@ -55,32 +51,32 @@ if (-not $JsonOnly -and -not $NoDotnetBuild) {
# installed/imported module in the caller session can shadow the current source changes.
Get-Module -Name 'PSPublishModule' -All -ErrorAction SilentlyContinue | Remove-Module -Force -ErrorAction SilentlyContinue

$importPath = $null
# Clean the repo Lib payload only after unloading the module; otherwise Windows can keep
# stale PSPublishModule binaries locked and the delete silently fails.
if (-not $JsonOnly) {
Remove-Item -Path (Join-Path $PSScriptRoot '../Lib') -Recurse -Force -ErrorAction SilentlyContinue
}

# Json-only and no-dotnet-build flows should avoid importing the source manifest from Module\Lib.
# Once a PowerShell session loads those repo DLLs on Windows, later self-build attempts cannot
# refresh them in-place. Import the compiled binary module instead for config generation.
$preferBinaryImport = $JsonOnly -or $NoDotnetBuild
$importPath = $null

if ($preferBinaryImport) {
if (-not (Test-Path -LiteralPath $binaryModule)) {
if (Test-Path -LiteralPath $csproj) {
$i = [char]0x2139 # ℹ
Write-Host "$i Building PSPublishModule ($Configuration)" -ForegroundColor DarkGray
$buildOutput = & dotnet build $csproj -c $Configuration --nologo --verbosity quiet 2>&1
if ($LASTEXITCODE -ne 0) {
$buildOutput | Out-Host
throw "dotnet build failed (exit $LASTEXITCODE)."
}
# Prefer the freshly built binary module for all PSPublishModule self-builds. Falling back to
# the source manifest is only a last resort when the binary output is unavailable.
if (-not (Test-Path -LiteralPath $binaryModule)) {
if (Test-Path -LiteralPath $csproj) {
$i = [char]0x2139 # ℹ
Write-Host "$i Building PSPublishModule ($Configuration)" -ForegroundColor DarkGray
$buildOutput = & dotnet build $csproj -c $Configuration --nologo --verbosity quiet 2>&1
if ($LASTEXITCODE -ne 0) {
$buildOutput | Out-Host
throw "dotnet build failed (exit $LASTEXITCODE)."
}
}
}

if (Test-Path -LiteralPath $binaryModule) {
$importPath = $binaryModule
}
if (Test-Path -LiteralPath $binaryModule) {
$importPath = $binaryModule
} elseif (Test-Path -LiteralPath $sourceLibRoot) {
# Keep the source-manifest path for regular repo builds where Module\Lib is intentionally populated.
# Build-ModuleSelf now prefers binary import to avoid in-place refreshes of loaded repo DLLs.
Write-Warning "Falling back to source manifest import because the compiled PSPublishModule binary was not found: $binaryModule"
$importPath = $sourceManifest
} else {
if (-not (Test-Path -LiteralPath $binaryModule)) {
Expand All @@ -104,6 +100,7 @@ if (-not $importPath) {
throw "Invoke-ModuleBuild is not available. Ensure PSPublishModule.dll built and importable."
}

Write-Verbose "Importing PSPublishModule from '$importPath'."
Import-Module $importPath -Force

$invokeModuleBuildCommand = Get-Command Invoke-ModuleBuild -ErrorAction SilentlyContinue
Expand Down
2 changes: 1 addition & 1 deletion Module/Docs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: PSPublishModule
Module Guid: eb76426a-1992-40a5-82cd-6480f883ef4d
Download Help Link: https://github.com/EvotecIT/PSPublishModule
Help Version: 3.0.0
Help Version: 3.0.1
Locale: en-US
---
# PSPublishModule Module
Expand Down
29 changes: 15 additions & 14 deletions Module/PSPublishModule.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@
DotNetFrameworkVersion = '4.5.2'
FunctionsToExport = @()
GUID = 'eb76426a-1992-40a5-82cd-6480f883ef4d'
ModuleVersion = '3.0.0'
ModuleVersion = '3.0.1'
PowerShellVersion = '5.1'
PrivateData = @{
PSData = @{
IconUri = 'https://evotec.xyz/wp-content/uploads/2019/02/PSPublishModule.png'
ProjectUri = 'https://github.com/EvotecIT/PSPublishModule'
RequireLicenseAcceptance = $false
Tags = @('Windows', 'MacOS', 'Linux', 'Build', 'Module')
IconUri = 'https://evotec.xyz/wp-content/uploads/2019/02/PSPublishModule.png'
ProjectUri = 'https://github.com/EvotecIT/PSPublishModule'
RequireLicenseAcceptance = $false
Tags = @('Windows', 'MacOS', 'Linux', 'Build', 'Module')
ExternalModuleDependencies = @()
}
}
RequiredModules = @(@{
Guid = '1d73a601-4a6c-43c5-ba3f-619b18bbb404'
ModuleName = 'powershellget'
ModuleVersion = '2.2.5'
Guid = '1d73a601-4a6c-43c5-ba3f-619b18bbb404'
ModuleName = 'powershellget'
ModuleVersion = '2.2.5'
}, @{
Guid = 'd6245802-193d-4068-a631-8863a4342a18'
ModuleName = 'PSScriptAnalyzer'
ModuleVersion = '1.24.0'
Guid = 'd6245802-193d-4068-a631-8863a4342a18'
ModuleName = 'PSScriptAnalyzer'
ModuleVersion = '1.24.0'
}, @{
Guid = 'a699dea5-2c73-4616-a270-1f7abb777e71'
ModuleName = 'Pester'
ModuleVersion = '5.7.1'
Guid = 'a699dea5-2c73-4616-a270-1f7abb777e71'
ModuleName = 'Pester'
ModuleVersion = '5.7.1'
})
RootModule = 'PSPublishModule.psm1'
NestedModules = @()
Expand Down
36 changes: 34 additions & 2 deletions PowerForge.PowerShell/Services/ModuleBuildPreparationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public ModuleBuildPreparedContext Prepare(ModuleBuildPreparationRequest request)
: LegacySegmentAdapter.CollectFromSettings(request.Settings))
: Array.Empty<IConfigurationSegment>();

var baseVersion = ResolveBaseVersion(projectRoot, moduleName!);
var frameworks = useLegacy && !request.DotNetFrameworkWasBound
? Array.Empty<string>()
: request.DotNetFramework;
Expand All @@ -47,7 +46,7 @@ public ModuleBuildPreparedContext Prepare(ModuleBuildPreparationRequest request)
SourcePath = projectRoot,
StagingPath = request.StagingPath,
CsprojPath = request.CsprojPath,
Version = baseVersion,
Version = "1.0.0",
Configuration = request.DotNetConfiguration,
Frameworks = frameworks,
KeepStaging = request.KeepStaging,
Expand Down Expand Up @@ -76,6 +75,8 @@ public ModuleBuildPreparedContext Prepare(ModuleBuildPreparationRequest request)
Segments = segments
};

spec.Build.Version = ResolveBaseVersion(projectRoot, moduleName!, segments);

return new ModuleBuildPreparedContext
{
ModuleName = moduleName!,
Expand Down Expand Up @@ -110,6 +111,37 @@ public void WritePipelineSpecJson(ModulePipelineSpec spec, string jsonFullPath)
File.WriteAllText(jsonFullPath, json, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
}

private static string ResolveBaseVersion(string projectRoot, string moduleName, IReadOnlyList<IConfigurationSegment>? segments)
{
var configuredVersion = ResolveConfiguredVersion(segments);
if (!string.IsNullOrWhiteSpace(configuredVersion))
return configuredVersion!;

return ResolveBaseVersion(projectRoot, moduleName);
}

private static string? ResolveConfiguredVersion(IReadOnlyList<IConfigurationSegment>? segments)
{
if (segments is null || segments.Count == 0)
return null;

for (var index = segments.Count - 1; index >= 0; index--)
{
if (segments[index] is not ConfigurationManifestSegment manifest)
continue;

var moduleVersion = manifest.Configuration?.ModuleVersion;
if (!string.IsNullOrWhiteSpace(moduleVersion))
{
var trimmed = (moduleVersion ?? string.Empty).Trim();
if (!string.IsNullOrWhiteSpace(trimmed))
return trimmed;
}
}

return null;
}

private static string ResolveBaseVersion(string projectRoot, string moduleName)
{
var baseVersion = "1.0.0";
Expand Down
Loading
Loading