-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Package Powershell module during build * Verify that all Cmdlets are exposed in the manifest as part of the build * Use common MSBuild properties and complete package metadata
- Loading branch information
1 parent
35217b1
commit 5f7e2a0
Showing
18 changed files
with
235 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#Requires -Version 7.4 | ||
<# | ||
.SYNOPSIS | ||
Remove the Powershell module from the build output. | ||
.DESCRIPTION | ||
This script removes the Powershell module from the build output. | ||
It is intended to be called by MSBuild during the normal clean process. | ||
The script might be called once for each target framework. | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter()] | ||
[string] | ||
[ValidateNotNullOrEmpty()] | ||
$OutputDirectory | ||
) | ||
|
||
$PSNativeCommandUseErrorActionPreference = $true | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$modulePath = Join-Path $OutputDirectory "PsModule" | ||
|
||
if (Test-Path $modulePath) { | ||
# This script might be called in parallel for each target framework. | ||
# Hence, we ignore errors as files might have been removed by another instance. | ||
Remove-Item -Path $modulePath -Force -Recurse -ErrorAction SilentlyContinue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#Requires -Version 7.4 | ||
<# | ||
.SYNOPSIS | ||
Package the Powershell module. | ||
.DESCRIPTION | ||
This script packages the Powershell module for distribution. | ||
It is intended to be called by MSBuild during the normal build | ||
process. The script will be called once for each target framework. | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match '[a-zA-Z\.]+' }, ErrorMessage = "The module name '{0}' is invalid.")] | ||
$ModuleName, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")] | ||
$TargetPath, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match 'net\d+\.?\d+' }, ErrorMessage = "The target framework '{0}' is invalid.")] | ||
$TargetFramework, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")] | ||
$OutputDirectory, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match '\d+\.\d+\.\d+' }, ErrorMessage = "The version '{0}' is invalid.")] | ||
$MajorMinorPatch, | ||
[Parameter()] | ||
[string] | ||
$NuGetPreReleaseTag | ||
) | ||
|
||
$PSNativeCommandUseErrorActionPreference = $true | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$excludedFiles = @("System.Management.Automation.dll", "JetBrains.Annotations.dll") | ||
|
||
$modulePath = Join-Path $OutputDirectory "PsModule" $ModuleName | ||
$isWindowsPowershell = $TargetFramework -like 'net4*' | ||
$moduleAssemblyPath = Join-Path $modulePath ($isWindowsPowershell ? 'desktop' : 'coreclr') | ||
|
||
# Prepare the output directory | ||
if (-not (Test-Path $modulePath)) { | ||
$null = New-Item -ItemType Directory -Path $modulePath | ||
} | ||
|
||
# Copy the build output | ||
if (Test-Path $moduleAssemblyPath) { | ||
Remove-Item -Path $moduleAssemblyPath -Force -Recurse | ||
} | ||
$null = New-Item -ItemType Directory -Path $moduleAssemblyPath | ||
$targetDirectory = (Get-Item $TargetPath).Directory.FullName | ||
Copy-Item -Path (Join-Path $targetDirectory "*") -Destination $moduleAssemblyPath -Exclude $excludedFiles -Recurse | ||
|
||
# Prepare the module manifest | ||
$config = Get-Content (Join-Path $PSScriptRoot "$ModuleName.psd1") -Raw | ||
$config = $config.Replace("ModuleVersion = '0.1'", "ModuleVersion = '$MajorMinorPatch'"); | ||
if (-not [string]::IsNullOrWhiteSpace($NuGetPreReleaseTag)) { | ||
$config = $config.Replace("# Prerelease = ''", "Prerelease = '$NuGetPreReleaseTag'"); | ||
} | ||
Set-Content -Path (Join-Path $modulePath "$ModuleName.psd1") -Value $config | ||
Copy-Item -Path (Join-Path $PSScriptRoot "$ModuleName.psm1") -Destination $modulePath | ||
|
||
# Verify that all Cmdlets are exposed in the manifest. We must load the modules | ||
# in separate Powershell processes to avoid conflicts. | ||
$powershell = $isWindowsPowershell ? 'powershell.exe' : 'pwsh.exe' | ||
$moduleCmdlets = (& $powershell -Command "[array](Import-Module -Scope Local $modulePath -PassThru).ExportedCmdlets.Keys -join ','") -split ',' | ||
$assemblyCmdlets = (& $powershell -Command "[array](Import-Module -Scope Local $TargetPath -PassThru).ExportedCmdlets.Keys -join ','") -split ',' | ||
$missingCmdlets = [Linq.Enumerable]::Except($assemblyCmdlets, $moduleCmdlets) | ||
if ($missingCmdlets.Count -gt 0) { | ||
throw "The following Cmdlets are not exposed in the module manifest: $($missingCmdlets -join ', ')" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,35 @@ | ||
param ($Configuration = "Debug", $OutputDir = ".") | ||
|
||
$cmdletName = "Eryph.ComputeClient" | ||
$excludedFiles = @("System.Management.Automation.dll", "JetBrains.Annotations.dll") | ||
|
||
# If this script is not running on a build server, remind user to | ||
# set environment variables so that this script can be debugged | ||
if(-not ($Env:GITVERSION_MajorMinorPatch)) | ||
{ | ||
Write-Error "You must set the following environment variables" | ||
Write-Error "to test this script interactively (values are examples)" | ||
Write-Host '$Env:GITVERSION_MajorMinorPatch = "1.0.0"' | ||
Write-Host '$Env:GITVERSION_NuGetPreReleaseTag = "ci0030"' | ||
exit 1 | ||
} | ||
|
||
|
||
Push-Location $PSScriptRoot | ||
cd .. | ||
$rootDir = Get-Location | ||
|
||
Push-Location $OutputDir | ||
|
||
if(Test-Path cmdlet ) { | ||
rm cmdlet -Force -Recurse -ErrorAction Stop | ||
#Requires -Version 7.4 | ||
<# | ||
.SYNOPSIS | ||
Prepare the Powershell module for publication. | ||
.DESCRIPTION | ||
This script moves the already built Powershell module to a location | ||
where the release pipeline will pick it up for publication. | ||
The name and output location of this script cannot be changed as | ||
it would break the release pipeline. | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter()] | ||
[string] | ||
[ValidateNotNullOrEmpty()] | ||
$Configuration, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")] | ||
$OutputDir | ||
) | ||
|
||
$ErrorActionPreference = 'Stop' | ||
$moduleName = "Eryph.ComputeClient" | ||
|
||
$repositoryPath = Resolve-Path (Join-Path $PSScriptRoot "..") | ||
$targetPath = Join-Path $OutputDir "cmdlet" | ||
|
||
if (Test-Path $targetPath ) { | ||
Remove-Item $targetPath -Force -Recurse | ||
} | ||
$null = New-Item -ItemType Directory $targetPath | ||
|
||
mkdir cmdlet | Out-Null | ||
cd cmdlet | ||
mkdir ${cmdletName} | Out-Null | ||
cd ${cmdletName} | ||
|
||
mkdir coreclr | Out-Null | ||
mkdir desktop | Out-Null | ||
|
||
cp $rootDir\build\${cmdletName}* . | ||
cp $rootDir\src\${cmdletName}.Commands\bin\${Configuration}\net6.0\* coreclr -Exclude $excludedFiles -Recurse | ||
cp $rootDir\src\${cmdletName}.Commands\bin\${Configuration}\net462\* desktop -Exclude $excludedFiles -Recurse | ||
|
||
$config = gc "${cmdletName}.psd1" -Raw | ||
$config = $config.Replace("ModuleVersion = '0.1'", "ModuleVersion = '${Env:GITVERSION_MajorMinorPatch}'"); | ||
|
||
if(-not [string]::IsNullOrWhiteSpace($Env:GITVERSION_NuGetPreReleaseTag)) { | ||
$config = $config.Replace("# Prerelease = ''", "Prerelease = '${Env:GITVERSION_NuGetPreReleaseTag}'"); | ||
} | ||
|
||
$config | sc "${cmdletName}.psd1" | ||
|
||
Pop-Location | ||
$modulePath = Join-Path $repositoryPath "src" "$moduleName.Commands" "bin" $Configuration "PsModule" | ||
Copy-Item $modulePath\* $targetPath -Recurse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://www.eryph.io</PackageProjectUrl> | ||
<PackageReleaseNotes>https://github.com/eryph-org/dotnet-computeclient/releases</PackageReleaseNotes> | ||
<Authors>dbosoft GmbH and Eryph contributors</Authors> | ||
<Company>dbosoft GmbH</Company> | ||
<Product>Eryph</Product> | ||
<Copyright>dbosoft GmbH. All rights reserved.</Copyright> | ||
<RepositoryUrl>https://github.com/eryph-org/dotnet-computeclient</RepositoryUrl> | ||
<!-- Declare that the Repository URL can be published to NuSpec --> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<!-- Embed source files that are not tracked by the source control manager to the PDB --> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<!-- Include PDB in the built .nupkg --> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<LangVersion>12</LangVersion> | ||
<NoWarn>CS1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<ContinuousIntegrationBuild Condition="'$(TF_BUILD)' == 'true'">True</ContinuousIntegrationBuild> | ||
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
src/Eryph.ComputeClient.Commands/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
{ | ||
"profiles": { | ||
"Eryph.ComputeClient.Commands": { | ||
"commandName": "Project" | ||
}, | ||
"Run in Powershell": { | ||
"commandName": "Executable", | ||
"executablePath": "powershell.exe", | ||
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module $(TargetPath)\"" | ||
}, | ||
"Run in Powershell Core": { | ||
"commandName": "Executable", | ||
"executablePath": "pwsh.exe", | ||
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module $(TargetPath)\"" | ||
"executablePath": "$(PowershellExecutable)", | ||
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module '$(ProjectDir)bin/$(Configuration)/PsModule/$(PsModuleName)'\"" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.