Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command Invoke-PesterJob #8

Merged
merged 17 commits into from
Sep 2, 2024
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Public commands:
- `Invoke-PesterJob`
- `Get-ModuleVersion`
- `ConvertTo-RelativePath`

## [0.2.0] - 2024-08-25

### Added
Expand All @@ -14,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `ConvertTo-DifferenceString`
- `Get-NumericalSequence`
- `Get-PSReadLineHistory`
- `Invoke-PesterJob`
- `New-SamplerGitHubReleaseTag`
- `Out-Difference`
- `Pop-VMLatestSnapShot`
Expand Down
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Pester:
StackTraceVerbosity: Full
CIFormat: Auto
CodeCoverage:
CoveragePercentTarget: 85
CoveragePercentTarget: 50
OutputEncoding: ascii
UseBreakpoints: false
TestResult:
Expand Down
65 changes: 65 additions & 0 deletions source/Public/ConvertTo-RelativePath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<#
.SYNOPSIS
Converts an absolute path to a relative path.

.DESCRIPTION
The ConvertTo-RelativePath command takes an absolute path and converts it
to a relative path based on the current location. If the absolute path
starts with the current location, the function removes the current location
from the beginning of the path and inserts a '.' to indicate the relative path.

.PARAMETER AbsolutePath
Specifies the absolute path that needs to be converted to a relative path.

.PARAMETER CurrentLocation
Specifies the current location used as a reference for converting the absolute
path to a relative path. If not specified, the function uses the current
location obtained from Get-Location.

.EXAMPLE
ConvertTo-RelativePath -AbsolutePath '/source/Viscalyx.Common/source/Public/ConvertTo-RelativePath.ps1' -CurrentLocation "/source/Viscalyx.Common"

Returns "./source/Public/ConvertTo-RelativePath.ps1", which is the
relative path of the given absolute path based on the current location.

.INPUTS
[System.String]

.OUTPUTS
[System.String]
#>
function ConvertTo-RelativePath
Fixed Show fixed Hide fixed
{
[CmdletBinding()]
[OutputType([System.String])]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
[System.String]
$AbsolutePath,

[Parameter(Position = 1)]
[System.String]
$CurrentLocation
)

begin
{
if (-not $PSBoundParameters.ContainsKey('CurrentLocation'))
{
$CurrentLocation = (Get-Location).Path
}
}

process
{
$relativePath = $AbsolutePath

if ($relativePath.StartsWith($CurrentLocation))
{
$relativePath = $relativePath.Substring($CurrentLocation.Length).Insert(0, '.')
}

return $relativePath
}
}
82 changes: 82 additions & 0 deletions source/Public/Get-ModuleVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<#
.SYNOPSIS
Retrieves the version of a PowerShell module.

.DESCRIPTION
The Get-ModuleVersion command retrieves the version of a PowerShell module.
It accepts a module name or a PSModuleInfo object as input and returns the
module version as a string.

.PARAMETER Module
Specifies the module for which to retrieve the version. This can be either
a module name or a PSModuleInfo object.

.EXAMPLE
Get-ModuleVersion -Module 'MyModule'

Retrieves the version of the module named "MyModule".

.EXAMPLE
$moduleInfo = Get-Module -Name 'MyModule'
Get-ModuleVersion -Module $moduleInfo

Retrieves the version of the module specified by the PSModuleInfo object $moduleInfo.

.INPUTS
[System.Object]

Accepts a module name or a PSModuleInfo object as input.

.OUTPUTS
[System.String]

Returns the module version as a string.
#>
function Get-ModuleVersion
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
[System.Object]
$Module
)

process
{
$moduleInfo = $null
$moduleVersion = $null

if ($Module -is [System.String])
{
$moduleInfo = Get-Module -Name $Module -ErrorAction 'Stop'

if (-not $moduleInfo)
{
Write-Error -Message "Cannot find the module '$Module'. Make sure it is loaded into the session."
}
}
elseif ($Module -is [System.Management.Automation.PSModuleInfo])
{
$moduleInfo = $Module
}
else
{
Write-Error -Message "Invalid parameter type. The parameter 'Module' must be either a string or a PSModuleInfo object."
}

if ($moduleInfo)
{
$moduleVersion = $moduleInfo.Version.ToString()

$previewReleaseTag = $moduleInfo.PrivateData.PSData.Prerelease

if ($previewReleaseTag)
{
$moduleVersion += '-{0}' -f $previewReleaseTag
}
}

return $moduleVersion
}
}
Loading