Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions Merge

This file was deleted.

3 changes: 2 additions & 1 deletion cleanup-old-workflows.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param()
# Files to remove (relative to repo root)
$filesToDelete = @(
".github\workflows\create-powershell-ci.ps1",
Expand Down
3 changes: 2 additions & 1 deletion create-download-cert.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param()
# Workflow folder
$workflowDir = ".github\workflows"
if (-not (Test-Path $workflowDir)) {
Expand Down
74 changes: 73 additions & 1 deletion create-powershell-ci.ps1
Original file line number Diff line number Diff line change
@@ -1 +1,73 @@

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param()

# Workflow folder
$workflowDir = ".github\workflows"
if (-not (Test-Path $workflowDir)) {
New-Item -ItemType Directory -Path $workflowDir -Force | Out-Null
}

# powershell-ci.yml
$powershellCiYaml = @'
name: PowerShell CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
powershell-ci:
name: PowerShell CI (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Modules
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser
Install-Module Pester -Force -Scope CurrentUser -SkipPublisherCheck

- name: Run PSScriptAnalyzer (Security Scan)
shell: pwsh
run: |
$results = Invoke-ScriptAnalyzer -Path . -Recurse -Severity Error,Warning |
Where-Object { $_.RuleName -like "*Security*" }

if ($results) {
$results | Format-Table
Write-Host "::error title=Security Scan [Run #$($env:GITHUB_RUN_NUMBER)]::Potential security issues found in PowerShell scripts."
throw "Security issues detected by PSScriptAnalyzer"
} else {
Write-Host "::notice title=Security Scan [Run #$($env:GITHUB_RUN_NUMBER)]::No common security issues found."
}

- name: Run Pester Tests
shell: pwsh
run: |
if (Test-Path ./tests) {
$results = Invoke-Pester -Path ./tests -PassThru
if ($results.FailedCount -gt 0) {
Write-Host "::error title=Pester Tests [Run #$($env:GITHUB_RUN_NUMBER)]::$($results.FailedCount) tests failed."
throw "Pester tests failed."
} else {
Write-Host "::notice title=Pester Tests [Run #$($env:GITHUB_RUN_NUMBER)]::All tests passed successfully."
}
} else {
Write-Host "::notice title=Pester Tests [Run #$($env:GITHUB_RUN_NUMBER)]::No Pester tests found in ./tests."
}
'@

$powershellCiFile = Join-Path $workflowDir "powershell-ci.yml"
$powershellCiYaml | Set-Content -Path $powershellCiFile -Force
Write-Host "$powershellCiFile created successfully."
30 changes: 21 additions & 9 deletions run-workflow-manually.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Hardcoded GitHub Personal Access Token (with repo/workflows scope)
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param()

# Hardcoded GitHub Personal Access Token (with repo/workflows scope)
$token = $env:GITHUB_TOKEN

# GitHub repo info
Expand All @@ -7,9 +10,18 @@ $repo = "System-Automation-Hub"

# Get list of workflow files
$workflowDir = ".github/workflows"
$workflows = Get-ChildItem $workflowDir -Filter *.yml | Select-Object -ExpandProperty Name
if (Test-Path $workflowDir) {
$workflows = Get-ChildItem $workflowDir -Filter *.yml | Select-Object -ExpandProperty Name
} else {
$workflows = @()
}

Write-Host "Available workflows to run:"
if ($workflows.Count -eq 0) {
Write-Host "No workflows found in $workflowDir" -ForegroundColor Yellow
return
}

$workflows | ForEach-Object { Write-Host "- $_" }

# Prompt user to choose workflow
Expand All @@ -27,9 +39,6 @@ if ($answer -ne 'Y') {
return
}

# Use token directly
$token = $env:GITHUB_TOKEN

# GitHub API endpoint
$uri = "https://api.github.com/repos/$owner/$repo/actions/workflows/$workflowFile/dispatches"

Expand All @@ -44,7 +53,10 @@ $headers = @{
$body = @{ ref = "main" } | ConvertTo-Json

# Trigger the workflow
Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $body

Write-Host "Workflow '$workflowFile' dispatched successfully!"
Write-Host "Check https://github.com/$owner/$repo/actions for status."
try {
Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $body
Write-Host "Workflow '$workflowFile' dispatched successfully!"
Write-Host "Check https://github.com/$owner/$repo/actions for status."
} catch {
Write-Host "Error triggering workflow: $($_.Exception.Message)" -ForegroundColor Red
}
2 changes: 1 addition & 1 deletion scripts/fetch-profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ try {
Write-Host "---------------------------"
} catch {
Write-Host "❌ Error: Could not fetch profile for '$Username'. Details: $($_.Exception.Message)" -ForegroundColor Red
}
}
2 changes: 1 addition & 1 deletion scripts/init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
param()
Write-Host 'Automation Hub Initialized' -ForegroundColor Cyan
Write-Host 'Machine:' RIZWAN
Write-Host 'User:' ruhal
Write-Host 'User:' ruhal
10 changes: 5 additions & 5 deletions start-automation.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# =============================================
# System Automation Hub Launcher
# =============================================
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
param()
# =============================================
# System Automation Hub Launcher
# =============================================

# --- Config ---
$port = 9000
$listenerScript = ".\webhooks\listener.ps1"

# --- Function to start listener in a new window ---
# --- Function to start listener ---
function Start-Listener {
Start-Process pwsh -ArgumentList "-NoExit -Command `"$listenerScript`""
Write-Host "✅ Listener started on port $port"
Expand Down
2 changes: 1 addition & 1 deletion webhooks/listener.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ try {
if ($null -ne $listener) {
$listener.Stop()
}
}
}
Loading