Skip to content

Commit 372179a

Browse files
Lots of misc fixes
1 parent 197dc52 commit 372179a

32 files changed

Lines changed: 514 additions & 234 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Lint winget configurations
2+
3+
on:
4+
push:
5+
paths:
6+
- 'winget_configurations/**'
7+
- '.github/workflows/lint-winget-configs.yml'
8+
pull_request:
9+
paths:
10+
- 'winget_configurations/**'
11+
- '.github/workflows/lint-winget-configs.yml'
12+
13+
jobs:
14+
lint:
15+
name: Lint winget configurations
16+
runs-on: windows-latest
17+
permissions:
18+
contents: read
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Validate winget configuration files
24+
shell: pwsh
25+
run: |
26+
$files = Get-ChildItem winget_configurations -Filter "*.yaml"
27+
foreach ($f in $files) {
28+
$content = Get-Content $f.FullName -Raw
29+
# Check for null RestartExplorer (bare colon with only optional comment after)
30+
if ($content -match 'RestartExplorer\s*:\s*(#.*)?[\r\n]') {
31+
Write-Error "Null RestartExplorer found in $($f.Name)"
32+
exit 1
33+
}
34+
# Check for AllowDestructive: true
35+
if ($content -match 'AllowDestructive\s*:\s*true') {
36+
Write-Error "AllowDestructive: true found in $($f.Name)"
37+
exit 1
38+
}
39+
}
40+
Write-Host "All YAML checks passed"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: PSScriptAnalyzer
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.ps1'
7+
- 'PSScriptAnalyzerSettings.psd1'
8+
- '.github/workflows/psscriptanalyzer.yml'
9+
pull_request:
10+
paths:
11+
- '**.ps1'
12+
- 'PSScriptAnalyzerSettings.psd1'
13+
- '.github/workflows/psscriptanalyzer.yml'
14+
15+
jobs:
16+
lint:
17+
name: PSScriptAnalyzer
18+
runs-on: windows-latest
19+
permissions:
20+
contents: read
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install PSScriptAnalyzer
26+
shell: pwsh
27+
run: |
28+
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
29+
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser
30+
}
31+
32+
- name: Run PSScriptAnalyzer
33+
shell: pwsh
34+
run: |
35+
$results = Invoke-ScriptAnalyzer -Path . -Recurse -Settings PSScriptAnalyzerSettings.psd1 -Severity Error,Warning
36+
if ($results) {
37+
$results | Format-Table -AutoSize
38+
Write-Error "PSScriptAnalyzer found $($results.Count) issue(s)."
39+
exit 1
40+
}
41+
Write-Host "PSScriptAnalyzer: no issues found."

.github/workflows/test-git-hooks.yml

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ on:
44
push:
55
paths:
66
- 'git-hooks/**'
7+
- 'bucket/**'
8+
- 'Profile.ps1'
9+
- 'install.ps1'
10+
- '**.Tests.ps1'
711
- '.github/workflows/test-git-hooks.yml'
812
pull_request:
913
paths:
1014
- 'git-hooks/**'
15+
- 'bucket/**'
16+
- 'Profile.ps1'
17+
- 'install.ps1'
18+
- '**.Tests.ps1'
1119
- '.github/workflows/test-git-hooks.yml'
1220

1321
jobs:
@@ -40,7 +48,7 @@ jobs:
4048
shell: pwsh
4149
run: |
4250
$config = New-PesterConfiguration
43-
$config.Run.Path = 'git-hooks/tests/commit-msg.Tests.ps1'
51+
$config.Run.Path = @('git-hooks/tests', 'bucket/tests', 'tests')
4452
$config.Output.Verbosity = 'Detailed'
4553
$config.TestResult.Enabled = $true
4654
$config.TestResult.OutputPath = 'test-results.xml'
@@ -53,3 +61,47 @@ jobs:
5361
with:
5462
name: test-results-${{ matrix.os }}
5563
path: test-results.xml
64+
65+
scoop-tests:
66+
name: Scoop integration tests
67+
runs-on: windows-latest
68+
permissions:
69+
contents: read
70+
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Install Scoop
75+
shell: pwsh
76+
run: |
77+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
78+
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
79+
# Ensure scoop is on PATH for subsequent steps
80+
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
81+
82+
- name: Install Pester
83+
shell: pwsh
84+
run: |
85+
if (-not (Get-Module -ListAvailable -Name Pester | Where-Object { $_.Version -ge '5.0' })) {
86+
Install-Module -Name Pester -MinimumVersion 5.0 -Force -SkipPublisherCheck -Scope CurrentUser
87+
}
88+
Import-Module Pester -MinimumVersion 5.0
89+
90+
- name: Run Scoop integration tests
91+
shell: pwsh
92+
run: |
93+
$config = New-PesterConfiguration
94+
$config.Run.Path = @('bucket/Utils.Tests.ps1', 'bucket/McAfeeUninstall.Tests.ps1')
95+
$config.Output.Verbosity = 'Detailed'
96+
$config.TestResult.Enabled = $true
97+
$config.TestResult.OutputPath = 'test-results-scoop.xml'
98+
$config.Run.Exit = $true
99+
Invoke-Pester -Configuration $config
100+
101+
- name: Upload test results
102+
if: always()
103+
uses: actions/upload-artifact@v4
104+
with:
105+
name: test-results-scoop
106+
path: test-results-scoop.xml
107+

.vsconfig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"Component.Microsoft.WebTools.BrowserLink.WebLivePreview",
1010
"Component.OpenJDK",
1111
"Component.VisualStudio.GitHub.Copilot",
12-
"Component.Xamarin.RemotedSimulator",
1312
"ComponentGroup.Microsoft.NET.AppModernization",
1413
"Microsoft.Component.Azure.DataLake.Tools",
1514
"Microsoft.Component.ClickOnce",
@@ -32,9 +31,6 @@
3231
"Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
3332
"Microsoft.NetCore.Component.DevelopmentTools",
3433
"Microsoft.NetCore.Component.Runtime.10.0",
35-
"Microsoft.NetCore.Component.Runtime.3.1",
36-
"Microsoft.NetCore.Component.Runtime.6.0",
37-
"Microsoft.NetCore.Component.Runtime.7.0",
3834
"Microsoft.NetCore.Component.Runtime.8.0",
3935
"Microsoft.NetCore.Component.Runtime.9.0",
4036
"Microsoft.NetCore.Component.SDK",
@@ -128,7 +124,6 @@
128124
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
129125
"Microsoft.VisualStudio.ComponentGroup.UWP.NetCoreAndStandard",
130126
"Microsoft.VisualStudio.ComponentGroup.UWP.Support",
131-
"Microsoft.VisualStudio.ComponentGroup.UWP.Xamarin",
132127
"Microsoft.VisualStudio.ComponentGroup.VisualStudioExtension.Prerequisites",
133128
"Microsoft.VisualStudio.ComponentGroup.Web",
134129
"Microsoft.VisualStudio.ComponentGroup.Web.CloudTools",

Profile.ps1

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,39 @@ function Log-Message {
3636
$line = "{0}: {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message
3737

3838
$m = [System.Threading.Mutex]::new($false, $script:LogMutexName)
39-
if ($m.WaitOne([TimeSpan]::FromSeconds(2))) {
40-
try {
41-
$attempts = 0
42-
while ($attempts -lt 5) {
43-
try {
44-
$fs = [System.IO.File]::Open($logFile, [System.IO.FileMode]::Append, [System.IO.FileAccess]::Write, [System.IO.FileShare]::ReadWrite)
39+
try {
40+
if ($m.WaitOne([TimeSpan]::FromSeconds(2))) {
41+
try {
42+
$attempts = 0
43+
while ($attempts -lt 5) {
4544
try {
46-
$sw = New-Object System.IO.StreamWriter($fs)
47-
$sw.WriteLine($line)
48-
$sw.Flush()
49-
$sw.Dispose()
50-
} finally {
51-
$fs.Dispose()
45+
$fs = [System.IO.File]::Open($logFile, [System.IO.FileMode]::Append, [System.IO.FileAccess]::Write, [System.IO.FileShare]::ReadWrite)
46+
try {
47+
$sw = New-Object System.IO.StreamWriter($fs)
48+
$sw.WriteLine($line)
49+
$sw.Flush()
50+
$sw.Dispose()
51+
} finally {
52+
$fs.Dispose()
53+
}
54+
break
55+
} catch {
56+
Start-Sleep -Milliseconds 150
57+
$attempts++
5258
}
53-
break
54-
} catch {
55-
Start-Sleep -Milliseconds 150
56-
$attempts++
5759
}
60+
} finally {
61+
try { $m.ReleaseMutex() | Out-Null } catch { }
5862
}
59-
} finally {
60-
try { $m.ReleaseMutex() | Out-Null } catch { }
61-
$m.Dispose()
6263
}
64+
} finally {
65+
$m.Dispose()
6366
}
6467
} catch {
6568
# Swallow all logging errors to avoid breaking the session
6669
}
6770
}
6871

69-
# Function to calculate SHA256 hash of a string
70-
function Get-SHA256 {
71-
param ([string]$String)
72-
[System.BitConverter]::ToString(
73-
[System.Security.Cryptography.SHA256]::Create().ComputeHash(
74-
[System.Text.Encoding]::UTF8.GetBytes($String)
75-
)
76-
).Replace("-", "").ToLower()
77-
}
78-
7972
# Function to show differences between two strings
8073
function Show-Diff {
8174
param (
@@ -264,9 +257,6 @@ try {
264257
Log-Message "Failed to initialize oh-my-posh: $($_.Exception.Message)"
265258
}
266259

267-
# Help Yarn Builds
268-
$env:PWD = (Get-Location).Path
269-
270260
# --- Custom Aliases -----------------------------------------------------------
271261
function ConvertTo-Base64 {
272262
param ([string]$InputString)

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
1. Take the desired configuration scripts from the [winget_configurations folder](./winget_configurations)
66
2. Follow the instructions at [https://learn.microsoft.com/windows/package-manager/configuration/](https://learn.microsoft.com/windows/package-manager/configuration/?WT.mc_id=8B97120A00B57354#use-a-winget-configuration-file-to-configure-your-machine) to setup your machine
77

8+
## Running install.ps1
9+
10+
On a fresh Windows machine the default execution policy is **Restricted**, which prevents PowerShell from running `.ps1` scripts entirely. The in-script execution-policy check (`Set-ExecutionPolicy Bypass -Scope Process`) is a safety notice only — it cannot bootstrap itself from Restricted mode because the script never gets to execute.
11+
12+
To launch the installer, run:
13+
14+
```powershell
15+
powershell -ExecutionPolicy Bypass -File install.ps1
16+
```
17+
818
## Scoop Bucket instructions:
919

1020
Setups my personal scoop bucket. Installs and uninstalls programs.

bucket/GitConfigure.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Function GitConfigure {
99
# See https://msdn.microsoft.com/en-us/powershell/wmf/5.0/feedback_symbolic?f=255&MSPPError=-2147217396
1010
if ($env:Data -and (Test-Path "$env:Data")) {
1111
New-Item -ItemType Junction -Path "$env:USERPROFILE\.ssh" -Target "$env:Data\Profile\.ssh"
12-
New-Item -ItemType HardLink -Target "$env:USERPROFILE\.gitconfig" -Path "$env:Data\Profile\.gitconfig"
12+
New-Item -ItemType HardLink -Path "$env:USERPROFILE\.gitconfig" -Target "$env:Data\Profile\.gitconfig"
1313
}
1414

1515
Import-ChocolateyModule
@@ -21,7 +21,7 @@ Function GitConfigure {
2121
#/NoAutoCrlf" <# This setting only affects new installs, it will not override an existing .gitconfig. This will ensure 'Checkout as is, commit as is' #>
2222
}
2323

24-
Install-Module posh-git -y -Scope -AllUsers -force -allowclobber # Both Posh-Git and IntelliTect.Git support Get-GitBranch.
24+
Install-Module posh-git -Scope AllUsers -Force -AllowClobber # Both Posh-Git and IntelliTect.Git support Get-GitBranch.
2525
# IntelliTect.Git will get priority if it appears first in the PSModulePath
2626
# or it is installed after Pscx (if not using source code)
2727
#Import-Module (Get-Childitem $env:PSModulePath.Split(';') posh-git.psm1 -Recurse -ErrorAction Ignore).FullName

bucket/GitIntegrationWithBeyondCompare.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

bucket/GitIntegrationWithBeyondCompare.ps1

Lines changed: 0 additions & 38 deletions
This file was deleted.

bucket/McAfeeUninstall.Tests.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# Static analysis tests for this script live in bucket/tests/McAfeeUninstall.Tests.ps1 (run in CI).
2+
# The test below is a Scoop integration test that requires Scoop installed locally.
3+
14
. "$PSScriptRoot\Utils.ps1"
2-
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace('.Tests', '')
3-
. "$PSScriptRoot\$sut"
45

56
Describe Install-McAfeeUninstall {
67
it "scoop install McAfeeUninstall" {
@@ -10,7 +11,7 @@ Describe Install-McAfeeUninstall {
1011
$manifestPath = "$PSScriptRoot\McAfeeUninstall.json"
1112
$manifestJson = Get-Content $manifestPath
1213
$manifest = $manifestJson | ConvertFrom-Json
13-
$manifest.url = $manifest.url | ForEach-Object {
14+
$manifest.url = $manifest.url | Where-Object { $_ -notmatch '^https://TODO' } | ForEach-Object {
1415
[Uri]$mockUri = $_ -replace 'https://raw.githubusercontent.com/BenjaminMichaelis/ScoopBucket/master/bucket', "$PSScriptRoot"
1516
Write-Output $mockUri.AbsoluteUri
1617
}

0 commit comments

Comments
 (0)