Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions private/templates/template.launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
10 changes: 10 additions & 0 deletions private/templates/template.module.psm1
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 18 additions & 1 deletion publish-Helper.ps1
Original file line number Diff line number Diff line change
@@ -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))

Expand Down Expand Up @@ -142,4 +159,4 @@ function Get-PublishModuleManifestPath {
} else {
$psdPath
}
}
}
36 changes: 31 additions & 5 deletions release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
#>
Expand All @@ -26,18 +42,28 @@
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
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
}
}
50 changes: 50 additions & 0 deletions sync-Helper.ps1
Original file line number Diff line number Diff line change
@@ -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]"
}
21 changes: 21 additions & 0 deletions sync.ps1
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 2 additions & 3 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ function Import-TestingHelper{
[Parameter()][switch]$AllowPrerelease,
[Parameter()][switch]$PassThru
)



if ($Version) {
$V = $Version.Split('-')
$semVer = $V[0]
Expand All @@ -47,4 +46,4 @@ function Import-TestingHelper{
Import-TestingHelper -AllowPrerelease

# Run test by PSD1 file
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors