Skip to content

Commit

Permalink
Merge pull request #40 from StartAutomating/NanoLeaf-Improvement-And-…
Browse files Browse the repository at this point in the history
…GitPub

Nano leaf improvement and GitPub
  • Loading branch information
StartAutomating authored Oct 12, 2022
2 parents cbd4eb3 + e1aa035 commit a522878
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 49 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"
}
}
94 changes: 88 additions & 6 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 @@ -381,7 +387,7 @@ jobs:
}
Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
[Ordered]@{
owner = '${{github.owner}}'
repo = '${{github.repository}}'
Expand All @@ -403,13 +409,62 @@ jobs:
"Content-type" = "application/json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
}
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
}
}
})
$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"
"ContentType" = "application/octet-stream"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
} -Body $fileBytes
$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 +473,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 Down Expand Up @@ -473,9 +542,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 @@ -495,8 +579,6 @@ jobs:
uses: StartAutomating/PipeScript@main
- name: UseEZOut
uses: StartAutomating/EZOut@master
- name: UsePiecemeal
uses: StartAutomating/Piecemeal@main
- name: UseHelpOut
uses: StartAutomating/HelpOut@master

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.2.6:
* Set-NanoLeaf:
* Fixing -SaturationIncrement (#35)
* Adding -BrightnessIncrement (#34)
* Fixing -Hue/-Saturation/-Brightness behavior to allow increment parameters to work. (#36)
* Making Parameter Aliases consistent with Set-HueLight (#38)
* Now using [GitPub](https://github.com/StartAutomating/GitPub) to blog (#37).
---

## 0.2.5:
* Set-HueRule: Easier conditions (Fixes #28) and plural aliases (Fixes #31)
* Adding Rename-HueSensor (Fixes #26).
Expand Down
40 changes: 18 additions & 22 deletions Functions/NanoLeaf/Set-NanoLeaf.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
[ComponentModel.AmbientValue({
[PSCustomObject]@{value=$_ % 360}
})]
[Alias('H')]
[int]
$Hue,

Expand All @@ -77,14 +78,15 @@
[ComponentModel.AmbientValue({
[PSCustomObject]@{value=[int][Math]::Round($_ * 100)}
})]
[Alias('S')]
[ValidateRange(0,1)]
[double]
$Saturation,

# Increments the saturation of the NanoLeaf light color.
[ComponentModel.DefaultBindingProperty('sat')]
[ComponentModel.AmbientValue({
[PSCustomObject]@{increment=[int][Math]::Round($_)}
[PSCustomObject]@{increment=[int][Math]::Round($_ * 100)}
})]
[int]
$SaturationIncrement,
Expand All @@ -94,9 +96,22 @@
# If provided with -Hue and -Saturation, sets the color of all panels.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateRange(0,1)]
[Alias('B','L','Luminance','.bri')]
[double]
$Brightness,

# The brightness increment.
# If no other parameters are provided, adjusts universal brightness.
[Parameter(ValueFromPipelineByPropertyName)]
[ComponentModel.DefaultBindingProperty('brightness')]
[ComponentModel.AmbientValue({
[PSCustomObject]@{increment=[int][Math]::Round($_ * 100)}
})]
[Alias('LuminanceIncrement')]
[ValidateRange(-1,1)]
[double]
$BrightnessIncrement,

# If set, will change all panels on the nanoleaf to a given color temperature.
[Parameter(ValueFromPipelineByPropertyName)]
[ComponentModel.DefaultBindingProperty('ct')]
Expand Down Expand Up @@ -336,34 +351,15 @@
} else {
$sendData.brightness.duration = 0
}
}

}
if ($on) {
$sendData.on = @{value=$true}
}
if ($off) {
$sendData.on = @{value=$false}
}

#region Set HSB/HSL Color for all panels
if ($Hue -and $Saturation -and $Brightness) {
$hslData = @{
write = [Ordered]@{
command = 'display'
version = '1.0'
animType = "solid"
palette = @(
[Ordered]@{hue=$Hue%360;saturation=[int]($Saturation*100);brightness=[int]($Brightness*100)}
)
colorType="HSB"
}
} | ConvertTo-Json -Depth 5

Send-NanoLeaf @ipAndToken -Command 'effects' -Data $hslData -Method PUT
return
}
#endregion Set HSB/HSL Color for all panels

$writeCommand = [Ordered]@{}
if (-not $effectName) {
$writeCommand.command = "display"
Expand Down
32 changes: 32 additions & 0 deletions GitHub/Jobs/RunGitPub.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@{
"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"
}
}
'@
}
}
)
}
11 changes: 4 additions & 7 deletions LightScript.GitHubWorkflow.psdevops.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#requires -Module PSDevOps
Push-Location $PSScriptRoot

New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish |
Import-BuildStep -Module LightScript
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, BuildModule |
Set-Content .\.github\workflows\TestAndPublish.yml -Encoding UTF8 -PassThru

New-GitHubWorkflow -Name "Run HelpOut" -On Push -Job HelpOut |
Set-Content .\.github\workflows\UpdateDocs.yml -Encoding UTF8 -PassThru

New-GitHubWorkflow -Name "Run EZOut" -On Push -Job RunEZOut |
Set-Content .\.github\workflows\RunEZOut.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

Pop-Location
11 changes: 10 additions & 1 deletion LightScript.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.2.5'
ModuleVersion = '0.2.6'
RootModule = 'LightScript.psm1'
Description = 'Smarter Lighting with PowerShell'
FormatsToProcess = 'LightScript.format.ps1xml'
Expand All @@ -14,6 +14,15 @@
LicenseURI = 'https://github.com/StartAutomating/LightScript/blob/main/LICENSE'
IconURI = 'https://github.com/StartAutomating/LightScript/blob/main/Assets/LightScript.png'
ReleaseNotes = @'
## 0.2.6:
* Set-NanoLeaf:
* Fixing -SaturationIncrement (#35)
* Adding -BrightnessIncrement (#34)
* Fixing -Hue/-Saturation/-Brightness behavior to allow increment parameters to work. (#36)
* Making Parameter Aliases consistent with Set-HueLight (#38)
* Now using [GitPub](https://github.com/StartAutomating/GitPub) to blog (#37).
---
## 0.2.5:
* Set-HueRule: Easier conditions (Fixes #28) and plural aliases (Fixes #31)
* Adding Rename-HueSensor (Fixes #26).
Expand Down
9 changes: 9 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.2.6:
* Set-NanoLeaf:
* Fixing -SaturationIncrement (#35)
* Adding -BrightnessIncrement (#34)
* Fixing -Hue/-Saturation/-Brightness behavior to allow increment parameters to work. (#36)
* Making Parameter Aliases consistent with Set-HueLight (#38)
* Now using [GitPub](https://github.com/StartAutomating/GitPub) to blog (#37).
---

## 0.2.5:
* Set-HueRule: Easier conditions (Fixes #28) and plural aliases (Fixes #31)
* Adding Rename-HueSensor (Fixes #26).
Expand Down
Loading

0 comments on commit a522878

Please sign in to comment.