Skip to content

Commit

Permalink
Add linting workflow and improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
AgenttiX committed Nov 3, 2023
1 parent d393882 commit d8acd6b
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 46 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI
on: push

jobs:
lint:
name: Lint with PSScriptAnalyzer
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Install PSScriptAnalyzer module
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -ErrorAction Stop
- name: Lint with PSScriptAnalyzer
shell: pwsh
run: |
Invoke-ScriptAnalyzer -Path *.ps1 -Recurse -Outvariable issues
$errors = $issues.Where({$_.Severity -eq 'Error'})
$warnings = $issues.Where({$_.Severity -eq 'Warning'})
if ($errors) {
Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction Stop
} else {
Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total."
}
# test-windows:
# name: Test on Windows
# runs-on: windows-latest
# steps:
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ obs-studio/profiler_data
obs-studio/updates
reports
reports.zip
venv
4 changes: 3 additions & 1 deletion Eject-Drive.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Drive letter
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "DriveLetter", Justification="Set to null on purpose")]
param(
[Parameter(Mandatory=$true)][char]$DriveLetter
)
Expand All @@ -16,7 +17,8 @@ param(
# $driveEject = New-Object -comObject Shell.Application
# $driveEject.Namespace(17).ParseName("${DriveLetter}:").InvokeVerb("Eject")

$vol = Get-WmiObject -Class Win32_Volume | where{$_.Name -eq "${DriveLetter}:\"}
# Todo: replace WMI with CIM
$vol = Get-WmiObject -Class Win32_Volume | Where-Object {$_.Name -eq "${DriveLetter}:\"}
$vol.DriveLetter = $null
$vol.Put()
$vol.Dismount($false, $false)
17 changes: 13 additions & 4 deletions Install-Software.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
This parameter is for internal use to check whether an UAC prompt has already been attempted.
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "Elevated", Justification="Used in utils")]
param(
[switch]$Elevated
)

. ".\Utils.ps1"
. "${PSScriptRoot}\Utils.ps1"

if ($RepoInUserDir) {
Update-Repo
Expand Down Expand Up @@ -282,7 +283,7 @@ function Install-OriginViewer {
Show-Output "Extracting Origin Viewer"
Expand-Archive -Path "${Downloads}\$Filename" -DestinationPath "${DestinationPath}"
$ExePath = Find-First -Filter "*.exe" -Path "${DestinationPath}"
if ($ExePath -eq $null) {
if ($null -eq $ExePath) {
Show-Information "No exe file was found in the extracted directory." -ForegroundColor Red
return $false
}
Expand Down Expand Up @@ -392,13 +393,18 @@ function Install-ThorlabsBeam ([string]$Version = "8.2.5232.395") {
}
}

function Install-ThorlabsKinesis ([string]$Version = "1.14.36", [string]$Version2 = "20973") {
function Install-ThorlabsKinesis () {
<#
.SYNOPSIS
Install Thorlabs Kinesis
.LINK
https://www.thorlabs.com/software_pages/ViewSoftwarePage.cfm?Code=Motion_Control&viewtab=0
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Thorlabs Kinesis is a singular noun")]
param(
[string]$Version = "1.14.36",
[string]$Version2 = "20973"
)
Show-Output "Downloading Thorlabs Kinesis. The web server has strict bot detection and the download may therefore fail, producing an invalid file."
$Arch = Get-InstallBitness -x86 "x86" -x86_64 "x64"
$Filename = "kinesis_${Version2}_setup_${Arch}.exe"
Expand Down Expand Up @@ -509,6 +515,9 @@ function CreateTable {
.LINK
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "e", Justification="Probably used by library code")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "sender", Justification="Probably used by library code")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "Form", Justification="Reserved for future use")]
[OutputType([system.Windows.Forms.DataGridView])]
param(
[Parameter(mandatory=$true)][System.Object]$Form,
Expand Down Expand Up @@ -707,7 +716,7 @@ if ($WindowsFeaturesSelected.Count) {
Show-Output "Installing Windows features."
foreach($feature in $WindowsFeaturesSelected) {
Show-Output "Installing ${feature}"
Enable-WindowsOptionalFeature -Feature "$feature" -Online
Enable-WindowsOptionalFeature -FeatureName "$feature" -Online
}
} else {
Show-Output "No Windows features were selected to be installed."
Expand Down
6 changes: 4 additions & 2 deletions Maintenance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ param(
)

# Load utility functions from another file.
Set-Location "${PSScriptRoot}"
. ".\Utils.ps1"
. "${PSScriptRoot}\Utils.ps1"

if ($Reboot -and $Shutdown) {
# The Show-Output function is defined in Utils.ps1
Expand Down Expand Up @@ -601,7 +600,10 @@ if ($Zerofree) {
.\zero-free-space.ps1 -DriveLetter "C"
}

Show-Output -ForegroundColor Cyan "Writing maintenance timestamp."
Get-Date -Format "o" | Out-File $TimestampPath
$ThisRunDate = [Datetime](Get-Content $TimestampPath)
Show-Output -ForegroundColor Cyan "Saved timestamp: ${ThisRunDate}"

Show-Output -ForegroundColor Green "The maintenance script is ready."
if ($Reboot) {
Expand Down
6 changes: 3 additions & 3 deletions Profile/Microsoft.PowerShell_profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Enable-SSHAgent {
# Be aware that if you are missing these lines from your profile, tab completion
# for `choco` will not function.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
$ChocolateyProfile = "${env:ChocolateyInstall}\helpers\chocolateyProfile.psm1"
if (Test-Path("${ChocolateyProfile}")) {
Import-Module "${ChocolateyProfile}"
}
2 changes: 1 addition & 1 deletion Profile/Setup-Profile.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Set-StrictMode -Latest
$ErrorActionPreference = "Stop"

. "$((Get-Item ${PSScriptRoot}).Parent.FullName)/utils.ps1"
. "$(Join-Path $((Get-Item "${PSScriptRoot}").Parent.FullName) "Utils.ps1")"

Show-Output "Configuring PowerShell profile."

Expand Down
2 changes: 1 addition & 1 deletion Repair-Computer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Fix various issues with Windows
#>

. "./Utils.ps1"
. "${PSScriptRoot}\Utils.ps1"
Elevate($MyInvocation.MyCommand.Definition)

Start-Transcript -Path "${LogPath}\Repair-Computer_$(Get-Date -Format "yyyy-MM-dd_HH-mm").txt"
Expand Down
13 changes: 7 additions & 6 deletions Report.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
#>

param(
[switch]$Elevated,
[switch]$NoArchive
)

. ".\Utils.ps1"
. "${PSScriptRoot}\Utils.ps1"
Elevate($myinvocation.MyCommand.Definition)

$host.ui.RawUI.WindowTitle = "Mika's reporting script"

$Downloads = ".\downloads"
$Reports = ".\reports"
# $Downloads = ".\Downloads"
$Reports = ".\Reports"

function Compress-ReportArchive {
Show-Output "Creating the report archive"
$Timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm"
Compress-Archive -Path "${Reports}" -DestinationPath ".\reports_${Timestamp}.zip" -CompressionLevel Optimal
Compress-Archive -Path "${Reports}" -DestinationPath ".\Reports_${Timestamp}.zip" -CompressionLevel Optimal
}

if ($OnlyArchive) {
Expand All @@ -34,7 +35,7 @@ if ($OnlyArchive) {
# Initialization
# -----
Show-Output "Running Mika's reporting script"
New-Item -Path "." -Name "reports" -ItemType "directory" -Force | Out-Null
New-Item -Path "." -Name "Reports" -ItemType "directory" -Force | Out-Null

Show-Output "Removing old reports"
Get-ChildItem "${Reports}/*" -Recurse | Remove-Item
Expand Down Expand Up @@ -87,7 +88,7 @@ if (Test-CommandExists "gpresult") {
if (Test-CommandExists "netsh") {
Show-Output "Creating WiFi report"
netsh wlan show wlanreport
Copy-Item "C:\ProgramData\Microsoft\Windows\WlanReport\wlan-report-latest.html" "${Reports}"
Copy-Item "C:\ProgramData\Microsoft\Windows\WlanReport\wlan_report_latest.html" "${Reports}"
}

if (Test-CommandExists "powercfg") {
Expand Down
7 changes: 3 additions & 4 deletions Reset-YubiKey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
This parameter is for internal use to check whether an UAC prompt has already been attempted.
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "Elevated", Justification="Used in utils")]
param(
[switch]$Elevated
)

. ".\Utils.ps1"

. "${PSScriptRoot}\Utils.ps1"
Elevate($myinvocation.MyCommand.Definition)

. ".\venv\Scripts\activate.ps1"
. "${PSScriptRoot}\venv\Scripts\activate.ps1"

Show-Output -ForegroundColor Cyan "Resetting FIDO"
ykman fido reset
Expand Down
2 changes: 1 addition & 1 deletion Run-PerfTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ param(
[switch]$Unigine
)

. "./Utils.ps1"
. "${PSScriptRoot}\Utils.ps1"
Elevate($MyInvocation.MyCommand.Definition)

Start-Transcript -Path "${LogPath}\perftest_$(Get-Date -Format "yyyy-MM-dd_HH-mm").txt"
Expand Down
5 changes: 2 additions & 3 deletions Setup-FIDO2-SSH.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
This parameter is for internal use to check whether an UAC prompt has already been attempted.
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "Elevated", Justification="Used in utils")]
param(
[switch]$Elevated
)

. ".\Utils.ps1"

. "${PSScriptRoot}\Utils.ps1"
Elevate($myinvocation.MyCommand.Definition)

. ".\venv\Scripts\activate.ps1"

Show-Output -ForegroundColor Cyan "Changing the FIDO2 PIN"
Expand Down
Loading

0 comments on commit d8acd6b

Please sign in to comment.