Skip to content

Commit ec4a74f

Browse files
Merge pull request #18 from StartAutomating/Eventful-Improvements
Eventful improvements
2 parents 0811bd1 + 08e24d6 commit ec4a74f

15 files changed

+343
-52
lines changed

.github/workflows/OnIssue.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
name: OnIssueChanged
3+
on:
4+
issues:
5+
workflow_dispatch:
6+
jobs:
7+
RunGitPub:
8+
runs-on: ubuntu-latest
9+
if: ${{ success() }}
10+
steps:
11+
- name: Check out repository
12+
uses: actions/checkout@v2
13+
- name: Use GitPub Action
14+
uses: StartAutomating/GitPub@main
15+
id: GitPub
16+
with:
17+
TargetBranch: edits-$([DateTime]::Now.ToString("r").Replace(":","-").Replace(" ", ""))
18+
CommitMessage: Posting with GitPub [skip ci]
19+
PublishParameters: |
20+
{
21+
"Get-GitPubIssue": {
22+
"Repository": '${{github.repository}}',
23+
},
24+
"Get-GitPubRelease": {
25+
"Repository": '${{github.repository}}',
26+
},
27+
"Publish-GitPubJekyll": {
28+
"OutputPath": "docs/_posts"
29+
}
30+
}
31+

.github/workflows/TestAndPublish.yml

Lines changed: 119 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ jobs:
306306
$Parameters.UserName = ${env:UserName}
307307
$Parameters.TagVersionFormat = ${env:TagVersionFormat}
308308
$Parameters.ReleaseNameFormat = ${env:ReleaseNameFormat}
309+
$Parameters.ReleaseAsset = ${env:ReleaseAsset}
310+
$Parameters.ReleaseAsset = $parameters.ReleaseAsset -split ';' -replace '^[''"]' -replace '[''"]$'
309311
foreach ($k in @($parameters.Keys)) {
310312
if ([String]::IsNullOrEmpty($parameters[$k])) {
311313
$parameters.Remove($k)
@@ -331,7 +333,11 @@ jobs:
331333
332334
# The release name format (default value: '$($imported.Name) $($imported.Version)')
333335
[string]
334-
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)'
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
335341
)
336342
337343
@@ -377,39 +383,89 @@ jobs:
377383
378384
if ($releaseExists) {
379385
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
380-
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+
}
381410
}
382411
383412
384-
Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
385-
[Ordered]@{
386-
owner = '${{github.owner}}'
387-
repo = '${{github.repository}}'
388-
tag_name = $targetVersion
389-
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
390-
body =
391-
if ($env:RELEASENOTES) {
392-
$env:RELEASENOTES
393-
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
394-
$imported.PrivateData.PSData.ReleaseNotes
395-
} else {
396-
"$($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+
}
397436
}
398-
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
399-
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
400-
} | ConvertTo-Json
401-
) -Headers @{
402-
"Accept" = "application/vnd.github.v3+json"
403-
"Content-type" = "application/json"
404-
"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
405456
}
457+
458+
459+
406460
} @Parameters
407461
- name: PublishPowerShellGallery
408462
id: PublishPowerShellGallery
409463
shell: pwsh
410464
run: |
411465
$Parameters = @{}
412466
$Parameters.ModulePath = ${env:ModulePath}
467+
$Parameters.Exclude = ${env:Exclude}
468+
$Parameters.Exclude = $parameters.Exclude -split ';' -replace '^[''"]' -replace '[''"]$'
413469
foreach ($k in @($parameters.Keys)) {
414470
if ([String]::IsNullOrEmpty($parameters[$k])) {
415471
$parameters.Remove($k)
@@ -418,19 +474,33 @@ jobs:
418474
Write-Host "::debug:: PublishPowerShellGallery $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
419475
& {param(
420476
[string]
421-
$ModulePath
477+
$ModulePath,
478+
479+
[string[]]
480+
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif', 'docs[/\]*')
422481
)
482+
423483
$gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
424484
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
425485
} else { $null }
426486
487+
if (-not $Exclude) {
488+
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif','docs[/\]*')
489+
}
490+
427491
428492
@"
429493
::group::GitHubEvent
430494
$($gitHubEvent | ConvertTo-Json -Depth 100)
431495
::endgroup::
432496
"@ | Out-Host
433497
498+
@"
499+
::group::PSBoundParameters
500+
$($PSBoundParameters | ConvertTo-Json -Depth 100)
501+
::endgroup::
502+
"@ | Out-Host
503+
434504
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
435505
(-not $gitHubEvent.psobject.properties['inputs'])) {
436506
"::warning::Pull Request has not merged, skipping Gallery Publish" | Out-Host
@@ -448,9 +518,9 @@ jobs:
448518
449519
if (-not $imported) { return }
450520
451-
$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue } catch {}
521+
$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue} catch {}
452522
453-
if ($foundModule -and $foundModule.Version -ge $imported.Version) {
523+
if ($foundModule -and (([Version]$foundModule.Version) -ge ([Version]$imported.Version))) {
454524
"::warning::Gallery Version of $moduleName is more recent ($($foundModule.Version) >= $($imported.Version))" | Out-Host
455525
} else {
456526
@@ -473,9 +543,24 @@ jobs:
473543
if (Test-Path $moduleGitPath) {
474544
Remove-Item -Recurse -Force $moduleGitPath
475545
}
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+
476561
Write-Host "Module Files:"
477562
Get-ChildItem $moduleTempPath -Recurse
478-
Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
563+
Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
479564
Publish-Module -Path $moduleTempPath -NuGetApiKey $gk
480565
if ($?) {
481566
Write-Host "Published to Gallery"
@@ -485,24 +570,20 @@ jobs:
485570
}
486571
}
487572
} @Parameters
488-
HelpOut:
489-
runs-on: ubuntu-latest
490-
if: ${{ success() }}
491-
steps:
492-
- name: Check out repository
493-
uses: actions/checkout@v2
494-
- name: UseHelpOut
495-
uses: StartAutomating/HelpOut@master
496-
RunEZOut:
573+
BuildEventful:
497574
runs-on: ubuntu-latest
498575
if: ${{ success() }}
499576
steps:
500577
- name: Check out repository
501578
uses: actions/checkout@v2
579+
- name: Use PSSVG Action
580+
uses: StartAutomating/PSSVG@main
581+
id: PSSVG
582+
- name: BuildPipeScript
583+
uses: StartAutomating/PipeScript@main
502584
- name: UseEZOut
503585
uses: StartAutomating/EZOut@master
504-
- name: Push Changes
505-
shell: pwsh
506-
run: git push; exit 0
586+
- name: UseHelpOut
587+
uses: StartAutomating/HelpOut@master
507588
env:
508589
NoCoverage: true

Assets/Eventful.svg

Lines changed: 11 additions & 0 deletions
Loading

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.1.7
2+
* Adding On@CommandNotFound event source (Fixes #11)
3+
* Watch-Event now allows eventsources -recursively (Fixes #15)
4+
5+
---
6+
17
## 0.1.6
28
* Adding LocationChanged event source (Fixes #12)
39

EventSources/@CommandNotFound.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<#
2+
.Synopsis
3+
Sends events when a command is not found.
4+
.Description
5+
Sends events when a command is not found.
6+
7+
Handling this event can resolve any unknown command.
8+
.EXAMPLE
9+
On@CommandNotFound
10+
.EXAMPLE
11+
On@CommandNotFound -Then { $event | Out-Host }
12+
#>
13+
param()
14+
15+
process {
16+
$global:ExecutionContext.SessionState.InvokeCommand.CommandNotFoundAction = {
17+
New-Event -SourceIdentifier "PowerShell.CommandNotFound" -MessageData $notFoundArgs -Sender $global:ExecutionContext -EventArguments $notFoundArgs
18+
}
19+
20+
[PSCustomObject]@{
21+
SourceIdentifier = "PowerShell.CommandNotFound"
22+
}
23+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#requires -Module PSDevOps
2-
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, HelpOut, RunEZOut -Environment @{
2+
Import-BuildStep -Module Eventful
3+
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, BuildEventful -Environment @{
34
NoCoverage = $true
45
}|
56
Set-Content .\.github\workflows\TestAndPublish.yml -Encoding UTF8 -PassThru
7+
8+
New-GitHubWorkflow -On Issue, Demand -Job RunGitPub -Name OnIssueChanged |
9+
Set-Content (Join-Path $PSScriptRoot .github\workflows\OnIssue.yml) -Encoding UTF8 -PassThru
10+

Eventful.PSSVG.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#requires -Module PSSVG
2+
3+
$assetsPath = Join-Path $PSScriptRoot Assets
4+
5+
if (-not (Test-Path $assetsPath)) {
6+
$null = New-Item -ItemType Directory -path $assetsPath -Force
7+
}
8+
=<svg> -content $(
9+
$commonParameters = @{
10+
Fill = '#4488FF'
11+
Stroke = 'black'
12+
StrokeWidth = '0.05'
13+
}
14+
15+
=<svg.symbol> -Id psChevron -Content @(
16+
=<svg.polygon> -Points (@(
17+
"40,20"
18+
"45,20"
19+
"60,50"
20+
"35,80"
21+
"32.5,80"
22+
"55,50"
23+
) -join ' ')
24+
) -ViewBox 100, 100
25+
26+
27+
=<svg.use> -Href '#psChevron' -X -25% -Y 35% @commonParameters -Height 30% -Opacity .9
28+
# =<svg.text> -Text '>' -X 20 -Y 50 -FontSize 48 -Rotate -7 -FontFamily monospace @commonParameters
29+
=<svg.text> -Text @(
30+
=<svg.tspan> -Content '@' -Dx -8.5em -FontFamily sans-serif -FontSize 4 -DominantBaseline 'middle'
31+
=<svg.tspan> -Content 'eventful' -TextAnchor 'left' -FontFamily monospace -Dx -.4em -DominantBaseline 'middle' -Dy 0em
32+
33+
# =<svg.tspan> -Content '@' -Dx -8.5em -FontFamily sans-serif -FontSize 4 -DominantBaseline 'middle' -Dy -1em
34+
) -X 40% -Y 50% -FontSize 24 -FontFamily monospace @commonParameters
35+
36+
<#=<svg.text> -Text @(
37+
=<svg.tspan> -Content 'eventful' -TextAnchor 'left' -FontFamily monospace -Dx -1em
38+
) -X 40% -Y 56% -FontSize 24 -FontFamily monospace @commonParameters
39+
=<svg.text> -Text @(
40+
=<svg.tspan> -Content '@' -TextAnchor 'right' -FontFamily sans-serif -Dx -1em
41+
) -X 25% -Y 53% -FontSize 12 -FontFamily monospace @commonParameters #>
42+
# =<svg.text> -Text 'SVG' -X 70% -Y 53.5% -FontSize 36 -FontFamily monospace -FontStretch "10%" -FontWeight 150 @commonParameters -DominantBaseline 'middle' -TextAnchor 'middle' -Opacity .9
43+
44+
) -ViewBox 0, 0, 200, 100 -OutputPath $(
45+
Join-Path (Join-Path $PSScriptRoot Assets) Eventful.svg
46+
)

0 commit comments

Comments
 (0)