diff --git a/private/templates/template.launch.json b/private/templates/template.launch.json index cb833c5..e72821b 100644 --- a/private/templates/template.launch.json +++ b/private/templates/template.launch.json @@ -2,6 +2,9 @@ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + // + // Module V2 - https://raw.githubusercontent.com/rulasg/DemoPsModule/main/.vscode/launch.json + "version": "0.2.0", "configurations": [ { diff --git a/private/templates/template.module.psm1 b/private/templates/template.module.psm1 index b4fb511..78ba1d5 100644 --- a/private/templates/template.module.psm1 +++ b/private/templates/template.module.psm1 @@ -1,3 +1,13 @@ +<# +.SYNOPSIS + RootModule of the module V2 TestingHelper framework. +.DESCRIPTION + This is the RootModule of a library that will load the module code from .ps1 files presented on public and private folders + This structure allows to split the code of a module on different files allowing a better maintenance and collaborative development. + Check rulasg/DemoPsModule as a module smaple or rulasg/TestingHelper as the helper of this framework. +.LINK + https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.module.psm1 +#> #Get public and private function definition files. diff --git a/publish-Helper.ps1 b/publish-Helper.ps1 index 7f7a2c7..3d360d3 100644 --- a/publish-Helper.ps1 +++ b/publish-Helper.ps1 @@ -1,3 +1,20 @@ +# add help to script + +<# +.SYNOPSIS + Publish a PowerShell module to the PowerShell Gallery. + +.DESCRIPTION + Functions library for publishing a PowerShell module to the PowerShell Gallery. + + This script is intended to be used as a helper for the Publish.ps1 script. + It is not intended to be used directly. + +.LINK + https://raw.githubusercontent.com/rulasg/DemoPsModule/main/publish-Helper.ps1 + +#> + Write-Information -MessageData ("Loading {0} ..." -f ($PSCommandPath | Split-Path -LeafBase)) @@ -142,4 +159,4 @@ function Get-PublishModuleManifestPath { } else { $psdPath } -} \ No newline at end of file +} diff --git a/release.ps1 b/release.ps1 index 1466a1e..1d9ff86 100644 --- a/release.ps1 +++ b/release.ps1 @@ -6,18 +6,34 @@ Create a tag on the repo and a release to that tag on GitHub remote repo. This script works very well with GitHub Actions workflow that run on release creation. + Check the following workflow as an example: + https://raw.githubusercontent.com/rulasg/DemoPsModule/main/.github/workflows/publish_module_on_release.yml + + .PARAMETER VersionTag Tag to create (Sample: v10.0.01-alpha). This is the same tag that will be used for the release. .PARAMETER Force Force the script to run without confirmation. +.PARAMETER CreateTag + Create the tag on the repo. If not specified, the script will only create the release. + .EXAMPLE .\release.ps1 -VersionTag v10.0.01-alpha + Create a release on the existing tag v10.0.01-alpha. + .EXAMPLE - .\release.ps1 -VersionTag v10.0.01-alpha -Force + .\release.ps1 -VersionTag v10.0.01-alpha -CreateTag + + Create a release on the existing tag v10.0.01-alpha and create the tag on the repo. +.EXAMPLE + .\release.ps1 -VersionTag v10.0.01-alpha -CreateTag -Force + + Create tag and create release without confirmation. + .LINK https://raw.githubusercontent.com/rulasg/DemoPsModule/main/release.ps1 #> @@ -26,7 +42,9 @@ param( # Update the module manifest with the version tag (Sample: v10.0.01-alpha) [Parameter(Mandatory)] [string]$VersionTag, - [Parameter()] [switch]$Force + [Parameter()] [switch]$Force, + [Parameter()] [switch]$CreateTag, + [Parameter()] [switch]$NotPreRelease ) # Confirm if not forced @@ -34,10 +52,18 @@ if ($Force -and -not $Confirm){ $ConfirmPreference = 'None' } -if ($PSCmdlet.ShouldProcess($VersionTag, "git tag creation")) { - git tag -a $VersionTag -m "Release tag" -s ; git push --tags +if ($CreateTag) { + if ($PSCmdlet.ShouldProcess($VersionTag, "git tag creation")) { + git tag -a $VersionTag -m "Release tag" -s ; git push --tags + } } if ($PSCmdlet.ShouldProcess($VersionTag, "gh release create")) { - gh release create $VersionTag --prerelease --generate-notes --verify-tag --title "Release $VersionTag" + + if ($NotPreRelease) { + gh release create $VersionTag --generate-notes --verify-tag --title "Release $VersionTag" + + } else { + gh release create $VersionTag --generate-notes --verify-tag --title "Release $VersionTag (PreRelease)" --prerelease + } } \ No newline at end of file diff --git a/sync-Helper.ps1 b/sync-Helper.ps1 new file mode 100644 index 0000000..2bb714b --- /dev/null +++ b/sync-Helper.ps1 @@ -0,0 +1,50 @@ +<# +.SYNOPSIS + Helper functions to Synchronize TestingHelper templates files + +.DESCRIPTION + Helper functions Synchronize TestingHelper templates to the local repo. + TestingHelper uses templates to create a new module. + This script will update the local module with the latest templates. +.LINK + https://raw.githubusercontent.com/rulasg/DemoPsModule/main/sync.ps1 +#> + +[cmdletbinding()] +param() + +function Get-UrlContent { + [cmdletbinding()] + param( + [Parameter(Mandatory=$true)][string]$url + ) + $wc = New-Object -TypeName System.Net.WebClient + $fileContent = $wc.DownloadString($url) + + return $fileContent +} + +function Out-ContentToFile { + [cmdletbinding(SupportsShouldProcess)] + param( + [Parameter(ValueFromPipeline)][string]$content, + [Parameter(Mandatory=$true)][string]$filePath + ) + + if ($PSCmdlet.ShouldProcess($filePath, "Save content [{0}] to file" -f $content.Length)) { + $content | Out-File -FilePath $filePath -Force + } +} + +function Save-UrlContentToFile { + [cmdletbinding()] + param( + [Parameter(Mandatory=$true)][string]$Url, + [Parameter(Mandatory=$true)][string]$FilePath + ) + + $fileContent = Get-UrlContent -Url $url + $fileContent | Out-ContentToFile -FilePath $filePath + + Write-Information -MessageData "Saved content to [$filePath] from [$url]" +} diff --git a/sync.ps1 b/sync.ps1 new file mode 100644 index 0000000..f83fac5 --- /dev/null +++ b/sync.ps1 @@ -0,0 +1,21 @@ +<# +.SYNOPSIS + Synchronizes TestingHelper templates files + +.DESCRIPTION + Synchronizes TestingHelper templates to the local repo. + TestingHelper uses templates to create a new module. + This script will update the local module with the latest templates. +.LINK + https://raw.githubusercontent.com/rulasg/DemoPsModule/main/sync.ps1 +#> + +[cmdletbinding()] +param() + +. ($PSScriptRoot | Join-Path -ChildPath "sync-Helper.ps1") + +Save-UrlContentToFile -Url 'https://raw.githubusercontent.com/rulasg/DemoPsModule/main/test.ps1' -FilePath 'test.ps1' +Save-UrlContentToFile -Url 'https://raw.githubusercontent.com/rulasg/DemoPsModule/main/release.ps1' -FilePath 'release.ps1' +Save-UrlContentToFile -Url 'https://raw.githubusercontent.com/rulasg/DemoPsModule/main/publish.ps1' -FilePath 'publish.ps1' +Save-UrlContentToFile -Url 'https://raw.githubusercontent.com/rulasg/DemoPsModule/main/publish-Helper.ps1' -FilePath 'publish-Helper.ps1' diff --git a/test.ps1 b/test.ps1 index 1188c07..49aefae 100644 --- a/test.ps1 +++ b/test.ps1 @@ -24,8 +24,7 @@ function Import-TestingHelper{ [Parameter()][switch]$AllowPrerelease, [Parameter()][switch]$PassThru ) - - + if ($Version) { $V = $Version.Split('-') $semVer = $V[0] @@ -47,4 +46,4 @@ function Import-TestingHelper{ Import-TestingHelper -AllowPrerelease # Run test by PSD1 file -Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors \ No newline at end of file +Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors