Skip to content

Commit d275933

Browse files
Refactor action.yml and main.ps1 to remove Path input and add WorkingDirectory input; implement Convert-VersionSpec function for version range handling.
1 parent bd73f91 commit d275933

File tree

4 files changed

+107
-36
lines changed

4 files changed

+107
-36
lines changed

action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ inputs:
99
Name:
1010
description: Name of the module to process.
1111
required: false
12-
Path:
13-
description: The path to the root of the repo.
14-
required: false
15-
default: ${{ github.workspace }}
1612
Debug:
1713
description: Enable debug output.
1814
required: false
@@ -28,15 +24,19 @@ inputs:
2824
description: Allow prerelease versions if available.
2925
required: false
3026
default: 'false'
27+
WorkingDirectory:
28+
description: The working directory where the script will run from.
29+
required: false
30+
default: ${{ github.workspace }}
3131

3232
runs:
3333
using: composite
3434
steps:
3535
- name: Document-PSModule
3636
env:
3737
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
38-
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}
3938
shell: pwsh
39+
working-directory: ${{ inputs.WorkingDirectory }}
4040
run: |
4141
# Build-PSModuleDocumentation
42-
${{ github.action_path }}\scripts\main.ps1
42+
${{ github.action_path }}/scripts/main.ps1
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
function Convert-VersionSpec {
2+
<#
3+
.SYNOPSIS
4+
Converts legacy version parameters into a NuGet version range string.
5+
6+
.DESCRIPTION
7+
This function takes minimum, maximum, or required version parameters
8+
and constructs a NuGet-compatible version range string.
9+
10+
- If `RequiredVersion` is specified, the output is an exact match range.
11+
- If both `MinimumVersion` and `MaximumVersion` are provided,
12+
an inclusive range is returned.
13+
- If only `MinimumVersion` is provided, it returns a minimum-inclusive range.
14+
- If only `MaximumVersion` is provided, it returns an upper-bound range.
15+
- If no parameters are provided, `$null` is returned.
16+
17+
.EXAMPLE
18+
Convert-VersionSpec -MinimumVersion "1.0.0" -MaximumVersion "2.0.0"
19+
20+
Output:
21+
```powershell
22+
[1.0.0,2.0.0]
23+
```
24+
25+
Returns an inclusive version range from 1.0.0 to 2.0.0.
26+
27+
.EXAMPLE
28+
Convert-VersionSpec -RequiredVersion "1.5.0"
29+
30+
Output:
31+
```powershell
32+
[1.5.0]
33+
```
34+
35+
Returns an exact match for version 1.5.0.
36+
37+
.EXAMPLE
38+
Convert-VersionSpec -MinimumVersion "1.0.0"
39+
40+
Output:
41+
```powershell
42+
[1.0.0, ]
43+
```
44+
45+
Returns a minimum-inclusive version range starting at 1.0.0.
46+
47+
.EXAMPLE
48+
Convert-VersionSpec -MaximumVersion "2.0.0"
49+
50+
Output:
51+
```powershell
52+
(, 2.0.0]
53+
```
54+
55+
Returns an upper-bound range up to version 2.0.0.
56+
57+
.OUTPUTS
58+
string
59+
60+
.NOTES
61+
The NuGet version range string based on the provided parameters.
62+
The returned string follows NuGet versioning syntax.
63+
64+
.LINK
65+
https://psmodule.io/Convert/Functions/Convert-VersionSpec
66+
#>
67+
[OutputType([string])]
68+
[CmdletBinding()]
69+
param(
70+
# The minimum version for the range. If specified alone, the range is open-ended upwards.
71+
[Parameter()]
72+
[string] $MinimumVersion,
73+
74+
# The maximum version for the range. If specified alone, the range is open-ended downwards.
75+
[Parameter()]
76+
[string] $MaximumVersion,
77+
78+
# Specifies an exact required version. If set, an exact version range is returned.
79+
[Parameter()]
80+
[string] $RequiredVersion
81+
)
82+
83+
if ($RequiredVersion) {
84+
# Use exact match in bracket notation.
85+
return "[$RequiredVersion]"
86+
} elseif ($MinimumVersion -and $MaximumVersion) {
87+
# Both bounds provided; both are inclusive.
88+
return "[$MinimumVersion,$MaximumVersion]"
89+
} elseif ($MinimumVersion) {
90+
# Only a minimum is provided. Use a minimum-inclusive range.
91+
return "[$MinimumVersion, ]"
92+
} elseif ($MaximumVersion) {
93+
# Only a maximum is provided; lower bound open.
94+
return "(, $MaximumVersion]"
95+
} else {
96+
return $null
97+
}
98+
}

scripts/helpers/Resolve-PSModuleDependency.ps1

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,6 @@
2929
[string] $ManifestFilePath
3030
)
3131

32-
# Helper: Convert legacy version parameters into a NuGet version range string.
33-
function Convert-VersionSpec {
34-
param(
35-
[string]$MinimumVersion,
36-
[string]$MaximumVersion,
37-
[string]$RequiredVersion
38-
)
39-
if ($RequiredVersion) {
40-
# Use exact match in bracket notation.
41-
return "[$RequiredVersion]"
42-
} elseif ($MinimumVersion -and $MaximumVersion) {
43-
# Both bounds provided; both are inclusive.
44-
return "[$MinimumVersion,$MaximumVersion]"
45-
} elseif ($MinimumVersion) {
46-
# Only a minimum is provided. Use a minimum-inclusive range.
47-
return "[$MinimumVersion, ]"
48-
} elseif ($MaximumVersion) {
49-
# Only a maximum is provided; lower bound open.
50-
return "(, $MaximumVersion]"
51-
} else {
52-
return $null
53-
}
54-
}
55-
5632
Write-Host 'Resolving dependencies'
5733
$manifest = Import-PowerShellDataFile -Path $ManifestFilePath
5834
Write-Host " - Reading [$ManifestFilePath]"

scripts/main.ps1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ $env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/'
2222
$moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name
2323
Write-Host "Module name: [$moduleName]"
2424

25-
$moduleSourceFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/src"
26-
if (-not (Test-Path -Path $moduleSourceFolderPath)) {
27-
throw "Module path [$moduleSourceFolderPath] does not exist."
28-
}
25+
$moduleSourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path
2926
Write-Host "Module source path: [$moduleSourceFolderPath]"
3027

31-
$modulesOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/module'
28+
$modulesOutputFolderPath = New-Item -Path 'outputs/module' -Force
3229
Write-Host "Module output path: [$modulesOutputFolderPath]"
33-
$docsOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/docs'
30+
$docsOutputFolderPath = New-Item -Path 'outputs/docs' -Force
3431
Write-Host "Docs output path: [$docsOutputFolderPath]"
3532

3633
$params = @{

0 commit comments

Comments
 (0)