Skip to content

Commit f8ba71c

Browse files
Improve tooling
1 parent 35217b1 commit f8ba71c

File tree

7 files changed

+196
-70
lines changed

7 files changed

+196
-70
lines changed

build/Clean-PsModule.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#Requires -Version 7.4
2+
<#
3+
.SYNOPSIS
4+
Remove the Powershell module from the build output.
5+
.DESCRIPTION
6+
This script removes the Powershell module from the build output.
7+
It is intended to be called by MSBuild during the normal clean process.
8+
The script might be called once for each target framework.
9+
#>
10+
[CmdletBinding()]
11+
param(
12+
[Parameter()]
13+
[string]
14+
[ValidateNotNullOrEmpty()]
15+
$OutputDirectory
16+
)
17+
18+
$PSNativeCommandUseErrorActionPreference = $true
19+
$ErrorActionPreference = 'Stop'
20+
21+
$modulePath = Join-Path $OutputDirectory "PsModule"
22+
23+
if (Test-Path $modulePath) {
24+
# This script might be called in parallel for each target framework.
25+
# Hence, we ignore errors as files might have been removed by another instance.
26+
Remove-Item -Path $modulePath -Force -Recurse -ErrorAction SilentlyContinue
27+
}

build/Package-PsModule.ps1

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#Requires -Version 7.4
2+
<#
3+
.SYNOPSIS
4+
Package the Powershell module.
5+
.DESCRIPTION
6+
This script packages the Powershell module for distribution.
7+
It is intended to be called by MSBuild during the normal build
8+
process. The script will be called once for each target framework.
9+
#>
10+
[CmdletBinding()]
11+
param(
12+
[Parameter()]
13+
[string]
14+
[ValidateScript({ $_ -match '[a-zA-Z\.]+' }, ErrorMessage = "The module name '{0}' is invalid.")]
15+
$ModuleName,
16+
[Parameter()]
17+
[string]
18+
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")]
19+
$TargetPath,
20+
[Parameter()]
21+
[string]
22+
[ValidateScript({ $_ -match 'net\d+\.?\d+' }, ErrorMessage = "The target framework '{0}' is invalid.")]
23+
$TargetFramework,
24+
[Parameter()]
25+
[string]
26+
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")]
27+
$OutputDirectory,
28+
[Parameter()]
29+
[string]
30+
[ValidateScript({ $_ -match '\d+\.\d+\.\d+' }, ErrorMessage = "The version '{0}' is invalid.")]
31+
$MajorMinorPatch,
32+
[Parameter()]
33+
[string]
34+
$NuGetPreReleaseTag
35+
)
36+
37+
$PSNativeCommandUseErrorActionPreference = $true
38+
$ErrorActionPreference = 'Stop'
39+
40+
$excludedFiles = @("System.Management.Automation.dll", "JetBrains.Annotations.dll")
41+
42+
$modulePath = Join-Path $OutputDirectory "PsModule" $ModuleName
43+
$isWindowsPowershell = $TargetFramework -like 'net4*'
44+
$moduleAssemblyPath = Join-Path $modulePath ($isWindowsPowershell ? 'desktop' : 'coreclr')
45+
46+
# Prepare the output directory
47+
if (-not (Test-Path $modulePath)) {
48+
$null = New-Item -ItemType Directory -Path $modulePath
49+
}
50+
51+
# Copy the build output
52+
if (Test-Path $moduleAssemblyPath) {
53+
Remove-Item -Path $moduleAssemblyPath -Force -Recurse
54+
}
55+
$null = New-Item -ItemType Directory -Path $moduleAssemblyPath
56+
$targetDirectory = (Get-Item $TargetPath).Directory.FullName
57+
Copy-Item -Path (Join-Path $targetDirectory "*") -Destination $moduleAssemblyPath -Exclude $excludedFiles -Recurse
58+
59+
# Prepare the module manifest
60+
$config = Get-Content (Join-Path $PSScriptRoot "$ModuleName.psd1") -Raw
61+
$config = $config.Replace("ModuleVersion = '0.1'", "ModuleVersion = '$MajorMinorPatch'");
62+
if (-not [string]::IsNullOrWhiteSpace($NuGetPreReleaseTag)) {
63+
$config = $config.Replace("# Prerelease = ''", "Prerelease = '$NuGetPreReleaseTag'");
64+
}
65+
Set-Content -Path (Join-Path $modulePath "$ModuleName.psd1") -Value $config
66+
Copy-Item -Path (Join-Path $PSScriptRoot "$ModuleName.psm1") -Destination $modulePath
67+
68+
# Verify that all Cmdlets are exposed in the manifest. We must load the modules
69+
# in separate Powershell processes to avoid conflicts.
70+
$powershell = $isWindowsPowershell ? 'powershell.exe' : 'pwsh.exe'
71+
$moduleCmdlets = (& $powershell -Command "[array](Import-Module -Scope Local $modulePath -PassThru).ExportedCmdlets.Keys -join ','") -split ','
72+
$assemblyCmdlets = (& $powershell -Command "[array](Import-Module -Scope Local $TargetPath -PassThru).ExportedCmdlets.Keys -join ','") -split ','
73+
$missingCmdlets = [Linq.Enumerable]::Except($assemblyCmdlets, $moduleCmdlets)
74+
if ($missingCmdlets.Count -gt 0) {
75+
throw "The following Cmdlets are not exposed in the module manifest: $($missingCmdlets -join ', ')"
76+
}

build/build-cmdlet.ps1

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,35 @@
1-
param ($Configuration = "Debug", $OutputDir = ".")
2-
3-
$cmdletName = "Eryph.ComputeClient"
4-
$excludedFiles = @("System.Management.Automation.dll", "JetBrains.Annotations.dll")
5-
6-
# If this script is not running on a build server, remind user to
7-
# set environment variables so that this script can be debugged
8-
if(-not ($Env:GITVERSION_MajorMinorPatch))
9-
{
10-
Write-Error "You must set the following environment variables"
11-
Write-Error "to test this script interactively (values are examples)"
12-
Write-Host '$Env:GITVERSION_MajorMinorPatch = "1.0.0"'
13-
Write-Host '$Env:GITVERSION_NuGetPreReleaseTag = "ci0030"'
14-
exit 1
15-
}
16-
17-
18-
Push-Location $PSScriptRoot
19-
cd ..
20-
$rootDir = Get-Location
21-
22-
Push-Location $OutputDir
23-
24-
if(Test-Path cmdlet ) {
25-
rm cmdlet -Force -Recurse -ErrorAction Stop
1+
#Requires -Version 7.4
2+
<#
3+
.SYNOPSIS
4+
Prepare the Powershell module for publication.
5+
.DESCRIPTION
6+
This script moves the already built Powershell module to a location
7+
where the release pipeline will pick it up for publication.
8+
The name and output location of this script cannot be changed as
9+
it would break the release pipeline.
10+
#>
11+
[CmdletBinding()]
12+
param (
13+
[Parameter()]
14+
[string]
15+
[ValidateNotNullOrEmpty()]
16+
$Configuration,
17+
[Parameter()]
18+
[string]
19+
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")]
20+
$OutputDir
21+
)
22+
23+
$ErrorActionPreference = 'Stop'
24+
$moduleName = "Eryph.ComputeClient"
25+
26+
$repositoryPath = Resolve-Path (Join-Path $PSScriptRoot "..")
27+
$targetPath = Join-Path $OutputDir "cmdlet"
28+
29+
if (Test-Path $targetPath ) {
30+
Remove-Item $targetPath -Force -Recurse
2631
}
32+
$null = New-Item -ItemType Directory $targetPath
2733

28-
mkdir cmdlet | Out-Null
29-
cd cmdlet
30-
mkdir ${cmdletName} | Out-Null
31-
cd ${cmdletName}
32-
33-
mkdir coreclr | Out-Null
34-
mkdir desktop | Out-Null
35-
36-
cp $rootDir\build\${cmdletName}* .
37-
cp $rootDir\src\${cmdletName}.Commands\bin\${Configuration}\net6.0\* coreclr -Exclude $excludedFiles -Recurse
38-
cp $rootDir\src\${cmdletName}.Commands\bin\${Configuration}\net462\* desktop -Exclude $excludedFiles -Recurse
39-
40-
$config = gc "${cmdletName}.psd1" -Raw
41-
$config = $config.Replace("ModuleVersion = '0.1'", "ModuleVersion = '${Env:GITVERSION_MajorMinorPatch}'");
42-
43-
if(-not [string]::IsNullOrWhiteSpace($Env:GITVERSION_NuGetPreReleaseTag)) {
44-
$config = $config.Replace("# Prerelease = ''", "Prerelease = '${Env:GITVERSION_NuGetPreReleaseTag}'");
45-
}
46-
47-
$config | sc "${cmdletName}.psd1"
48-
49-
Pop-Location
34+
$modulePath = Join-Path $repositoryPath "src" "$moduleName.Commands" "bin" $Configuration "PsModule"
35+
Copy-Item $modulePath\* $targetPath -Recurse

src/Directory.Build.props

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project>
2+
<PropertyGroup>
3+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
4+
<PackageProjectUrl>https://www.eryph.io</PackageProjectUrl>
5+
<PackageReleaseNotes>https://github.com/eryph-org/dotnet-computeclient/releases</PackageReleaseNotes>
6+
<Authors>dbosoft GmbH and Eryph contributors</Authors>
7+
<Company>dbosoft GmbH</Company>
8+
<Product>Eryph</Product>
9+
<Copyright>dbosoft GmbH. All rights reserved.</Copyright>
10+
<RepositoryUrl>https://github.com/eryph-org/dotnet-computeclient</RepositoryUrl>
11+
<!-- Declare that the Repository URL can be published to NuSpec -->
12+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
13+
<!-- Embed source files that are not tracked by the source control manager to the PDB -->
14+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
15+
<!-- Include PDB in the built .nupkg -->
16+
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
17+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
18+
</PropertyGroup>
19+
20+
<PropertyGroup>
21+
<LangVersion>12</LangVersion>
22+
<NoWarn>CS1591</NoWarn>
23+
</PropertyGroup>
24+
25+
<PropertyGroup>
26+
<ContinuousIntegrationBuild Condition="'$(TF_BUILD)' == 'true'">True</ContinuousIntegrationBuild>
27+
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
32+
<PrivateAssets>all</PrivateAssets>
33+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
34+
</PackageReference>
35+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
36+
</ItemGroup>
37+
</Project>
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net462;net8.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
7-
<LangVersion>12</LangVersion>
87
</PropertyGroup>
98

109
<ItemGroup>
11-
<PackageReference Include="Eryph.ClientRuntime.Powershell" Version="0.7.0" />
10+
<PackageReference Include="Eryph.ClientRuntime.Powershell" Version="0.7.2-PullRequest56.2" />
1211
<PackageReference Include="Eryph.ConfigModel.Catlets.Json" Version="0.7.0" />
1312
<PackageReference Include="Eryph.ConfigModel.Catlets.Yaml" Version="0.7.0" />
1413
<PackageReference Include="Eryph.ConfigModel.Networks.Json" Version="0.7.0" />
1514
<PackageReference Include="Eryph.ConfigModel.Networks.Yaml" Version="0.7.0" />
16-
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
17-
<PrivateAssets>all</PrivateAssets>
18-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19-
</PackageReference>
2015
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1">
2116
<PrivateAssets>All</PrivateAssets>
2217
</PackageReference>
@@ -25,4 +20,21 @@
2520
<ItemGroup>
2621
<ProjectReference Include="..\Eryph.ComputeClient\Eryph.ComputeClient.csproj" />
2722
</ItemGroup>
23+
24+
<!-- Custom properties and targets for packaging the Powershell module -->
25+
<PropertyGroup>
26+
<PsModuleName>Eryph.ComputeClient</PsModuleName>
27+
<PowershellExecutable>pwsh.exe</PowershellExecutable>
28+
</PropertyGroup>
29+
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">
30+
<PowershellExecutable>powershell.exe</PowershellExecutable>
31+
</PropertyGroup>
32+
33+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
34+
<Exec Command="pwsh.exe -NoProfile -File &quot;$(ProjectDir)../../build/Package-PsModule.ps1&quot; -ModuleName &quot;$(PsModuleName)&quot; -OutputDirectory &quot;$([System.IO.Path]::Combine($(ProjectDir), 'bin', $(Configuration)))&quot; -TargetPath &quot;$(TargetPath)&quot; -TargetFramework &quot;$(TargetFramework)&quot; -MajorMinorPatch &quot;$(GitVersion_MajorMinorPatch)&quot; -NuGetPreReleaseTag &quot;$(GitVersion_NuGetPreReleaseTag)&quot;" />
35+
</Target>
36+
<Target Name="PostClean" AfterTargets="Clean">
37+
<Exec Command="pwsh.exe -NoProfile -File &quot;$(ProjectDir)../../build/Clean-PsModule.ps1&quot; -OutputDirectory &quot;$([System.IO.Path]::Combine($(ProjectDir), 'bin', $(Configuration)))&quot;" />
38+
</Target>
39+
2840
</Project>
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
{
22
"profiles": {
3-
"Eryph.ComputeClient.Commands": {
4-
"commandName": "Project"
5-
},
63
"Run in Powershell": {
74
"commandName": "Executable",
8-
"executablePath": "powershell.exe",
9-
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module $(TargetPath)\""
10-
},
11-
"Run in Powershell Core": {
12-
"commandName": "Executable",
13-
"executablePath": "pwsh.exe",
14-
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module $(TargetPath)\""
5+
"executablePath": "$(PowershellExecutable)",
6+
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module '$(ProjectDir)bin/$(Configuration)/PsModule/$(PsModuleName)'\""
157
}
168
}
179
}

src/Eryph.ComputeClient/Eryph.ComputeClient.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
<Nullable>annotations</Nullable>
7+
<description>Client library for the eryph compute API.</description>
78
</PropertyGroup>
89

910
<PropertyGroup>
10-
<LangVersion>12</LangVersion>
1111
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
1212
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json</RestoreAdditionalProjectSources>
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Eryph.ClientRuntime.Authentication" Version="0.7.0" />
17-
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
18-
<PrivateAssets>all</PrivateAssets>
19-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20-
</PackageReference>
16+
<PackageReference Include="Eryph.ClientRuntime.Authentication" Version="0.7.2-PullRequest56.2" />
2117
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20240527.2" PrivateAssets="All" />
2218
</ItemGroup>
2319

0 commit comments

Comments
 (0)