Skip to content

Commit

Permalink
Merge pull request #18 from StartAutomating/Eventful-Improvements
Browse files Browse the repository at this point in the history
Eventful improvements
  • Loading branch information
StartAutomating authored Oct 23, 2022
2 parents 0811bd1 + 08e24d6 commit ec4a74f
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 52 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/OnIssue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

name: OnIssueChanged
on:
issues:
workflow_dispatch:
jobs:
RunGitPub:
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Use GitPub Action
uses: StartAutomating/GitPub@main
id: GitPub
with:
TargetBranch: edits-$([DateTime]::Now.ToString("r").Replace(":","-").Replace(" ", ""))
CommitMessage: Posting with GitPub [skip ci]
PublishParameters: |
{
"Get-GitPubIssue": {
"Repository": '${{github.repository}}',
},
"Get-GitPubRelease": {
"Repository": '${{github.repository}}',
},
"Publish-GitPubJekyll": {
"OutputPath": "docs/_posts"
}
}
157 changes: 119 additions & 38 deletions .github/workflows/TestAndPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ jobs:
$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 @@ -331,7 +333,11 @@ jobs:
# The release name format (default value: '$($imported.Name) $($imported.Version)')
[string]
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)'
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)',
# Any assets to attach to the release. Can be a wildcard or file name.
[string[]]
$ReleaseAsset
)
Expand Down Expand Up @@ -377,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 = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
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 @@ -418,19 +474,33 @@ 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 Gallery Publish" | Out-Host
Expand All @@ -448,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 @@ -473,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 @@ -485,24 +570,20 @@ jobs:
}
}
} @Parameters
HelpOut:
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: UseHelpOut
uses: StartAutomating/HelpOut@master
RunEZOut:
BuildEventful:
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Use PSSVG Action
uses: StartAutomating/PSSVG@main
id: PSSVG
- name: BuildPipeScript
uses: StartAutomating/PipeScript@main
- name: UseEZOut
uses: StartAutomating/EZOut@master
- name: Push Changes
shell: pwsh
run: git push; exit 0
- name: UseHelpOut
uses: StartAutomating/HelpOut@master
env:
NoCoverage: true
11 changes: 11 additions & 0 deletions Assets/Eventful.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.1.7
* Adding On@CommandNotFound event source (Fixes #11)
* Watch-Event now allows eventsources -recursively (Fixes #15)

---

## 0.1.6
* Adding LocationChanged event source (Fixes #12)

Expand Down
23 changes: 23 additions & 0 deletions EventSources/@CommandNotFound.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<#
.Synopsis
Sends events when a command is not found.
.Description
Sends events when a command is not found.
Handling this event can resolve any unknown command.
.EXAMPLE
On@CommandNotFound
.EXAMPLE
On@CommandNotFound -Then { $event | Out-Host }
#>
param()

process {
$global:ExecutionContext.SessionState.InvokeCommand.CommandNotFoundAction = {
New-Event -SourceIdentifier "PowerShell.CommandNotFound" -MessageData $notFoundArgs -Sender $global:ExecutionContext -EventArguments $notFoundArgs
}

[PSCustomObject]@{
SourceIdentifier = "PowerShell.CommandNotFound"
}
}
7 changes: 6 additions & 1 deletion Eventful.GithubWorkflow.psdevops.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#requires -Module PSDevOps
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, HelpOut, RunEZOut -Environment @{
Import-BuildStep -Module Eventful
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, BuildEventful -Environment @{
NoCoverage = $true
}|
Set-Content .\.github\workflows\TestAndPublish.yml -Encoding UTF8 -PassThru

New-GitHubWorkflow -On Issue, Demand -Job RunGitPub -Name OnIssueChanged |
Set-Content (Join-Path $PSScriptRoot .github\workflows\OnIssue.yml) -Encoding UTF8 -PassThru

46 changes: 46 additions & 0 deletions Eventful.PSSVG.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#requires -Module PSSVG

$assetsPath = Join-Path $PSScriptRoot Assets

if (-not (Test-Path $assetsPath)) {
$null = New-Item -ItemType Directory -path $assetsPath -Force
}
=<svg> -content $(
$commonParameters = @{
Fill = '#4488FF'
Stroke = 'black'
StrokeWidth = '0.05'
}

=<svg.symbol> -Id psChevron -Content @(
=<svg.polygon> -Points (@(
"40,20"
"45,20"
"60,50"
"35,80"
"32.5,80"
"55,50"
) -join ' ')
) -ViewBox 100, 100


=<svg.use> -Href '#psChevron' -X -25% -Y 35% @commonParameters -Height 30% -Opacity .9
# =<svg.text> -Text '>' -X 20 -Y 50 -FontSize 48 -Rotate -7 -FontFamily monospace @commonParameters
=<svg.text> -Text @(
=<svg.tspan> -Content '@' -Dx -8.5em -FontFamily sans-serif -FontSize 4 -DominantBaseline 'middle'
=<svg.tspan> -Content 'eventful' -TextAnchor 'left' -FontFamily monospace -Dx -.4em -DominantBaseline 'middle' -Dy 0em

# =<svg.tspan> -Content '@' -Dx -8.5em -FontFamily sans-serif -FontSize 4 -DominantBaseline 'middle' -Dy -1em
) -X 40% -Y 50% -FontSize 24 -FontFamily monospace @commonParameters

<#=<svg.text> -Text @(
=<svg.tspan> -Content 'eventful' -TextAnchor 'left' -FontFamily monospace -Dx -1em
) -X 40% -Y 56% -FontSize 24 -FontFamily monospace @commonParameters
=<svg.text> -Text @(
=<svg.tspan> -Content '@' -TextAnchor 'right' -FontFamily sans-serif -Dx -1em
) -X 25% -Y 53% -FontSize 12 -FontFamily monospace @commonParameters #>
# =<svg.text> -Text 'SVG' -X 70% -Y 53.5% -FontSize 36 -FontFamily monospace -FontStretch "10%" -FontWeight 150 @commonParameters -DominantBaseline 'middle' -TextAnchor 'middle' -Opacity .9

) -ViewBox 0, 0, 200, 100 -OutputPath $(
Join-Path (Join-Path $PSScriptRoot Assets) Eventful.svg
)
Loading

0 comments on commit ec4a74f

Please sign in to comment.