Skip to content

Commit 6172d97

Browse files
authored
Merge pull request #30 from rulasg/29-testps1-and-publishps1-improvements
29 testps1 and publishps1 improvements
2 parents cfee7d7 + d9b7f5b commit 6172d97

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

publish.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ param(
2626
# The NuGet API Key for the PSGallery
2727
[Parameter(Mandatory=$false)] [string]$NuGetApiKey,
2828
# Force the publish without prompting for confirmation
29-
[Parameter(Mandatory=$false)] [switch]$Force
29+
[Parameter(Mandatory=$false)] [switch]$Force,
30+
# Force publishing package to the gallery. Equivalente to Import-Module -Force
31+
[Parameter(Mandatory=$false)] [switch]$ForcePublish
3032
)
3133

3234
# check that $NuggetApiKey is null or whitespace
3335
# If it is use environment variable $env:NugetApiKey
3436
if ( [string]::IsNullOrWhiteSpace($NuGetApiKey) ) {
3537

3638
if ( [string]::IsNullOrWhiteSpace($env:NUGETAPIKEY) ) {
37-
Write-Error -Message '$Env:NUGETAPIKEY is not set. Try running `$Env:NUGETAPIKEY = fdf nuget | Get-SecretValue`'
3839
Write-Error -Message '$Env:NUGETAPIKEY is not set. Try running `$Env:NUGETAPIKEY = (Find-DocsFile nugetapikey | rsk | Get-SecretData).Get()`'
3940
return
4041
}
@@ -74,5 +75,5 @@ if ($PSCmdlet.ShouldProcess($psdPath, "Publish-Module")) {
7475
# show an empty line
7576
Write-Information -InformationAction Continue -Message ""
7677
Write-Information -InformationAction Continue -Message $message
77-
publish-Module -Name $psdPath -NuGetApiKey $NuGetApiKey
78+
Publish-Module -Name $psdPath -NuGetApiKey $NuGetApiKey -Force:$ForcePublish
7879
}

test.ps1

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
[CmdletBinding()]
22
param ()
33

4-
function Import-TestingHelper($Version){
4+
function Import-TestingHelper{
5+
[CmdletBinding()]
6+
param (
7+
[Parameter()][string]$Version,
8+
[Parameter()][switch]$AllowPrerelease,
9+
[Parameter()][switch]$PassThru
10+
)
511

6-
if (-not (import-Module TestingHelper -RequiredVersion $Version -PassThru -ErrorAction SilentlyContinue )) {
7-
Install-Module -Name TestingHelper -Force -RequiredVersion $Version
8-
Import-Module -Name TestingHelper -Force -RequiredVersion $Version
12+
13+
if ($Version) {
14+
$V = $Version.Split('-')
15+
$semVer = $V[0]
16+
$AllowPrerelease = ($AllowPrerelease -or ($null -ne $V[1]))
17+
}
18+
19+
$module = Import-Module TestingHelper -PassThru -ErrorAction SilentlyContinue -RequiredVersion:$semVer
20+
21+
if ($null -eq $module) {
22+
$installed = Install-Module -Name TestingHelper -Force -AllowPrerelease:$AllowPrerelease -passThru -RequiredVersion:$Version
23+
$module = Import-Module -Name $installed.Name -RequiredVersion ($installed.Version.Split('-')[0]) -Force -PassThru
924
}
10-
}
1125

12-
Import-TestingHelper -Version $Version
26+
if ($PassThru) {
27+
$module
28+
}
29+
}
1330

14-
$psd = get-childitem -Path $PSScriptRoot -Filter *.psd1
31+
Import-TestingHelper -version 2.1.1-alpha #first version wiht Test-ModulelocalPsd1
1532

16-
Import-Module -Name $psd.FullName -Force
33+
# Run test by PSD1 file
34+
Test-ModulelocalPSD1
1735

18-
Test-Module -Name $psd.BaseName
36+
# Run tests by module name
37+
# We need to manage the import of the version we want to test
38+
# If there are different versions of the module installed, we need to import the one we want to test
39+
# $psd = get-childitem -Path $PSScriptRoot -Filter *.psd1
40+
# Import-Module -Name $psd.FullName -Force
41+
# Test-Module -Name $psd.BaseName

0 commit comments

Comments
 (0)