diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f048850..ebf67d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,24 +1,60 @@ -- name: PowerShell Security Scan - shell: pwsh - run: | - $psFiles = Get-ChildItem -Path . -Include *.ps1,*.psm1 -Recurse -File | - Select-Object -ExpandProperty FullName - - if ($psFiles) { - - $results = Invoke-ScriptAnalyzer -Path $psFiles -Severity Error,Warning | - Where-Object { $_.RuleName -like "*Security*" } - - if ($results) { - $results | Format-Table - Write-Host "::error title=Security Scan::Potential security issues found in PowerShell scripts." - throw "Security issues detected by PSScriptAnalyzer" - } - else { - Write-Host "::notice title=Security Scan::No common security issues found in PowerShell scripts." - } - - } - else { - Write-Host "::notice title=Security Scan::No PowerShell files found." - } \ No newline at end of file +name: Continuous Integration + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + pester-test: + name: Run Pester Tests + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run Pester tests + shell: pwsh + run: | + $results = Invoke-Pester -Path ./tests/Project.Tests.ps1 -PassThru + if ($results.FailedCount -gt 0) { + throw "Pester tests failed with $($results.FailedCount) errors." + } + + security-scan: + name: PowerShell Security Scan + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install PSScriptAnalyzer + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module PSScriptAnalyzer -Force -Scope CurrentUser + + - name: Run PowerShell Security Scan + shell: pwsh + run: | + $psFiles = Get-ChildItem -Path . -Include *.ps1,*.psm1 -Recurse -File | + Select-Object -ExpandProperty FullName + + if ($psFiles) { + $results = Invoke-ScriptAnalyzer -Path $psFiles -Severity Error,Warning | + Where-Object { $_.RuleName -like "*Security*" } + + if ($results) { + $results | Format-Table + Write-Host "::error title=Security Scan::Potential security issues found in PowerShell scripts." + throw "Security issues detected by PSScriptAnalyzer" + } + else { + Write-Host "::notice title=Security Scan::No common security issues found in PowerShell scripts." + } + } + else { + Write-Host "::notice title=Security Scan::No PowerShell files found." + } diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e56ddb0..d525381 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -15,7 +15,7 @@ on: jobs: analyze: - name: CodeQL JavaScript/TypeScript Scan + name: CodeQL Security Scan runs-on: ubuntu-latest permissions: @@ -26,7 +26,7 @@ jobs: strategy: fail-fast: false matrix: - language: ['javascript-typescript'] + language: ['javascript-typescript', 'python'] timeout-minutes: 30 @@ -70,12 +70,10 @@ jobs: - name: Run PowerShell Security Scan shell: pwsh run: | - # Find PowerShell files and convert to string paths $psFiles = Get-ChildItem -Path . -Include *.ps1,*.psm1 -Recurse -File | Select-Object -ExpandProperty FullName if ($psFiles) { - $results = Invoke-ScriptAnalyzer -Path $psFiles -Severity Error,Warning | Where-Object { $_.RuleName -like "*Security*" } @@ -87,7 +85,6 @@ jobs: else { Write-Host "::notice title=Security Scan::No common security issues found in PowerShell scripts." } - } else { Write-Host "::notice title=Security Scan::No PowerShell files found." diff --git a/.github/workflows/powershell-ci.yml b/.github/workflows/powershell-ci.yml index 6e62848..39d138d 100644 --- a/.github/workflows/powershell-ci.yml +++ b/.github/workflows/powershell-ci.yml @@ -16,7 +16,9 @@ jobs: - name: Install PSScriptAnalyzer shell: pwsh - run: Install-Module PSScriptAnalyzer -Force -Scope CurrentUser + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module PSScriptAnalyzer -Force -Scope CurrentUser - name: Run Security Scan shell: pwsh @@ -30,4 +32,4 @@ jobs: throw "Security issues detected by PSScriptAnalyzer" } else { Write-Host "::notice title=Security Scan::No common security issues found." - } \ No newline at end of file + } diff --git a/.github/workflows/powershell.yml b/.github/workflows/powershell.yml index 426f029..c911c9d 100644 --- a/.github/workflows/powershell.yml +++ b/.github/workflows/powershell.yml @@ -7,6 +7,7 @@ on: branches: [ "main" ] schedule: - cron: '38 9 * * 5' + workflow_dispatch: permissions: contents: read @@ -29,16 +30,12 @@ jobs: - name: Run PSScriptAnalyzer shell: pwsh run: | - # Determine repo root path based on OS - if ($IsWindows) { - $scanPath = ".\" - } else { - $scanPath = "." - } + # Ensure repository is trusted for smooth module installation + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module PSScriptAnalyzer -Force -Scope CurrentUser # Run PSScriptAnalyzer - Install-Module PSScriptAnalyzer -Force -Scope CurrentUser - $results = Invoke-ScriptAnalyzer -Path $scanPath -Recurse -Severity Error,Warning ` + $results = Invoke-ScriptAnalyzer -Path . -Recurse -Severity Error,Warning ` | Where-Object { $_.RuleName -like "*Security*" } if ($results) { diff --git a/webhooks/listener.ps1 b/webhooks/listener.ps1 index 784613b..8d8f929 100644 --- a/webhooks/listener.ps1 +++ b/webhooks/listener.ps1 @@ -1,16 +1,9 @@ -<<<<<<< HEAD -[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] -# ============================================= -# System Automation Hub - Webhook Listener +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] # ============================================= -======= -# ============================================= # System Automation Hub - Webhook Listener # ============================================= -[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] param() ->>>>>>> origin/remote-control-bridge-12936344523257638862 $port = 9000 $endpoint = "http://localhost:$port/" @@ -24,24 +17,18 @@ $listener.Prefixes.Add($endpoint) try { $listener.Start() -<<<<<<< HEAD Write-Host "🚀 Listener started on $endpoint" -ForegroundColor Cyan Write-Host "Press Ctrl+C to stop.`n" -ForegroundColor DarkGray Write-Host "💡 To test locally, run:" -ForegroundColor Green - Write-Host "curl -X POST $endpoint -d '{""test"": ""hello""}' -H 'Content-Type: application/json'" -ForegroundColor DarkGray + Write-Host "curl -X POST $endpoint -d '{\"test\": \"hello\"}' -H 'Content-Type: application/json'" -ForegroundColor DarkGray Write-Host "`nWaiting for events..." -ForegroundColor Cyan -======= - Write-Host "🚀 Listener started on $endpoint" - Write-Host "Press Ctrl+C to stop.`n" ->>>>>>> origin/remote-control-bridge-12936344523257638862 while ($listener.IsListening) { $context = $listener.GetContext() $request = $context.Request $response = $context.Response -<<<<<<< HEAD $timestamp = Get-Date -Format 'HH:mm:ss' $method = $request.HttpMethod $remote = $request.RemoteEndPoint @@ -55,15 +42,11 @@ try { Write-Host "$method " -ForegroundColor Yellow -NoNewline Write-Host "from " -ForegroundColor Gray -NoNewline Write-Host "$remote" -ForegroundColor White -======= - Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Received $($request.HttpMethod) request from $($request.RemoteEndPoint)" ->>>>>>> origin/remote-control-bridge-12936344523257638862 # Read body if available if ($request.HasEntityBody) { $reader = New-Object System.IO.StreamReader($request.InputStream, [System.Text.Encoding]::UTF8) $body = $reader.ReadToEnd() -<<<<<<< HEAD try { if ($request.ContentType -match "application/json") { @@ -79,9 +62,6 @@ try { Write-Host "Payload (Raw):" -ForegroundColor Cyan Write-Host $body -ForegroundColor DarkGray } -======= - Write-Host "Payload: $body" ->>>>>>> origin/remote-control-bridge-12936344523257638862 } # Simple response @@ -89,22 +69,12 @@ try { $response.ContentLength64 = $buffer.Length $response.OutputStream.Write($buffer, 0, $buffer.Length) $response.Close() -<<<<<<< HEAD Write-Host "Done.`n" -ForegroundColor DarkGray } } catch { Write-Host "❌ Error: $($_.Exception.Message)" -ForegroundColor Red -======= - } -} catch { - Write-Host "❌ Error: $($_.Exception.Message)" ->>>>>>> origin/remote-control-bridge-12936344523257638862 } finally { if ($null -ne $listener) { $listener.Stop() } -<<<<<<< HEAD -} -======= } ->>>>>>> origin/remote-control-bridge-12936344523257638862