diff --git a/.github/workflows/powershell.yml b/.github/workflows/powershell.yml index 10c5cab..ff245c2 100644 --- a/.github/workflows/powershell.yml +++ b/.github/workflows/powershell.yml @@ -36,7 +36,7 @@ jobs: # The below set up runs PSScriptAnalyzer to your entire repository and runs some basic security rules. path: .\ recurse: true - severity: 'Error' + severity: "Error" # Include your own basic security rules. Removing this option will run all the rules # includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"' output: results.sarif @@ -45,4 +45,4 @@ jobs: - name: Upload SARIF results file uses: github/codeql-action/upload-sarif@v2 with: - sarif_file: results.sarif + sarif_file: results.sarif \ No newline at end of file diff --git a/TestingHelperTest/private/tests-Helper-New-ModuleV3.ps1 b/TestingHelperTest/private/tests-Helper-New-ModuleV3.ps1 index 0227e28..c0f2f58 100644 --- a/TestingHelperTest/private/tests-Helper-New-ModuleV3.ps1 +++ b/TestingHelperTest/private/tests-Helper-New-ModuleV3.ps1 @@ -76,8 +76,8 @@ function Assert-AddModuleV3 { # Deploy if ($AddDeployScript) { - Assert-ItemExist -Path ($Path | Join-Path -ChildPath "deploy.ps1") -Comment "Deploy-Module.ps1" - Assert-ItemExist -Path ($Path | Join-Path -ChildPath "deploy-helper.ps1") -Comment "Deploy-Module.ps1" + Assert-ItemExist -Path ($Path | Join-Path -ChildPath "deploy.ps1") -Comment "deploy.ps1" + Assert-ItemExist -Path ($Path | Join-Path -ChildPath "deploy-helper.ps1") -Comment "deploy-helper.ps1" } # release script @@ -94,7 +94,7 @@ function Assert-AddModuleV3 { # PSScriptAnalyzer if ($AddPSScriptAnalyzerWorkflow) { $destination = $Path | Join-Path -ChildPath ".github" -AdditionalChildPath "workflows" - Assert-ItemExist -Path ($destination | Join-Path -ChildPath "PSScriptAnalyzer.yml") -Comment "PSScriptAnalyzer.yml" + Assert-ItemExist -Path ($destination | Join-Path -ChildPath "powershell.yml") -Comment "powershell.yml" } # TestingWorkflow diff --git a/TestingHelperTest/public/Tests-deploy.ps1 b/TestingHelperTest/public/Tests-deploy.ps1 index 7e55b78..510c9a1 100644 --- a/TestingHelperTest/public/Tests-deploy.ps1 +++ b/TestingHelperTest/public/Tests-deploy.ps1 @@ -17,7 +17,7 @@ $SCRITPBLOCK_WITHNOEXCEPTION = { return 0 } } -$EXCEPTION_MESSAGE = 'Some throw exception comming from Deploy-Module Injection' +$EXCEPTION_MESSAGE = 'Some exception message thown on Invoke-DeployModule injected function' $SCRITPBLOCK_WITHEXCEPTION = { function Invoke-DeployModule { diff --git a/deploy-helper.ps1 b/deploy-helper.ps1 index 62a7dcd..cb29901 100644 --- a/deploy-helper.ps1 +++ b/deploy-helper.ps1 @@ -55,7 +55,7 @@ function Invoke-DeployModuleToPSGallery{ } # Deploy the module with ShouldProcess (-whatif, -confirm) - if ($PSCmdlet.ShouldProcess($psdPath, "Deploy-Module")) { + if ($PSCmdlet.ShouldProcess($psdPath, "Invoke-DeployModule")) { "Deploying {0} {1} {2} to PSGallery ..." -f $($psd1.RootModule), $($psd1.ModuleVersion), $($psd1.PrivateData.pSData.Prerelease) | Write-Information # During testing we should use -WhatIf paarmetre when calling for deploy. # Just reach this point when testing call failure @@ -159,4 +159,4 @@ function Get-DeployModuleManifestPath { } else { $psdPath } -} +} \ No newline at end of file diff --git a/deploy.ps1 b/deploy.ps1 index fc30069..8c5fc0c 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -74,4 +74,3 @@ if ( [string]::IsNullOrWhiteSpace($NuGetApiKey) ) { # Deploy module to PSGallery Invoke-DeployModuleToPSGallery -NuGetApiKey $NuGetApiKey -Force - diff --git a/deploy_module_on_release.yml b/deploy_module_on_release.yml new file mode 100644 index 0000000..e73346b --- /dev/null +++ b/deploy_module_on_release.yml @@ -0,0 +1,48 @@ +name: Deploy on Release Published + +on: + workflow_dispatch: + release: + types: [published] + +permissions: + contents: read + +jobs: + deploy_to_powershellgallery: + runs-on: ubuntu-latest + environment: powershellgallery + steps: + - uses: actions/checkout@v3 + - env: + EVENT_CONTEXT: ${{ toJSON(github.event) }} + run: | + echo $EVENT_CONTEXT + + - name: deploy_ps1 + shell: pwsh + env: + NUGETAPIKEY: ${{ secrets.NUGETAPIKEY }} + EVENT_REF: ${{ github.event.ref }} + RELEASE_TAG: ${{ github.event.release.tag_name }} + RELEASE_NAME: ${{ github.event.release.name }} + run: | + $env:EVENT_REF = $env:REF + + If ([string]::IsNullOrEmpty($env:EVENT_REF)) { + # Release published trigger + $tag = $env:RELEASE_TAG + write-host -message "Release [$env:RELEASE_NAME] on tag [$tag]" + } else { + # Read Tag o Branch name + $tag = $env:EVENT_REF.Split('/')[2] + write-host "workflow_dispatch triggered on ref leaf [$tag]" + } + + If([string]::IsNullorwhitespace($tag)) { + # Tag name is empty, exit + write-error "Tag name is empty" + exit 1 + } + + ./deploy.ps1 -VersionTag $tag -NugetApiKey $env:NUGETAPIKEY diff --git a/private/templates/template.v3.PSScriptAnalyzer.yml b/powershell.yml similarity index 99% rename from private/templates/template.v3.PSScriptAnalyzer.yml rename to powershell.yml index 60bdec1..96d32d8 100644 --- a/private/templates/template.v3.PSScriptAnalyzer.yml +++ b/powershell.yml @@ -44,3 +44,4 @@ jobs: uses: github/codeql-action/upload-sarif@v2 with: sarif_file: results.sarif + diff --git a/private/templates/template.deploy.ps1 b/private/templates/template.deploy.ps1 index 12848fc..bf4de2f 100644 --- a/private/templates/template.deploy.ps1 +++ b/private/templates/template.deploy.ps1 @@ -70,10 +70,10 @@ if ($Force -and -not $Confirm){ } # Deploy the module with ShouldProcess (-whatif, -confirm) -if ($PSCmdlet.ShouldProcess($psdPath, "Deploy-Module")) { +if ($PSCmdlet.ShouldProcess($psdPath, "Publish-Module")) { $message ="Deploying {0} {1} {2} to PSGallery ..." -f $($psdPath.Name), $($psd1.ModuleVersion), $($psd1.PrivateData.pSData.Prerelease) # show an empty line Write-Information -InformationAction Continue -Message "" Write-Information -InformationAction Continue -Message $message - Deploy-Module -Name $psdPath -NuGetApiKey $NuGetApiKey -Force:$ForceDeploy + Publish-Module -Name $psdPath -NuGetApiKey $NuGetApiKey -Force:$ForceDeploy } \ No newline at end of file diff --git a/private/templates/template.test.ps1 b/private/templates/template.test.ps1 index 502a526..e2ac7d7 100644 --- a/private/templates/template.test.ps1 +++ b/private/templates/template.test.ps1 @@ -45,4 +45,4 @@ function Import-TestingHelper{ Import-TestingHelper -AllowPrerelease # Run test by PSD1 file -Invoke-TestingHelper +Test-ModulelocalPSD1 diff --git a/private/templates/template.v3.deploy-helper.ps1 b/private/templates/template.v3.deploy-helper.ps1 index 6d4e279..cb29901 100644 --- a/private/templates/template.v3.deploy-helper.ps1 +++ b/private/templates/template.v3.deploy-helper.ps1 @@ -55,7 +55,7 @@ function Invoke-DeployModuleToPSGallery{ } # Deploy the module with ShouldProcess (-whatif, -confirm) - if ($PSCmdlet.ShouldProcess($psdPath, "Deploy-Module")) { + if ($PSCmdlet.ShouldProcess($psdPath, "Invoke-DeployModule")) { "Deploying {0} {1} {2} to PSGallery ..." -f $($psd1.RootModule), $($psd1.ModuleVersion), $($psd1.PrivateData.pSData.Prerelease) | Write-Information # During testing we should use -WhatIf paarmetre when calling for deploy. # Just reach this point when testing call failure @@ -107,7 +107,7 @@ function Invoke-DeployModule { Force = $Force } - Deploy-Module @parameters + Publish-Module @parameters if($?){ Write-Information -MessageData "Deployed module [$Name] to PSGallery" @@ -159,4 +159,4 @@ function Get-DeployModuleManifestPath { } else { $psdPath } -} +} \ No newline at end of file diff --git a/private/templates/template.v3.deploy.ps1 b/private/templates/template.v3.deploy.ps1 index fc30069..d33a969 100644 --- a/private/templates/template.v3.deploy.ps1 +++ b/private/templates/template.v3.deploy.ps1 @@ -73,5 +73,4 @@ if ( [string]::IsNullOrWhiteSpace($NuGetApiKey) ) { } # Deploy module to PSGallery -Invoke-DeployModuleToPSGallery -NuGetApiKey $NuGetApiKey -Force - +Invoke-DeployModuleToPSGallery -NuGetApiKey $NuGetApiKey -Force \ No newline at end of file diff --git a/private/templates/template.v3.powershell.yml b/private/templates/template.v3.powershell.yml new file mode 100644 index 0000000..5a66b46 --- /dev/null +++ b/private/templates/template.v3.powershell.yml @@ -0,0 +1,46 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# +# https://github.com/microsoft/action-psscriptanalyzer +# For more information on PSScriptAnalyzer in general, see +# https://github.com/PowerShell/PSScriptAnalyzer + +name: PSScriptAnalyzer + +on: + workflow_dispatch: + pull_request: + +permissions: + contents: read + +jobs: + build: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + name: PSScriptAnalyzer + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Run PSScriptAnalyzer + uses: microsoft/psscriptanalyzer-action@v1.1 + with: + # Check https://github.com/microsoft/action-psscriptanalyzer for more info about the options. + # The below set up runs PSScriptAnalyzer to your entire repository and runs some basic security rules. + path: .\ + recurse: true + severity: 'Error' + # Include your own basic security rules. Removing this option will run all the rules + # includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"' + output: results.sarif + + # Upload the SARIF file generated in the previous step + - name: Upload SARIF results file + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: results.sarif \ No newline at end of file diff --git a/private/templates/template.v3.sync-helper.ps1 b/private/templates/template.v3.sync-helper.ps1 index 2bb714b..28354cb 100644 --- a/private/templates/template.v3.sync-helper.ps1 +++ b/private/templates/template.v3.sync-helper.ps1 @@ -31,8 +31,10 @@ function Out-ContentToFile { [Parameter(Mandatory=$true)][string]$filePath ) - if ($PSCmdlet.ShouldProcess($filePath, "Save content [{0}] to file" -f $content.Length)) { - $content | Out-File -FilePath $filePath -Force + process{ + if ($PSCmdlet.ShouldProcess($filePath, "Save content [{0}] to file" -f $content.Length)) { + $content | Out-File -FilePath $filePath -Force + } } } @@ -44,7 +46,12 @@ function Save-UrlContentToFile { ) $fileContent = Get-UrlContent -Url $url - $fileContent | Out-ContentToFile -FilePath $filePath - Write-Information -MessageData "Saved content to [$filePath] from [$url]" -} + if ([string]::IsNullOrWhiteSpace($fileContent)) { + Write-Error -Message "Content from [$url] is empty" + return + } else { + $fileContent | Out-ContentToFile -FilePath $filePath + Write-Information -MessageData "Saved content to [$filePath] from [$url]" + } +} \ No newline at end of file diff --git a/private/templates/template.v3.sync.ps1 b/private/templates/template.v3.sync.ps1 index 39831b4..4db95c9 100644 --- a/private/templates/template.v3.sync.ps1 +++ b/private/templates/template.v3.sync.ps1 @@ -1,21 +1,29 @@ <# .SYNOPSIS - Synchronizes TestingHelper templates files + Synchronizes with TestingHelper templates files .DESCRIPTION - Synchronizes TestingHelper templates to the local repo. + Synchronizes with 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 + https://raw.githubusercontent.com/rulasg/TestingHelper/main/sync.ps1 #> -[cmdletbinding()] +[cmdletbinding(SupportsShouldProcess)] 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/deploy.ps1' -FilePath 'deploy.ps1' -Save-UrlContentToFile -Url 'https://raw.githubusercontent.com/rulasg/DemoPsModule/main/deploy-helper.ps1' -FilePath 'deploy-helper.ps1' +Save-UrlContentToFile -FilePath 'deploy_module_on_release.yml' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy_module_on_release.yml' +Save-UrlContentToFile -FilePath 'powershell.yml' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.powershell.yml' +Save-UrlContentToFile -FilePath 'test_with_TestingHelper.yml' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.test_with_TestingHelper.yml' + +Save-UrlContentToFile -FilePath 'deploy-helper.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy-helper.ps1' +Save-UrlContentToFile -FilePath 'deploy.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy.ps1' + +Save-UrlContentToFile -FilePath 'sync-helper.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.sync-helper.ps1' +Save-UrlContentToFile -FilePath 'sync.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.sync.ps1' + +Save-UrlContentToFile -FilePath 'release.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.release.ps1' +Save-UrlContentToFile -FilePath 'test.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.test.ps1' \ No newline at end of file diff --git a/private/templates/template.v3.test.ps1 b/private/templates/template.v3.test.ps1 new file mode 100644 index 0000000..ff4e3bb --- /dev/null +++ b/private/templates/template.v3.test.ps1 @@ -0,0 +1,50 @@ +<# +.SYNOPSIS + Run tests +.DESCRIPTION + Run the unit test of the actual module +.NOTES + Using TestingHelper this script will search for a Test module and run the tests + This script will be referenced from launch.json to run the tests on VSCode +.LINK + https://raw.githubusercontent.com/rulasg/DemoPsModule/main/test.ps1 +.EXAMPLE + > ./test.ps1 +#> + +[CmdletBinding()] +param ( + #Switch ShowTestErrors + [Parameter()][switch]$ShowTestErrors +) + +function Import-TestingHelper{ + [CmdletBinding()] + param ( + [Parameter()][string]$Version, + [Parameter()][switch]$AllowPrerelease, + [Parameter()][switch]$PassThru + ) + + if ($Version) { + $V = $Version.Split('-') + $semVer = $V[0] + $AllowPrerelease = ($AllowPrerelease -or ($null -ne $V[1])) + } + + $module = Import-Module TestingHelper -PassThru -ErrorAction SilentlyContinue -RequiredVersion:$semVer + + if ($null -eq $module) { + $installed = Install-Module -Name TestingHelper -Force -AllowPrerelease:$AllowPrerelease -passThru -RequiredVersion:$Version + $module = Import-Module -Name $installed.Name -RequiredVersion ($installed.Version.Split('-')[0]) -Force -PassThru + } + + if ($PassThru) { + $module + } +} + +Import-TestingHelper -AllowPrerelease + +# Run test by PSD1 file +Invoke-TestingHelper -ShowTestErrors:$ShowTestErrors \ No newline at end of file diff --git a/public/Invoke-TestingHelper.ps1 b/public/Invoke-TestingHelper.ps1 index 04b6188..65ef05f 100644 --- a/public/Invoke-TestingHelper.ps1 +++ b/public/Invoke-TestingHelper.ps1 @@ -52,22 +52,15 @@ function Test-Module { $result | Add-Member -NotePropertyName "TestsName" -NotePropertyValue $functionsTestName $result | Add-Member -NotePropertyName "Tests" -NotePropertyValue $functionsTest.Length $result | Add-Member -NotePropertyName "Time" -NotePropertyValue $time - - # Display single line result - Write-Host -ForegroundColor DarkCyan - $TestingModuleName | Write-Host -ForegroundColor Green -NoNewline - " results - " | Write-Host -ForegroundColor DarkCyan -NoNewline - Out-SingleResultData -Name "Pass" -Value $result.Pass -Color "Yellow" - Out-SingleResultData -Name "Failed" -Value $result.Failed -Color "Red" - Out-SingleResultData -Name "Skipped" -Value $result.Skipped -Color "Yellow" - Out-SingleResultData -Name "NotImplemented" -Value $result.NotImplemented -Color "Red" - Write-Host -ForegroundColor DarkCyan - - # Displayy all results strucutre - $result - - # Save result to global variable - $global:ResultTestingHelper = $result + + # Save result to global variable + $global:ResultTestingHelper = $result + + # Displayy all results strucutre + $global:ResultTestingHelper | Write-Output + + # Display single line result + Show-ResultSingleLine -Result $result # unload testing module Remove-Module -Name $TestingModuleName -Force @@ -135,14 +128,14 @@ function Invoke-TestingHelper { $result | Add-Member -NotePropertyName "Tests" -NotePropertyValue $functionsTest.Length $result | Add-Member -NotePropertyName "Time" -NotePropertyValue $time - # Display single line result - Show-ResultSingleLine -Result $result - - # Displayy all results strucutre - $result - # Save result to global variable $global:ResultTestingHelper = $result + + # Displayy all results strucutre + $global:ResultTestingHelper | Write-Output + + # Display single line result + Show-ResultSingleLine -Result $result # unload testing module Remove-Module -Name $TestingModuleName -Force diff --git a/public/New-ModuleV3.ps1 b/public/New-ModuleV3.ps1 index a015a7b..4d99b85 100644 --- a/public/New-ModuleV3.ps1 +++ b/public/New-ModuleV3.ps1 @@ -141,7 +141,7 @@ function New-ModuleV3 { # Add PSScriptAnalyzer if($AddPSScriptAnalyzerWorkflow){ $destination = $modulePath | Join-Path -ChildPath ".github" -AdditionalChildPath "workflows" - Import-Template -Path $destination -File "PSScriptAnalyzer.yml" -Template "template.v3.PSScriptAnalyzer.yml" + Import-Template -Path $destination -File "powershell.yml" -Template "template.v3.powershell.yml" } # Add Testing diff --git a/sync-helper.ps1 b/sync-helper.ps1 index b57868a..7fe6558 100644 --- a/sync-helper.ps1 +++ b/sync-helper.ps1 @@ -31,7 +31,7 @@ function Out-ContentToFile { [Parameter(Mandatory=$true)][string]$filePath ) - process { + process{ if ($PSCmdlet.ShouldProcess($filePath, "Save content [{0}] to file" -f $content.Length)) { $content | Out-File -FilePath $filePath -Force @@ -47,7 +47,12 @@ function Save-UrlContentToFile { ) $fileContent = Get-UrlContent -Url $url - $fileContent | Out-ContentToFile -FilePath $filePath - Write-Information -MessageData "Saved content to [$filePath] from [$url]" -} + if ([string]::IsNullOrWhiteSpace($fileContent)) { + Write-Error -Message "Content from [$url] is empty" + return + } else { + $fileContent | Out-ContentToFile -FilePath $filePath + Write-Information -MessageData "Saved content to [$filePath] from [$url]" + } +} \ No newline at end of file diff --git a/sync.ps1 b/sync.ps1 index 39831b4..04f60a1 100644 --- a/sync.ps1 +++ b/sync.ps1 @@ -1,21 +1,29 @@ <# .SYNOPSIS - Synchronizes TestingHelper templates files + Synchronizes with TestingHelper templates files .DESCRIPTION - Synchronizes TestingHelper templates to the local repo. + Synchronizes with 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 + https://raw.githubusercontent.com/rulasg/TestingHelper/main/sync.ps1 #> -[cmdletbinding()] +[cmdletbinding(SupportsShouldProcess)] 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/deploy.ps1' -FilePath 'deploy.ps1' -Save-UrlContentToFile -Url 'https://raw.githubusercontent.com/rulasg/DemoPsModule/main/deploy-helper.ps1' -FilePath 'deploy-helper.ps1' +Save-UrlContentToFile -FilePath 'deploy_module_on_release.yml' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy_module_on_release.yml' +Save-UrlContentToFile -FilePath 'powershell.yml' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.powershell.yml' +Save-UrlContentToFile -FilePath 'test_with_TestingHelper.yml' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.test_with_TestingHelper.yml' + +Save-UrlContentToFile -FilePath 'deploy-helper.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy-helper.ps1' +Save-UrlContentToFile -FilePath 'deploy.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy.ps1' + +Save-UrlContentToFile -FilePath 'sync-helper.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.sync-helper.ps1' +Save-UrlContentToFile -FilePath 'sync.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.sync.ps1' + +Save-UrlContentToFile -FilePath 'release.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.release.ps1' +Save-UrlContentToFile -FilePath 'test.ps1' -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.test.ps1' \ No newline at end of file diff --git a/test.ps1 b/test.ps1 index a3f9122..ff4e3bb 100644 --- a/test.ps1 +++ b/test.ps1 @@ -14,6 +14,7 @@ [CmdletBinding()] param ( + #Switch ShowTestErrors [Parameter()][switch]$ShowTestErrors ) @@ -24,7 +25,7 @@ function Import-TestingHelper{ [Parameter()][switch]$AllowPrerelease, [Parameter()][switch]$PassThru ) - + if ($Version) { $V = $Version.Split('-') $semVer = $V[0] @@ -46,6 +47,4 @@ function Import-TestingHelper{ Import-TestingHelper -AllowPrerelease # Run test by PSD1 file -# Test-ModulelocalPSD1 is Obsolete. -# Switch to Invoke-TestingHelper as soon as a deplyed version has this function -Test-ModulelocalPSD1 \ No newline at end of file +Invoke-TestingHelper -ShowTestErrors:$ShowTestErrors \ No newline at end of file diff --git a/test_with_TestingHelper.yml b/test_with_TestingHelper.yml new file mode 100644 index 0000000..d08b89d --- /dev/null +++ b/test_with_TestingHelper.yml @@ -0,0 +1,45 @@ +# This is a workflow to test you PowerShell module with TestingHelper +# https://github.com/rulasg/DemoPsModule/blob/main/.github/workflows/test_with_TestingHelper.yml + +name: Test with TestingHelper + +# Controls when the workflow will run +on: + + # Run as check on pull request + pull_request: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +permissions: + # To run test we only need to read the repository + contents: read + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + test: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Runs a single command using the runners shell + - name: Run test.ps1 + shell: pwsh + run: | + $result = ./test.ps1 -ShowTestErrors + $result + + # Allow Not Implemented and Skipped tests to pass + $passed = $result.Tests -eq $result.Pass + $result.NotImplemented + $result.Skipped + # $passed = $result.Tests -eq $result.Pass + + if($passed) + { "All test passed" | Write-Verbose -verbose ; exit 0 } + else + { "Not all tests passed" | Write-Verbose -verbose ; exit 1 }