diff --git a/build/Clean-PsModule.ps1 b/build/Clean-PsModule.ps1 new file mode 100644 index 0000000..623d86d --- /dev/null +++ b/build/Clean-PsModule.ps1 @@ -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 +} diff --git a/build/Eryph.ComputeClient.psd1 b/build/Eryph.ComputeClient.psd1 index fc336db..b3d3eb4 100644 --- a/build/Eryph.ComputeClient.psd1 +++ b/build/Eryph.ComputeClient.psd1 @@ -73,12 +73,12 @@ FunctionsToExport = @() # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @( - "Get-Catlet", - "New-Catlet", - "Remove-Catlet", - "Update-Catlet", - "Start-Catlet", - "Stop-Catlet", + "Get-Catlet", + "New-Catlet", + "Remove-Catlet", + "Update-Catlet", + "Start-Catlet", + "Stop-Catlet", "Get-CatletIp", "Get-CatletDisk", "New-CatletDisk", diff --git a/build/Package-PsModule.ps1 b/build/Package-PsModule.ps1 new file mode 100644 index 0000000..27ffcd9 --- /dev/null +++ b/build/Package-PsModule.ps1 @@ -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 ', ')" +} diff --git a/build/build-cmdlet.ps1 b/build/build-cmdlet.ps1 index 4548313..c94c29e 100644 --- a/build/build-cmdlet.ps1 +++ b/build/build-cmdlet.ps1 @@ -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 \ No newline at end of file +$modulePath = Join-Path $repositoryPath "src" "$moduleName.Commands" "bin" $Configuration "PsModule" +Copy-Item $modulePath\* $targetPath -Recurse diff --git a/gen/generate_local.ps1 b/gen/generate_local.ps1 index d5b3560..3c0f44d 100644 --- a/gen/generate_local.ps1 +++ b/gen/generate_local.ps1 @@ -12,7 +12,7 @@ $PSNativeCommandUseErrorActionPreference = $true $ErrorActionPreference = 'Stop' # Update the version in the csproj when changing this -$autoRestCSharpVersion = "3.0.0-beta.20240527.2" +$autoRestCSharpVersion = "3.0.0-beta.20241108.1" $settings = Get-Content -Raw -Path "$PSScriptRoot/config.json" | ConvertFrom-Json $tag = $settings.tag @@ -20,7 +20,7 @@ $spec = $settings.spec npm exec --package="autorest@3.7.1" -- ` autorest ` - --version="3.10.2" ` + --version="3.10.3" ` --use="@autorest/csharp@$autoRestCSharpVersion" ` --use="@autorest/modelerfour@4.27.0" ` "$PSScriptRoot/../../eryph-api-spec/specification/$spec" ` diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000..ea18890 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,37 @@ + + + MIT + https://www.eryph.io + https://github.com/eryph-org/dotnet-computeclient/releases + dbosoft GmbH and Eryph contributors + dbosoft GmbH + Eryph + dbosoft GmbH. All rights reserved. + https://github.com/eryph-org/dotnet-computeclient + + true + + true + + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + + + + 12 + CS1591 + + + + True + True + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj b/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj index 95f62b2..bee85d6 100644 --- a/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj +++ b/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj @@ -1,22 +1,17 @@  - net462;net6.0 + net462;net8.0 false true - 12 - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - All @@ -25,4 +20,21 @@ + + + + Eryph.ComputeClient + pwsh.exe + + + powershell.exe + + + + + + + + + diff --git a/src/Eryph.ComputeClient.Commands/Properties/launchSettings.json b/src/Eryph.ComputeClient.Commands/Properties/launchSettings.json index df293cf..b5167b2 100644 --- a/src/Eryph.ComputeClient.Commands/Properties/launchSettings.json +++ b/src/Eryph.ComputeClient.Commands/Properties/launchSettings.json @@ -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)'\"" } } } \ No newline at end of file diff --git a/src/Eryph.ComputeClient/Eryph.ComputeClient.csproj b/src/Eryph.ComputeClient/Eryph.ComputeClient.csproj index 1591b11..e703b3c 100644 --- a/src/Eryph.ComputeClient/Eryph.ComputeClient.csproj +++ b/src/Eryph.ComputeClient/Eryph.ComputeClient.csproj @@ -4,21 +4,17 @@ netstandard2.0 true annotations + Client library for the eryph compute API. - 12 true https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + \ No newline at end of file diff --git a/src/Eryph.ComputeClient/Generated/Internal/RequestContentHelper.cs b/src/Eryph.ComputeClient/Generated/Internal/RequestContentHelper.cs index 703d4a0..1cdcae3 100644 --- a/src/Eryph.ComputeClient/Generated/Internal/RequestContentHelper.cs +++ b/src/Eryph.ComputeClient/Generated/Internal/RequestContentHelper.cs @@ -55,6 +55,20 @@ public static RequestContent FromEnumerable(IEnumerable enumerable) return content; } + public static RequestContent FromEnumerable(ReadOnlySpan span) + where T : notnull + { + Utf8JsonRequestContent content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteStartArray(); + for (int i = 0; i < span.Length; i++) + { + content.JsonWriter.WriteObjectValue(span[i]); + } + content.JsonWriter.WriteEndArray(); + + return content; + } + public static RequestContent FromDictionary(IDictionary dictionary) where TValue : notnull { diff --git a/src/Eryph.ComputeClient/Generated/Models/CatletDriveType.cs b/src/Eryph.ComputeClient/Generated/Models/CatletDriveType.cs index 23a468b..fa3462f 100644 --- a/src/Eryph.ComputeClient/Generated/Models/CatletDriveType.cs +++ b/src/Eryph.ComputeClient/Generated/Models/CatletDriveType.cs @@ -42,7 +42,7 @@ public CatletDriveType(string value) public static bool operator ==(CatletDriveType left, CatletDriveType right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(CatletDriveType left, CatletDriveType right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator CatletDriveType(string value) => new CatletDriveType(value); /// @@ -53,7 +53,7 @@ public CatletDriveType(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; } diff --git a/src/Eryph.ComputeClient/Generated/Models/CatletStatus.cs b/src/Eryph.ComputeClient/Generated/Models/CatletStatus.cs index ce27fb0..a436e3b 100644 --- a/src/Eryph.ComputeClient/Generated/Models/CatletStatus.cs +++ b/src/Eryph.ComputeClient/Generated/Models/CatletStatus.cs @@ -39,7 +39,7 @@ public CatletStatus(string value) public static bool operator ==(CatletStatus left, CatletStatus right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(CatletStatus left, CatletStatus right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator CatletStatus(string value) => new CatletStatus(value); /// @@ -50,7 +50,7 @@ public CatletStatus(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; } diff --git a/src/Eryph.ComputeClient/Generated/Models/CatletStopMode.cs b/src/Eryph.ComputeClient/Generated/Models/CatletStopMode.cs index 1652d07..eb80d5b 100644 --- a/src/Eryph.ComputeClient/Generated/Models/CatletStopMode.cs +++ b/src/Eryph.ComputeClient/Generated/Models/CatletStopMode.cs @@ -33,7 +33,7 @@ public CatletStopMode(string value) public static bool operator ==(CatletStopMode left, CatletStopMode right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(CatletStopMode left, CatletStopMode right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator CatletStopMode(string value) => new CatletStopMode(value); /// @@ -44,7 +44,7 @@ public CatletStopMode(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; } diff --git a/src/Eryph.ComputeClient/Generated/Models/GeneType.cs b/src/Eryph.ComputeClient/Generated/Models/GeneType.cs index e1b82ab..fa60240 100644 --- a/src/Eryph.ComputeClient/Generated/Models/GeneType.cs +++ b/src/Eryph.ComputeClient/Generated/Models/GeneType.cs @@ -36,7 +36,7 @@ public GeneType(string value) public static bool operator ==(GeneType left, GeneType right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(GeneType left, GeneType right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator GeneType(string value) => new GeneType(value); /// @@ -47,7 +47,7 @@ public GeneType(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; } diff --git a/src/Eryph.ComputeClient/Generated/Models/OperationStatus.cs b/src/Eryph.ComputeClient/Generated/Models/OperationStatus.cs index 5fbd8a9..36c4471 100644 --- a/src/Eryph.ComputeClient/Generated/Models/OperationStatus.cs +++ b/src/Eryph.ComputeClient/Generated/Models/OperationStatus.cs @@ -39,7 +39,7 @@ public OperationStatus(string value) public static bool operator ==(OperationStatus left, OperationStatus right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(OperationStatus left, OperationStatus right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator OperationStatus(string value) => new OperationStatus(value); /// @@ -50,7 +50,7 @@ public OperationStatus(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; } diff --git a/src/Eryph.ComputeClient/Generated/Models/OperationTaskStatus.cs b/src/Eryph.ComputeClient/Generated/Models/OperationTaskStatus.cs index 224d685..60d7a46 100644 --- a/src/Eryph.ComputeClient/Generated/Models/OperationTaskStatus.cs +++ b/src/Eryph.ComputeClient/Generated/Models/OperationTaskStatus.cs @@ -39,7 +39,7 @@ public OperationTaskStatus(string value) public static bool operator ==(OperationTaskStatus left, OperationTaskStatus right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(OperationTaskStatus left, OperationTaskStatus right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator OperationTaskStatus(string value) => new OperationTaskStatus(value); /// @@ -50,7 +50,7 @@ public OperationTaskStatus(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; } diff --git a/src/Eryph.ComputeClient/Generated/Models/ResourceType.cs b/src/Eryph.ComputeClient/Generated/Models/ResourceType.cs index a5f0014..3fcf38b 100644 --- a/src/Eryph.ComputeClient/Generated/Models/ResourceType.cs +++ b/src/Eryph.ComputeClient/Generated/Models/ResourceType.cs @@ -39,7 +39,7 @@ public ResourceType(string value) public static bool operator ==(ResourceType left, ResourceType right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(ResourceType left, ResourceType right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator ResourceType(string value) => new ResourceType(value); /// @@ -50,7 +50,7 @@ public ResourceType(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; } diff --git a/src/Eryph.ComputeClient/Generated/Models/TaskReferenceType.cs b/src/Eryph.ComputeClient/Generated/Models/TaskReferenceType.cs index 64dd539..e9485a6 100644 --- a/src/Eryph.ComputeClient/Generated/Models/TaskReferenceType.cs +++ b/src/Eryph.ComputeClient/Generated/Models/TaskReferenceType.cs @@ -33,7 +33,7 @@ public TaskReferenceType(string value) public static bool operator ==(TaskReferenceType left, TaskReferenceType right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(TaskReferenceType left, TaskReferenceType right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator TaskReferenceType(string value) => new TaskReferenceType(value); /// @@ -44,7 +44,7 @@ public TaskReferenceType(string value) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; /// public override string ToString() => _value; }