-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from T0pCyber/Development
Development
- Loading branch information
Showing
87 changed files
with
4,002 additions
and
2,425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
on: | ||
push: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-2019 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: PSScriptAnalyzer | ||
on: | ||
pull_request: | ||
paths: | ||
- "**.ps1" | ||
- "**.psm1" | ||
- "**.psd1" | ||
push: | ||
paths: | ||
- "**.ps1" | ||
- "**.psm1" | ||
- "**.psd1" | ||
|
||
jobs: | ||
analyze: | ||
name: PSScriptAnalyzer | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Required for getting changed files | ||
|
||
- name: Get changed files | ||
shell: pwsh | ||
run: | | ||
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') { | ||
$baseCommit = git rev-parse $env:GITHUB_EVENT.pull_request.base.sha | ||
$headCommit = git rev-parse HEAD | ||
$changedFiles = git diff --name-only $baseCommit..$headCommit | ||
} else { | ||
$changedFiles = git diff --name-only HEAD^1 HEAD | ||
} | ||
$powershellFiles = $changedFiles | Where-Object { | ||
$_ -match '\.(ps1|psm1|psd1)$' | ||
} | ||
$powershellFiles | Out-File -FilePath $env:GITHUB_WORKSPACE/changed_files.txt | ||
Write-Host "Changed PowerShell files:" | ||
$powershellFiles | ForEach-Object { Write-Host " $_" } | ||
- name: Install PSScriptAnalyzer | ||
shell: pwsh | ||
run: | | ||
Set-PSRepository PSGallery -InstallationPolicy Trusted | ||
Install-Module PSScriptAnalyzer -Force | ||
- name: Run PSScriptAnalyzer | ||
shell: pwsh | ||
run: | | ||
$settingsPath = Join-Path $env:GITHUB_WORKSPACE 'Hawk' 'internal' 'configurations' 'PSScriptAnalyzerSettings.psd1' | ||
Write-Output "Using settings file: $settingsPath" | ||
if (-not (Test-Path $settingsPath)) { | ||
Write-Error "PSScriptAnalyzer settings file not found at: $settingsPath" | ||
exit 1 | ||
} | ||
$changedFiles = Get-Content -Path "$env:GITHUB_WORKSPACE/changed_files.txt" | ||
if (-not $changedFiles) { | ||
Write-Output "No PowerShell files were changed" | ||
$null > (Join-Path $env:GITHUB_WORKSPACE 'psscriptanalyzer-results.txt') | ||
exit 0 | ||
} | ||
$results = @() | ||
foreach ($file in $changedFiles) { | ||
$fullPath = Join-Path $env:GITHUB_WORKSPACE $file | ||
if (Test-Path $fullPath) { | ||
Write-Output "Analyzing $fullPath" | ||
$fileResults = Invoke-ScriptAnalyzer -Path $fullPath -Settings $settingsPath | ||
if ($fileResults) { | ||
$results += $fileResults | ||
} | ||
} | ||
} | ||
if ($results) { | ||
Write-Output "Found $($results.Count) issues in changed files:" | ||
$results | Format-Table -AutoSize | Out-String | Write-Output | ||
$results | Format-Table -AutoSize | Out-File (Join-Path $env:GITHUB_WORKSPACE 'psscriptanalyzer-results.txt') | ||
exit 1 | ||
} else { | ||
Write-Output "No PSScriptAnalyzer issues found in changed files" | ||
$null > (Join-Path $env:GITHUB_WORKSPACE 'psscriptanalyzer-results.txt') | ||
exit 0 | ||
} | ||
- name: Upload Results | ||
if: always() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: psscriptanalyzer-results | ||
path: psscriptanalyzer-results.txt | ||
if-no-files-found: warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: powershell-script-analyzer | ||
name: PowerShell Script Analyzer | ||
entry: pwsh | ||
args: | ||
- -NoProfile | ||
- -ExecutionPolicy | ||
- Bypass | ||
- -File | ||
- Hawk/internal/scripts/pre_commit_hook_scripts/Invoke-PowerShellScriptAnalyzer.ps1 | ||
language: system | ||
types: [powershell] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.