Skip to content

Commit

Permalink
Merge pull request #17 from StartAutomating/Splatter-Updates
Browse files Browse the repository at this point in the history
Splatter 0.5.4
  • Loading branch information
StartAutomating committed May 9, 2023
2 parents 32310b1 + 6e5e545 commit b866d46
Show file tree
Hide file tree
Showing 31 changed files with 2,001 additions and 85 deletions.
194 changes: 159 additions & 35 deletions .github/workflows/TestBuildAndPublish.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

name: Test Build And Publish

name: Analyze, Test, Tag, and Publish
on:
workflow_dispatch:
push:
pull_request:
workflow_dispatch:
jobs:
PowerShellStaticAnalysis:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -124,6 +125,8 @@ jobs:
$Parameters = @{}
$Parameters.ModulePath = ${env:ModulePath}
$Parameters.PesterMaxVersion = ${env:PesterMaxVersion}
$Parameters.NoCoverage = ${env:NoCoverage}
$Parameters.NoCoverage = $parameters.NoCoverage -match 'true';
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
Expand All @@ -142,7 +145,11 @@ jobs:
$ModulePath,
# The Pester max version. By default, this is pinned to 4.99.99.
[string]
$PesterMaxVersion = '4.99.99'
$PesterMaxVersion = '4.99.99',
# If set, will not collect code coverage.
[switch]
$NoCoverage
)
$global:ErrorActionPreference = 'continue'
Expand All @@ -154,11 +161,18 @@ jobs:
$importedModule = Import-Module $ModulePath -Force -PassThru
$importedPester, $importedModule | Out-Host
$codeCoverageParameters = @{
CodeCoverage = "$($importedModule | Split-Path)\*-*.ps1"
CodeCoverageOutputFile = ".\$moduleName.Coverage.xml"
}
if ($NoCoverage) {
$codeCoverageParameters = @{}
}
$result =
Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml `
-CodeCoverage "$($importedModule | Split-Path)\*-*.ps1" -CodeCoverageOutputFile ".\$moduleName.Coverage.xml"
Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml @codeCoverageParameters
"::set-output name=TotalCount::$($result.TotalCount)",
"::set-output name=PassedCount::$($result.PassedCount)",
Expand Down Expand Up @@ -238,7 +252,7 @@ jobs:
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
(-not $gitHubEvent.psobject.properties['inputs'])) {
"::warning::Pull Request has not merged, skipping" | Out-Host
"::warning::Pull Request has not merged, skipping Tagging" | Out-Host
return
}
Expand Down Expand Up @@ -291,6 +305,9 @@ jobs:
$Parameters.UserEmail = ${env:UserEmail}
$Parameters.UserName = ${env:UserName}
$Parameters.TagVersionFormat = ${env:TagVersionFormat}
$Parameters.ReleaseNameFormat = ${env:ReleaseNameFormat}
$Parameters.ReleaseAsset = ${env:ReleaseAsset}
$Parameters.ReleaseAsset = $parameters.ReleaseAsset -split ';' -replace '^[''"]' -replace '[''"]$'
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
Expand All @@ -312,7 +329,15 @@ jobs:
# The tag version format (default value: 'v$(imported.Version)')
# This can expand variables. $imported will contain the imported module.
[string]
$TagVersionFormat = 'v$($imported.Version)'
$TagVersionFormat = 'v$($imported.Version)',
# The release name format (default value: '$($imported.Name) $($imported.Version)')
[string]
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)',
# Any assets to attach to the release. Can be a wildcard or file name.
[string[]]
$ReleaseAsset
)
Expand All @@ -329,7 +354,7 @@ jobs:
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
(-not $gitHubEvent.psobject.properties['inputs'])) {
"::warning::Pull Request has not merged, skipping" | Out-Host
"::warning::Pull Request has not merged, skipping GitHub release" | Out-Host
return
}
Expand All @@ -348,6 +373,7 @@ jobs:
$targetVersion =$ExecutionContext.InvokeCommand.ExpandString($TagVersionFormat)
$targetReleaseName = $targetVersion
$releasesURL = 'https://api.github.com/repos/${{github.repository}}/releases'
"Release URL: $releasesURL" | Out-Host
$listOfReleases = Invoke-RestMethod -Uri $releasesURL -Method Get -Headers @{
"Accept" = "application/vnd.github.v3+json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
Expand All @@ -357,39 +383,89 @@ jobs:
if ($releaseExists) {
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
return
$releasedIt = $releaseExists
} else {
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
[Ordered]@{
owner = '${{github.owner}}'
repo = '${{github.repository}}'
tag_name = $targetVersion
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
body =
if ($env:RELEASENOTES) {
$env:RELEASENOTES
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
$imported.PrivateData.PSData.ReleaseNotes
} else {
"$($imported.Name) $targetVersion"
}
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
} | ConvertTo-Json
) -Headers @{
"Accept" = "application/vnd.github.v3+json"
"Content-type" = "application/json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
}
}
Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
[Ordered]@{
owner = '${{github.owner}}'
repo = '${{github.repository}}'
tag_name = $targetVersion
name = "$($imported.Name) $targetVersion"
body =
if ($env:RELEASENOTES) {
$env:RELEASENOTES
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
$imported.PrivateData.PSData.ReleaseNotes
} else {
"$($imported.Name) $targetVersion"
if (-not $releasedIt) {
throw "Release failed"
} else {
$releasedIt | Out-Host
}
$releaseUploadUrl = $releasedIt.upload_url -replace '\{.+$'
if ($ReleaseAsset) {
$fileList = Get-ChildItem -Recurse
$filesToRelease =
@(:nextFile foreach ($file in $fileList) {
foreach ($relAsset in $ReleaseAsset) {
if ($relAsset -match '[\*\?]') {
if ($file.Name -like $relAsset) {
$file; continue nextFile
}
} elseif ($file.Name -eq $relAsset -or $file.FullName -eq $relAsset) {
$file; continue nextFile
}
}
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
} | ConvertTo-Json
) -Headers @{
"Accept" = "application/vnd.github.v3+json"
"Content-type" = "application/json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
})
$releasedFiles = @{}
foreach ($file in $filesToRelease) {
if ($releasedFiles[$file.Name]) {
Write-Warning "Already attached file $($file.Name)"
continue
} else {
$fileBytes = [IO.File]::ReadAllBytes($file.FullName)
$releasedFiles[$file.Name] =
Invoke-RestMethod -Uri "${releaseUploadUrl}?name=$($file.Name)" -Headers @{
"Accept" = "application/vnd.github+json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
} -Body $fileBytes -ContentType Application/octet-stream
$releasedFiles[$file.Name]
}
}
"Attached $($releasedFiles.Count) file(s) to release" | Out-Host
}
} @Parameters
- name: PublishPowerShellGallery
id: PublishPowerShellGallery
shell: pwsh
run: |
$Parameters = @{}
$Parameters.ModulePath = ${env:ModulePath}
$Parameters.Exclude = ${env:Exclude}
$Parameters.Exclude = $parameters.Exclude -split ';' -replace '^[''"]' -replace '[''"]$'
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
Expand All @@ -398,22 +474,36 @@ jobs:
Write-Host "::debug:: PublishPowerShellGallery $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
& {param(
[string]
$ModulePath
$ModulePath,
[string[]]
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif', 'docs[/\]*')
)
$gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
} else { $null }
if (-not $Exclude) {
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif','docs[/\]*')
}
@"
::group::GitHubEvent
$($gitHubEvent | ConvertTo-Json -Depth 100)
::endgroup::
"@ | Out-Host
@"
::group::PSBoundParameters
$($PSBoundParameters | ConvertTo-Json -Depth 100)
::endgroup::
"@ | Out-Host
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
(-not $gitHubEvent.psobject.properties['inputs'])) {
"::warning::Pull Request has not merged, skipping" | Out-Host
"::warning::Pull Request has not merged, skipping Gallery Publish" | Out-Host
return
}
Expand All @@ -428,9 +518,9 @@ jobs:
if (-not $imported) { return }
$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue } catch {}
$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue} catch {}
if ($foundModule -and $foundModule.Version -ge $imported.Version) {
if ($foundModule -and (([Version]$foundModule.Version) -ge ([Version]$imported.Version))) {
"::warning::Gallery Version of $moduleName is more recent ($($foundModule.Version) >= $($imported.Version))" | Out-Host
} else {
Expand All @@ -453,9 +543,24 @@ jobs:
if (Test-Path $moduleGitPath) {
Remove-Item -Recurse -Force $moduleGitPath
}
if ($Exclude) {
"::notice::Attempting to Exlcude $exclude" | Out-Host
Get-ChildItem $moduleTempPath -Recurse |
Where-Object {
foreach ($ex in $exclude) {
if ($_.FullName -like $ex) {
"::notice::Excluding $($_.FullName)" | Out-Host
return $true
}
}
} |
Remove-Item
}
Write-Host "Module Files:"
Get-ChildItem $moduleTempPath -Recurse
Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
Publish-Module -Path $moduleTempPath -NuGetApiKey $gk
if ($?) {
Write-Host "Published to Gallery"
Expand All @@ -465,4 +570,23 @@ jobs:
}
}
} @Parameters
BuildSplatter:
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: GitLogger
uses: GitLogging/GitLoggerAction@main
id: GitLogger
- name: Use PSSVG Action
uses: StartAutomating/PSSVG@main
id: PSSVG
- name: BuildPipeScript
uses: StartAutomating/PipeScript@main
- name: UseEZOut
uses: StartAutomating/EZOut@master
- name: Run HelpOut
uses: StartAutomating/HelpOut@master
id: HelpOut

Binary file removed Assets/Splatter-16x9.png
Binary file not shown.
Binary file modified Assets/Splatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Assets/Splatter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Build/Splatter.GitHubWorkflow.PSDevOps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#requires -Module PSDevOps
Import-BuildStep -ModuleName Splatter
Push-Location ($PSScriptRoot | Split-Path)
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis,
TestPowerShellOnLinux,
TagReleaseAndPublish,
BuildSplatter -OutputPath .\.github\workflows\TestBuildAndPublish.yml
Pop-Location
16 changes: 16 additions & 0 deletions Build/Splatter.HelpOut.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#require -Module HelpOut
Push-Location ($PSScriptRoot | Split-Path)

$SplatterLoaded = Get-Module Splatter
if (-not $SplatterLoaded) {
$SplatterLoaded = Get-ChildItem -Recurse -Filter "*.psd1" | Where-Object Name -like 'Splatter*' | Import-Module -Name { $_.FullName } -Force -PassThru
}
if ($SplatterLoaded) {
"::notice title=ModuleLoaded::Splatter Loaded" | Out-Host
} else {
"::error:: Splatter not loaded" |Out-Host
}

Save-MarkdownHelp -Module Splatter -SkipCommandType Alias -PassThru

Pop-Location
Loading

0 comments on commit b866d46

Please sign in to comment.