Skip to content

WebSocket 0.1.1 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5427701
feat: Get-WebSocket -TimeOut ( Fixes #23 )
Nov 28, 2024
f79d058
feat: Get-WebSocket -TimeOut ( Fixes #23 )
Nov 28, 2024
7ceadfa
feat: Get-WebSocket -TimeOut ( Fixes #23 )
Nov 28, 2024
102fc27
feat: Get-WebSocket -TimeOut ( Fixes #23 )
Nov 28, 2024
3515639
feat: Get-WebSocket -TimeOut ( Fixes #23 )
Nov 28, 2024
3c8b30d
feat: Get-WebSocket -TimeOut ( Fixes #23 )
Nov 28, 2024
b1b6f74
feat: Get-WebSocket -Maximum ( Fixes #22 )
Nov 28, 2024
3cad8eb
feat: Get-WebSocket -Maximum ( Fixes #22 )
Nov 28, 2024
e2382f6
feat: Get-WebSocket -Maximum ( Fixes #22 )
Nov 28, 2024
5b92da4
feat: Get-WebSocket -Maximum ( Fixes #22 )
Nov 28, 2024
3fd880e
feat: WebSocket action ( Fixes #24 )
Nov 28, 2024
840680e
feat: WebSocket action ( Fixes #24 )
Nov 28, 2024
d01a7ff
feat: WebSocket action ( Fixes #24 )
Nov 28, 2024
1c91db5
feat: WebSocket tests ( Fixes #25 )
Nov 28, 2024
39c4434
feat: WebSocket tests ( Fixes #25 )
Nov 28, 2024
81a4f52
feat: WebSocket tests ( Fixes #25 )
Nov 28, 2024
de48130
feat: WebSocket Container starting .WebSocket files ( Fixes #26 )
Nov 28, 2024
b32e74a
docs: Generating WebSocket README with PipeScript ( Fixes #27 )
Nov 30, 2024
ccda061
docs: Generating WebSocket README with PipeScript ( Fixes #27 )
Nov 30, 2024
5fd644b
docs: Generating WebSocket README with PipeScript ( Fixes #27 )
Nov 30, 2024
0f10ff8
docs: Generating WebSocket README with PipeScript ( Fixes #27 )
Nov 30, 2024
2c1f9d9
docs: Generating WebSocket README with PipeScript ( Fixes #27 )
Nov 30, 2024
72e72a0
docs: Generating WebSocket README with PipeScript ( Fixes #27 )
Nov 30, 2024
c49d8e8
docs: Generating WebSocket README with PipeScript ( Fixes #27 )
Nov 30, 2024
e9d5817
docs: More Get-WebSocket examples ( Fixes #27 )
Nov 30, 2024
b0b979c
docs: More Get-WebSocket examples ( Fixes #27 )
Nov 30, 2024
3fe73fd
docs: More Get-WebSocket examples ( Fixes #27 )
Nov 30, 2024
2597ccc
docs: More Get-WebSocket examples ( Fixes #27 )
Nov 30, 2024
6d93bcf
docs: More Get-WebSocket examples ( Fixes #27 )
Nov 30, 2024
1ed7496
docs: More Get-WebSocket examples ( Fixes #27 )
Nov 30, 2024
de0cede
docs: More Get-WebSocket examples ( Fixes #27 )
Nov 30, 2024
b11e8ee
docs: Get-WebSocket aliasing ( Fixes #28 )
Nov 30, 2024
d525f28
docs: Get-WebSocket aliasing ( Fixes #28 )
Nov 30, 2024
55ca843
docs: Get-WebSocket aliasing ( Fixes #28 )
Nov 30, 2024
df9ebb4
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
917fa5b
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
9734a05
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
a8ae39b
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
df5c904
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
675cdd6
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
0957e7b
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
ced404e
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
5758738
feat: Get-WebSocket -WatchFor ( Fixes #29 )
Dec 4, 2024
a34e862
feat: Get-WebSocket -RawText ( Fixes #30 )
Dec 4, 2024
de0d484
feat: Get-WebSocket -RawText ( Fixes #30 )
Dec 4, 2024
03883c9
feat: Get-WebSocket -RawText ( Fixes #30 )
Dec 4, 2024
62176f2
feat: Get-WebSocket -RawText ( Fixes #30 )
Dec 4, 2024
b00340c
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
d967dbd
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
a1e36f3
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
cb2ec59
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
e9572ae
feat: Sponsorship Support ( Fixes #14 )
Dec 4, 2024
2ba3410
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
4f5d359
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
7ef90bc
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
71e97dc
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
94e2476
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
249dfe8
feat: Get-WebSocket -Binary ( Fixes #31 )
Dec 4, 2024
55e4480
release: WebSocket 0.1.1
Dec 4, 2024
9d004d8
release: WebSocket 0.1.1
Dec 4, 2024
a4f1cb5
release: WebSocket 0.1.1
Dec 4, 2024
5a1e16c
release: WebSocket 0.1.1
Dec 4, 2024
0a303b7
release: WebSocket 0.1.1
Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [StartAutomating]
349 changes: 349 additions & 0 deletions Build/GitHub/Actions/WebSocketAction.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
<#
.Synopsis
GitHub Action for WebSocket
.Description
GitHub Action for WebSocket. This will:

* Import WebSocket
* If `-Run` is provided, run that script
* Otherwise, unless `-SkipScriptFile` is passed, run all *.WebSocket.ps1 files beneath the workflow directory
* If any `-ActionScript` was provided, run scripts from the action path that match a wildcard pattern.

If you will be making changes using the GitHubAPI, you should provide a -GitHubToken
If none is provided, and ENV:GITHUB_TOKEN is set, this will be used instead.
Any files changed can be outputted by the script, and those changes can be checked back into the repo.
Make sure to use the "persistCredentials" option with checkout.
#>

param(
# A PowerShell Script that uses WebSocket.
# Any files outputted from the script will be added to the repository.
# If those files have a .Message attached to them, they will be committed with that message.
[string]
$Run,

# If set, will not process any files named *.WebSocket.ps1
[switch]
$SkipScriptFile,

# A list of modules to be installed from the PowerShell gallery before scripts run.
[string[]]
$InstallModule,

# If provided, will commit any remaining changes made to the workspace with this commit message.
[string]
$CommitMessage,

# If provided, will checkout a new branch before making the changes.
# If not provided, will use the current branch.
[string]
$TargetBranch,

# The name of one or more scripts to run, from this action's path.
[string[]]
$ActionScript,

# The github token to use for requests.
[string]
$GitHubToken = '{{ secrets.GITHUB_TOKEN }}',

# The user email associated with a git commit. If this is not provided, it will be set to the username@noreply.github.com.
[string]
$UserEmail,

# The user name associated with a git commit.
[string]
$UserName,

# If set, will not push any changes made to the repository.
# (they will still be committed unless `-NoCommit` is passed)
[switch]
$NoPush,

# If set, will not commit any changes made to the repository.
# (this also implies `-NoPush`)
[switch]
$NoCommit
)

$ErrorActionPreference = 'continue'
"::group::Parameters" | Out-Host
[PSCustomObject]$PSBoundParameters | Format-List | Out-Host
"::endgroup::" | Out-Host

$gitHubEventJson = [IO.File]::ReadAllText($env:GITHUB_EVENT_PATH)
$gitHubEvent =
if ($env:GITHUB_EVENT_PATH) {
$gitHubEventJson | ConvertFrom-Json
} else { $null }
"::group::Parameters" | Out-Host
$gitHubEvent | Format-List | Out-Host
"::endgroup::" | Out-Host


$anyFilesChanged = $false
$ActionModuleName = 'PSJekyll'
$actorInfo = $null


$checkDetached = git symbolic-ref -q HEAD
if ($LASTEXITCODE) {
"::warning::On detached head, skipping action" | Out-Host
exit 0
}

function InstallActionModule {
param([string]$ModuleToInstall)
$moduleInWorkspace = Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -File |
Where-Object Name -eq "$($moduleToInstall).psd1" |
Where-Object {
$(Get-Content $_.FullName -Raw) -match 'ModuleVersion'
}
if (-not $moduleInWorkspace) {
$availableModules = Get-Module -ListAvailable
if ($availableModules.Name -notcontains $moduleToInstall) {
Install-Module $moduleToInstall -Scope CurrentUser -Force -AcceptLicense -AllowClobber
}
Import-Module $moduleToInstall -Force -PassThru | Out-Host
} else {
Import-Module $moduleInWorkspace.FullName -Force -PassThru | Out-Host
}
}
function ImportActionModule {
#region -InstallModule
if ($InstallModule) {
"::group::Installing Modules" | Out-Host
foreach ($moduleToInstall in $InstallModule) {
InstallActionModule -ModuleToInstall $moduleToInstall
}
"::endgroup::" | Out-Host
}
#endregion -InstallModule

if ($env:GITHUB_ACTION_PATH) {
$LocalModulePath = Join-Path $env:GITHUB_ACTION_PATH "$ActionModuleName.psd1"
if (Test-path $LocalModulePath) {
Import-Module $LocalModulePath -Force -PassThru | Out-String
} else {
throw "Module '$ActionModuleName' not found"
}
} elseif (-not (Get-Module $ActionModuleName)) {
throw "Module '$ActionModuleName' not found"
}

"::notice title=ModuleLoaded::$ActionModuleName Loaded from Path - $($LocalModulePath)" | Out-Host
if ($env:GITHUB_STEP_SUMMARY) {
"# $($ActionModuleName)" |
Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
}
}
function InitializeAction {
#region Custom
#endregion Custom

# Configure git based on the $env:GITHUB_ACTOR
if (-not $UserName) { $UserName = $env:GITHUB_ACTOR }
if (-not $actorID) { $actorID = $env:GITHUB_ACTOR_ID }
$actorInfo =
if ($GitHubToken -notmatch '^\{{2}' -and $GitHubToken -notmatch '\}{2}$') {
Invoke-RestMethod -Uri "https://api.github.com/user/$actorID" -Headers @{ Authorization = "token $GitHubToken" }
} else {
Invoke-RestMethod -Uri "https://api.github.com/user/$actorID"
}

if (-not $UserEmail) { $UserEmail = "$UserName@noreply.github.com" }
git config --global user.email $UserEmail
git config --global user.name $actorInfo.name

# Pull down any changes
git pull | Out-Host

if ($TargetBranch) {
"::notice title=Expanding target branch string $targetBranch" | Out-Host
$TargetBranch = $ExecutionContext.SessionState.InvokeCommand.ExpandString($TargetBranch)
"::notice title=Checking out target branch::$targetBranch" | Out-Host
git checkout -b $TargetBranch | Out-Host
git pull | Out-Host
}
}

function InvokeActionModule {
$myScriptStart = [DateTime]::Now
$myScript = $ExecutionContext.SessionState.PSVariable.Get("Run").Value
if ($myScript) {
Invoke-Expression -Command $myScript |
. ProcessOutput |
Out-Host
return
}
$myScriptTook = [Datetime]::Now - $myScriptStart
$MyScriptFilesStart = [DateTime]::Now

$myScriptList = @()
$shouldSkip = $ExecutionContext.SessionState.PSVariable.Get("SkipScriptFile").Value
if ($shouldSkip) {
return
}
$scriptFiles = @(
Get-ChildItem -Recurse -Path $env:GITHUB_WORKSPACE |
Where-Object Name -Match "\.$($ActionModuleName)\.ps1$"
if ($ActionScript) {
if ($ActionScript -match '^\s{0,}/' -and $ActionScript -match '/\s{0,}$') {
$ActionScriptPattern = $ActionScript.Trim('/').Trim() -as [regex]
if ($ActionScriptPattern) {
$ActionScriptPattern = [regex]::new($ActionScript.Trim('/').Trim(), 'IgnoreCase,IgnorePatternWhitespace', [timespan]::FromSeconds(0.5))
Get-ChildItem -Recurse -Path $env:GITHUB_ACTION_PATH |
Where-Object { $_.Name -Match "\.$($ActionModuleName)\.ps1$" -and $_.FullName -match $ActionScriptPattern }
}
} else {
Get-ChildItem -Recurse -Path $env:GITHUB_ACTION_PATH |
Where-Object Name -Match "\.$($ActionModuleName)\.ps1$" |
Where-Object FullName -Like $ActionScript
}
}
) | Select-Object -Unique
$scriptFiles |
ForEach-Object -Begin {
if ($env:GITHUB_STEP_SUMMARY) {
"## $ActionModuleName Scripts" |
Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
}
} -Process {
$myScriptList += $_.FullName.Replace($env:GITHUB_WORKSPACE, '').TrimStart('/')
$myScriptCount++
$scriptFile = $_
if ($env:GITHUB_STEP_SUMMARY) {
"### $($scriptFile.Fullname -replace [Regex]::Escape($env:GITHUB_WORKSPACE))" |
Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
}
$scriptCmd = $ExecutionContext.SessionState.InvokeCommand.GetCommand($scriptFile.FullName, 'ExternalScript')
foreach ($requiredModule in $CommandInfo.ScriptBlock.Ast.ScriptRequirements.RequiredModules) {
if ($requiredModule.Name -and
(-not $requiredModule.MaximumVersion) -and
(-not $requiredModule.RequiredVersion)
) {
InstallActionModule $requiredModule.Name
}
}
$scriptFileOutputs = . $scriptCmd
$scriptFileOutputs |
. ProcessOutput |
Out-Host
}

$MyScriptFilesTook = [Datetime]::Now - $MyScriptFilesStart
$SummaryOfMyScripts = "$myScriptCount $ActionModuleName scripts took $($MyScriptFilesTook.TotalSeconds) seconds"
$SummaryOfMyScripts |
Out-Host
if ($env:GITHUB_STEP_SUMMARY) {
$SummaryOfMyScripts |
Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
}
#region Custom
#endregion Custom
}

function OutError {
$anyRuntimeExceptions = $false
foreach ($err in $error) {
$errParts = @(
"::error "
@(
if ($err.InvocationInfo.ScriptName) {
"file=$($err.InvocationInfo.ScriptName)"
}
if ($err.InvocationInfo.ScriptLineNumber -ge 1) {
"line=$($err.InvocationInfo.ScriptLineNumber)"
if ($err.InvocationInfo.OffsetInLine -ge 1) {
"col=$($err.InvocationInfo.OffsetInLine)"
}
}
if ($err.CategoryInfo.Activity) {
"title=$($err.CategoryInfo.Activity)"
}
) -join ','
"::"
$err.Exception.Message
if ($err.CategoryInfo.Category -eq 'OperationStopped' -and
$err.CategoryInfo.Reason -eq 'RuntimeException') {
$anyRuntimeExceptions = $true
}
) -join ''
$errParts | Out-Host
if ($anyRuntimeExceptions) {
exit 1
}
}
}

function PushActionOutput {
if ($anyFilesChanged) {
"::notice::$($anyFilesChanged) Files Changed" | Out-Host
}
if ($CommitMessage -or $anyFilesChanged) {
if ($CommitMessage) {
Get-ChildItem $env:GITHUB_WORKSPACE -Recurse |
ForEach-Object {
$gitStatusOutput = git status $_.Fullname -s
if ($gitStatusOutput) {
git add $_.Fullname
}
}

git commit -m $ExecutionContext.SessionState.InvokeCommand.ExpandString($CommitMessage)
}

$checkDetached = git symbolic-ref -q HEAD
if (-not $LASTEXITCODE -and -not $NoPush -and -not $noCommit) {
if ($TargetBranch -and $anyFilesChanged) {
"::notice::Pushing Changes to $targetBranch" | Out-Host
git push --set-upstream origin $TargetBranch
} elseif ($anyFilesChanged) {
"::notice::Pushing Changes" | Out-Host
git push
}
"Git Push Output: $($gitPushed | Out-String)"
} else {
"::notice::Not pushing changes (on detached head)" | Out-Host
$LASTEXITCODE = 0
exit 0
}
}
}

filter ProcessOutput {
$out = $_
$outItem = Get-Item -Path $out -ErrorAction Ignore
if (-not $outItem -and $out -is [string]) {
$out | Out-Host
if ($env:GITHUB_STEP_SUMMARY) {
"> $out" | Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
}
return
}
$fullName, $shouldCommit =
if ($out -is [IO.FileInfo]) {
$out.FullName, (git status $out.Fullname -s)
} elseif ($outItem) {
$outItem.FullName, (git status $outItem.Fullname -s)
}
if ($shouldCommit -and -not $NoCommit) {
"$fullName has changed, and should be committed" | Out-Host
git add $fullName
if ($out.Message) {
git commit -m "$($out.Message)" | Out-Host
} elseif ($out.CommitMessage) {
git commit -m "$($out.CommitMessage)" | Out-Host
} elseif ($gitHubEvent.head_commit.message) {
git commit -m "$($gitHubEvent.head_commit.message)" | Out-Host
}
$anyFilesChanged = $true
}
$out
}

. ImportActionModule
. InitializeAction
. InvokeActionModule
. PushActionOutput
. OutError
10 changes: 10 additions & 0 deletions Build/WebSocket.GitHubAction.PSDevOps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#requires -Module PSDevOps
Import-BuildStep -SourcePath (
Join-Path $PSScriptRoot 'GitHub'
) -BuildSystem GitHubAction

$PSScriptRoot | Split-Path | Push-Location

New-GitHubAction -Name "UseWebSocket" -Description 'Work with WebSockets in PowerShell' -Action WebSocketAction -Icon chevron-right -OutputPath .\action.yml

Pop-Location
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
## WebSocket 0.1

> Like It? [Star It](https://github.com/PowerShellWeb/WebSocket)
> Love It? [Support It](https://github.com/sponsors/StartAutomating)

## WebSocket 0.1.1

* WebSocket GitHub Action
* Run any `*.WebSocket.ps1` files in a repository (#24)
* WebSocket container updates
* Container now runs mounted `*.WebSocket.ps1` files (#26)
* Get-WebSocket improvements:
* New Parameters:
* -Maximum (#22)
* -TimeOut (#23)
* -WatchFor (#29)
* -RawText (#30)
* -Binary (#31)
* WebSocket Testing (#25)
* Adding FUNDING.yml (#14)

---

## WebSocket 0.1

* Initial Release of WebSocket module
* Get-WebSocket gets content from a WebSocket
* Docker container for WebSocket
Expand Down
Loading