1-
2- name : Test Build And Publish
1+
2+ name : Analyze, Test, Tag, and Publish
33on :
4- workflow_dispatch :
54 push :
5+ pull_request :
6+ workflow_dispatch :
67jobs :
78 PowerShellStaticAnalysis :
89 runs-on : ubuntu-latest
@@ -124,6 +125,8 @@ jobs:
124125 $Parameters = @{}
125126 $Parameters.ModulePath = ${env:ModulePath}
126127 $Parameters.PesterMaxVersion = ${env:PesterMaxVersion}
128+ $Parameters.NoCoverage = ${env:NoCoverage}
129+ $Parameters.NoCoverage = $parameters.NoCoverage -match 'true';
127130 foreach ($k in @($parameters.Keys)) {
128131 if ([String]::IsNullOrEmpty($parameters[$k])) {
129132 $parameters.Remove($k)
@@ -142,7 +145,11 @@ jobs:
142145 $ModulePath,
143146 # The Pester max version. By default, this is pinned to 4.99.99.
144147 [string]
145- $PesterMaxVersion = '4.99.99'
148+ $PesterMaxVersion = '4.99.99',
149+
150+ # If set, will not collect code coverage.
151+ [switch]
152+ $NoCoverage
146153 )
147154
148155 $global:ErrorActionPreference = 'continue'
@@ -154,11 +161,18 @@ jobs:
154161 $importedModule = Import-Module $ModulePath -Force -PassThru
155162 $importedPester, $importedModule | Out-Host
156163
164+ $codeCoverageParameters = @{
165+ CodeCoverage = "$($importedModule | Split-Path)\*-*.ps1"
166+ CodeCoverageOutputFile = ".\$moduleName.Coverage.xml"
167+ }
168+
169+ if ($NoCoverage) {
170+ $codeCoverageParameters = @{}
171+ }
157172
158173
159174 $result =
160- Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml `
161- -CodeCoverage "$($importedModule | Split-Path)\*-*.ps1" -CodeCoverageOutputFile ".\$moduleName.Coverage.xml"
175+ Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml @codeCoverageParameters
162176
163177 "::set-output name=TotalCount::$($result.TotalCount)",
164178 "::set-output name=PassedCount::$($result.PassedCount)",
@@ -238,7 +252,7 @@ jobs:
238252
239253 if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
240254 (-not $gitHubEvent.psobject.properties['inputs'])) {
241- "::warning::Pull Request has not merged, skipping" | Out-Host
255+ "::warning::Pull Request has not merged, skipping Tagging " | Out-Host
242256 return
243257 }
244258
@@ -291,6 +305,9 @@ jobs:
291305 $Parameters.UserEmail = ${env:UserEmail}
292306 $Parameters.UserName = ${env:UserName}
293307 $Parameters.TagVersionFormat = ${env:TagVersionFormat}
308+ $Parameters.ReleaseNameFormat = ${env:ReleaseNameFormat}
309+ $Parameters.ReleaseAsset = ${env:ReleaseAsset}
310+ $Parameters.ReleaseAsset = $parameters.ReleaseAsset -split ';' -replace '^[''"]' -replace '[''"]$'
294311 foreach ($k in @($parameters.Keys)) {
295312 if ([String]::IsNullOrEmpty($parameters[$k])) {
296313 $parameters.Remove($k)
@@ -312,7 +329,15 @@ jobs:
312329 # The tag version format (default value: 'v$(imported.Version)')
313330 # This can expand variables. $imported will contain the imported module.
314331 [string]
315- $TagVersionFormat = 'v$($imported.Version)'
332+ $TagVersionFormat = 'v$($imported.Version)',
333+
334+ # The release name format (default value: '$($imported.Name) $($imported.Version)')
335+ [string]
336+ $ReleaseNameFormat = '$($imported.Name) $($imported.Version)',
337+
338+ # Any assets to attach to the release. Can be a wildcard or file name.
339+ [string[]]
340+ $ReleaseAsset
316341 )
317342
318343
@@ -329,7 +354,7 @@ jobs:
329354
330355 if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
331356 (-not $gitHubEvent.psobject.properties['inputs'])) {
332- "::warning::Pull Request has not merged, skipping" | Out-Host
357+ "::warning::Pull Request has not merged, skipping GitHub release " | Out-Host
333358 return
334359 }
335360
@@ -348,6 +373,7 @@ jobs:
348373 $targetVersion =$ExecutionContext.InvokeCommand.ExpandString($TagVersionFormat)
349374 $targetReleaseName = $targetVersion
350375 $releasesURL = 'https://api.github.com/repos/${{github.repository}}/releases'
376+ "Release URL: $releasesURL" | Out-Host
351377 $listOfReleases = Invoke-RestMethod -Uri $releasesURL -Method Get -Headers @{
352378 "Accept" = "application/vnd.github.v3+json"
353379 "Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
@@ -357,39 +383,89 @@ jobs:
357383
358384 if ($releaseExists) {
359385 "::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
360- return
386+ $releasedIt = $releaseExists
387+ } else {
388+ $releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
389+ [Ordered]@{
390+ owner = '${{github.owner}}'
391+ repo = '${{github.repository}}'
392+ tag_name = $targetVersion
393+ name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
394+ body =
395+ if ($env:RELEASENOTES) {
396+ $env:RELEASENOTES
397+ } elseif ($imported.PrivateData.PSData.ReleaseNotes) {
398+ $imported.PrivateData.PSData.ReleaseNotes
399+ } else {
400+ "$($imported.Name) $targetVersion"
401+ }
402+ draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
403+ prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
404+ } | ConvertTo-Json
405+ ) -Headers @{
406+ "Accept" = "application/vnd.github.v3+json"
407+ "Content-type" = "application/json"
408+ "Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
409+ }
361410 }
362411
363412
364- Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
365- [Ordered]@{
366- owner = '${{github.owner}}'
367- repo = '${{github.repository}}'
368- tag_name = $targetVersion
369- name = "$($imported.Name) $targetVersion"
370- body =
371- if ($env:RELEASENOTES) {
372- $env:RELEASENOTES
373- } elseif ($imported.PrivateData.PSData.ReleaseNotes) {
374- $imported.PrivateData.PSData.ReleaseNotes
375- } else {
376- "$($imported.Name) $targetVersion"
413+
414+
415+
416+ if (-not $releasedIt) {
417+ throw "Release failed"
418+ } else {
419+ $releasedIt | Out-Host
420+ }
421+
422+ $releaseUploadUrl = $releasedIt.upload_url -replace '\{.+$'
423+
424+ if ($ReleaseAsset) {
425+ $fileList = Get-ChildItem -Recurse
426+ $filesToRelease =
427+ @(:nextFile foreach ($file in $fileList) {
428+ foreach ($relAsset in $ReleaseAsset) {
429+ if ($relAsset -match '[\*\?]') {
430+ if ($file.Name -like $relAsset) {
431+ $file; continue nextFile
432+ }
433+ } elseif ($file.Name -eq $relAsset -or $file.FullName -eq $relAsset) {
434+ $file; continue nextFile
435+ }
377436 }
378- draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
379- prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
380- } | ConvertTo-Json
381- ) -Headers @{
382- "Accept" = "application/vnd.github.v3+json"
383- "Content-type" = "application/json"
384- "Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
437+ })
438+
439+ $releasedFiles = @{}
440+ foreach ($file in $filesToRelease) {
441+ if ($releasedFiles[$file.Name]) {
442+ Write-Warning "Already attached file $($file.Name)"
443+ continue
444+ } else {
445+ $fileBytes = [IO.File]::ReadAllBytes($file.FullName)
446+ $releasedFiles[$file.Name] =
447+ Invoke-RestMethod -Uri "${releaseUploadUrl}?name=$($file.Name)" -Headers @{
448+ "Accept" = "application/vnd.github+json"
449+ "Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
450+ } -Body $fileBytes -ContentType Application/octet-stream
451+ $releasedFiles[$file.Name]
452+ }
453+ }
454+
455+ "Attached $($releasedFiles.Count) file(s) to release" | Out-Host
385456 }
457+
458+
459+
386460 } @Parameters
387461 - name : PublishPowerShellGallery
388462 id : PublishPowerShellGallery
389463 shell : pwsh
390464 run : |
391465 $Parameters = @{}
392466 $Parameters.ModulePath = ${env:ModulePath}
467+ $Parameters.Exclude = ${env:Exclude}
468+ $Parameters.Exclude = $parameters.Exclude -split ';' -replace '^[''"]' -replace '[''"]$'
393469 foreach ($k in @($parameters.Keys)) {
394470 if ([String]::IsNullOrEmpty($parameters[$k])) {
395471 $parameters.Remove($k)
@@ -398,22 +474,36 @@ jobs:
398474 Write-Host "::debug:: PublishPowerShellGallery $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
399475 & {param(
400476 [string]
401- $ModulePath
477+ $ModulePath,
478+
479+ [string[]]
480+ $Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif', 'docs[/\]*')
402481 )
482+
403483 $gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
404484 [IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
405485 } else { $null }
406486
487+ if (-not $Exclude) {
488+ $Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif','docs[/\]*')
489+ }
490+
407491
408492 @"
409493 ::group::GitHubEvent
410494 $($gitHubEvent | ConvertTo-Json -Depth 100)
411495 ::endgroup::
412496 "@ | Out-Host
413497
498+ @"
499+ ::group::PSBoundParameters
500+ $($PSBoundParameters | ConvertTo-Json -Depth 100)
501+ ::endgroup::
502+ "@ | Out-Host
503+
414504 if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
415505 (-not $gitHubEvent.psobject.properties['inputs'])) {
416- "::warning::Pull Request has not merged, skipping" | Out-Host
506+ "::warning::Pull Request has not merged, skipping Gallery Publish " | Out-Host
417507 return
418508 }
419509
@@ -428,9 +518,9 @@ jobs:
428518
429519 if (-not $imported) { return }
430520
431- $foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue } catch {}
521+ $foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue} catch {}
432522
433- if ($foundModule -and $foundModule.Version -ge $imported.Version) {
523+ if ($foundModule -and (([Version] $foundModule.Version) -ge ([Version] $imported.Version)) ) {
434524 "::warning::Gallery Version of $moduleName is more recent ($($foundModule.Version) >= $($imported.Version))" | Out-Host
435525 } else {
436526
@@ -453,9 +543,24 @@ jobs:
453543 if (Test-Path $moduleGitPath) {
454544 Remove-Item -Recurse -Force $moduleGitPath
455545 }
546+
547+ if ($Exclude) {
548+ "::notice::Attempting to Exlcude $exclude" | Out-Host
549+ Get-ChildItem $moduleTempPath -Recurse |
550+ Where-Object {
551+ foreach ($ex in $exclude) {
552+ if ($_.FullName -like $ex) {
553+ "::notice::Excluding $($_.FullName)" | Out-Host
554+ return $true
555+ }
556+ }
557+ } |
558+ Remove-Item
559+ }
560+
456561 Write-Host "Module Files:"
457562 Get-ChildItem $moduleTempPath -Recurse
458- Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
563+ Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
459564 Publish-Module -Path $moduleTempPath -NuGetApiKey $gk
460565 if ($?) {
461566 Write-Host "Published to Gallery"
@@ -465,4 +570,23 @@ jobs:
465570 }
466571 }
467572 } @Parameters
573+ BuildSplatter :
574+ runs-on : ubuntu-latest
575+ if : ${{ success() }}
576+ steps :
577+ - name : Check out repository
578+ uses : actions/checkout@v2
579+ - name : GitLogger
580+ uses : GitLogging/GitLoggerAction@main
581+ id : GitLogger
582+ - name : Use PSSVG Action
583+ uses : StartAutomating/PSSVG@main
584+ id : PSSVG
585+ - name : BuildPipeScript
586+ uses : StartAutomating/PipeScript@main
587+ - name : UseEZOut
588+ uses : StartAutomating/EZOut@master
589+ - name : Run HelpOut
590+ uses : StartAutomating/HelpOut@master
591+ id : HelpOut
468592
0 commit comments