Skip to content

Commit 3261c93

Browse files
authored
Merge pull request #10 from pwshdevs/1.0.9-Features
1.0.9 features - Homebrew support on macos and linux (tested on linux) - Automated Pester reports on PR's - Automated PSScriptAnalyzer reports on PR's - Added initial DryRun capabilities to homebrew functionality, will expand on it to Chocolately, Scoop and Powershell in 1.0.10
2 parents 49b3815 + 7a1406a commit 3261c93

87 files changed

Lines changed: 3207 additions & 473 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run-lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run PSScriptAnalyzer Tests
2+
on:
3+
pull_request:
4+
branches:
5+
- develop
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
psscriptanalyzer:
11+
name: PSScriptAnalyzer
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
issues: write
16+
checks: write
17+
pull-requests: write
18+
security-events: write
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Lint with PSScriptAnalyzer
22+
shell: pwsh
23+
run: |
24+
.\runSecurity.ps1
25+
26+
- name: Upload SARIF results file
27+
uses: github/codeql-action/upload-sarif@v3
28+
with:
29+
sarif_file: results.sarif
30+
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Run Pester Tests
2+
on:
3+
pull_request:
4+
branches:
5+
- develop
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
pester-test-linux:
11+
name: Pester test (On Linux)
12+
runs-on: ubuntu-latest
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
permissions:
16+
contents: read
17+
issues: read
18+
checks: write
19+
pull-requests: write
20+
steps:
21+
- name: Check out repository code
22+
uses: actions/checkout@v4
23+
- name: Execute runTests.ps1
24+
shell: pwsh
25+
run: |
26+
.\runTests.ps1
27+
- name: Publish Test Results
28+
uses: EnricoMi/publish-unit-test-result-action/linux@v2
29+
if: (!cancelled())
30+
with:
31+
check_name: Pester test (On Linux) Results
32+
files: testResults.xml
33+
34+
pester-test-windows:
35+
name: Pester test (On Windows)
36+
runs-on: windows-latest
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
permissions:
40+
contents: read
41+
issues: read
42+
checks: write
43+
pull-requests: write
44+
steps:
45+
- name: Check out repository code
46+
uses: actions/checkout@v4
47+
- name: Execute runTests.ps1
48+
shell: pwsh
49+
run: |
50+
.\runTests.ps1
51+
- name: Publish Test Results
52+
uses: EnricoMi/publish-unit-test-result-action/windows@v2
53+
if: (!cancelled())
54+
with:
55+
check_name: Pester test (On Windows) Results
56+
files: testResults.xml
57+
58+
pester-test-macos:
59+
name: Pester test (On macOS)
60+
runs-on: macos-latest
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
permissions:
64+
contents: read
65+
issues: read
66+
checks: write
67+
pull-requests: write
68+
steps:
69+
- name: Check out repository code
70+
uses: actions/checkout@v4
71+
- name: Execute runTests.ps1
72+
shell: pwsh
73+
run: |
74+
.\runTests.ps1
75+
- name: Publish Test Results
76+
uses: EnricoMi/publish-unit-test-result-action/macos@v2
77+
if: (!cancelled())
78+
with:
79+
check_name: Pester test (On macOS) Results
80+
files: testResults.xml

DevSetup/Private/3rdParty/ConvertFrom-3rdPartyInstall.Tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ BeforeAll {
22
. $PSScriptRoot\ConvertFrom-3rdPartyInstall.ps1
33
. $PSScriptRoot\..\..\..\DevSetup\Private\3rdParty\VisualStudio\ConvertFrom-VisualStudioInstall.ps1
44
. $PSScriptRoot\..\..\..\DevSetup\Private\3rdParty\VisualStudioCode\ConvertFrom-VisualStudioCodeInstall.ps1
5+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Test-OperatingSystem.ps1
56
Mock Write-Host { }
67
Mock Write-Warning { }
78
Mock ConvertFrom-VisualStudioInstall { $true }
89
Mock ConvertFrom-VisualStudioCodeInstall { $true }
10+
Mock Test-OperatingSystem { $true }
911
}
1012

1113
Describe "ConvertFrom-3rdPartyInstall" {

DevSetup/Private/3rdParty/ConvertFrom-3rdPartyInstall.ps1

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ Function ConvertFrom-3rdPartyInstall {
33
[string]$Config
44
)
55

6-
# Convert from Visual Studio installations
7-
Write-Host "`nScanning Visual Studio installations..." -ForegroundColor Cyan
8-
if (-not (ConvertFrom-VisualStudioInstall -Config $Config)) {
9-
Write-Warning "Failed to convert Visual Studio installations, but continuing..."
10-
}
6+
if((Test-OperatingSystem -Windows)) {
7+
# Convert from Visual Studio installations
8+
Write-Host "`nScanning Visual Studio installations..." -ForegroundColor Cyan
9+
if (-not (ConvertFrom-VisualStudioInstall -Config $Config)) {
10+
Write-Warning "Failed to convert Visual Studio installations, but continuing..."
11+
}
1112

12-
# Convert from Visual Studio Code installations
13-
Write-Host "`nScanning Visual Studio Code installation..." -ForegroundColor Cyan
14-
if (-not (ConvertFrom-VisualStudioCodeInstall -Config $Config)) {
15-
Write-Warning "Failed to convert Visual Studio Code installation, but continuing..."
13+
# Convert from Visual Studio Code installations
14+
Write-Host "`nScanning Visual Studio Code installation..." -ForegroundColor Cyan
15+
if (-not (ConvertFrom-VisualStudioCodeInstall -Config $Config)) {
16+
Write-Warning "Failed to convert Visual Studio Code installation, but continuing..."
17+
}
1618
}
1719
}
Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,102 @@
11
BeforeAll {
2-
. $PSScriptRoot\Export-DevSetupEnv.ps1
3-
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupEnvPath.ps1
4-
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupLocalEnvPath.ps1
5-
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupCommunityEnvPath.ps1
6-
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Write-NewConfig.ps1
7-
Mock Get-DevSetupEnvPath { "TestDrive:\DevSetupEnvs" }
8-
Mock Get-DevSetupLocalEnvPath { "TestDrive:\DevSetupEnvs\local"}
9-
Mock Get-DevSetupCommunityEnvPath { "TestDrive:\DevSetupEnvs\community"}
2+
. (Join-Path $PSScriptRoot "Export-DevSetupEnv.ps1")
3+
. (Join-Path $PSScriptRoot "..\..\..\DevSetup\Private\Utils\Get-DevSetupEnvPath.ps1")
4+
. (Join-Path $PSScriptRoot "..\..\..\DevSetup\Private\Utils\Get-DevSetupLocalEnvPath.ps1")
5+
. (Join-Path $PSScriptRoot "..\..\..\DevSetup\Private\Utils\Get-DevSetupCommunityEnvPath.ps1")
6+
. (Join-Path $PSScriptRoot "..\..\..\DevSetup\Private\Utils\Write-NewConfig.ps1")
7+
. (Join-Path $PSScriptRoot "..\..\..\DevSetup\Private\Utils\Write-StatusMessage.ps1")
8+
if ($PSVersionTable.PSVersion.Major -eq 5) {
9+
Mock Get-DevSetupEnvPath { "$TestDrive\DevSetup\DevSetupEnvs" }
10+
Mock Get-DevSetupLocalEnvPath { "$TestDrive\DevSetup\DevSetupEnvs\local" }
11+
Mock Get-DevSetupCommunityEnvPath { "$TestDrive\DevSetup\DevSetupEnvs\community" }
12+
} elseif ($PSVersionTable.PSVersion.Major -ge 6) {
13+
if ($IsWindows) {
14+
Mock Get-DevSetupEnvPath { "$TestDrive\DevSetup\DevSetupEnvs" }
15+
Mock Get-DevSetupLocalEnvPath { "$TestDrive\DevSetup\DevSetupEnvs\local" }
16+
Mock Get-DevSetupCommunityEnvPath { "$TestDrive\DevSetup\DevSetupEnvs\community" }
17+
}
18+
if ($IsLinux) {
19+
Mock Get-DevSetupEnvPath { "$TestDrive/home/testuser/DevSetup/DevSetupEnvs" }
20+
Mock Get-DevSetupLocalEnvPath { "$TestDrive/home/testuser/DevSetup/DevSetupEnvs/local" }
21+
Mock Get-DevSetupCommunityEnvPath { "$TestDrive/home/testuser/DevSetup/DevSetupEnvs/community" }
22+
}
23+
if ($IsMacOS) {
24+
Mock Get-DevSetupEnvPath { "$TestDrive/Users/TestUser/DevSetup/DevSetupEnvs" }
25+
Mock Get-DevSetupLocalEnvPath { "$TestDrive/Users/TestUser/DevSetup/DevSetupEnvs/local" }
26+
Mock Get-DevSetupCommunityEnvPath { "$TestDrive/Users/TestUser/DevSetup/DevSetupEnvs/community" }
27+
}
28+
}
1029
Mock Write-NewConfig { param($OutFile) $OutFile }
1130
Mock Write-Host { }
1231
Mock Write-Error { }
32+
Mock Write-StatusMessage { }
1333
}
1434

1535
Describe "Export-DevSetupEnv" {
1636

1737
Context "When called with a valid name" {
1838
It "Should create the config file and return its path" {
1939
$result = Export-DevSetupEnv -Name "MyEnv"
20-
$result | Should -Be "TestDrive:\DevSetupEnvs\local\MyEnv.devsetup"
21-
Assert-MockCalled Write-NewConfig -Exactly 1 -Scope It -ParameterFilter { $OutFile -eq "TestDrive:\DevSetupEnvs\local\MyEnv.devsetup" }
22-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "exported to" -and $ForegroundColor -eq "Green" }
40+
if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows)) {
41+
$expectedPath = "$TestDrive\DevSetup\DevSetupEnvs\local\MyEnv.devsetup"
42+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux) {
43+
$expectedPath = "$TestDrive/home/testuser/DevSetup/DevSetupEnvs/local/MyEnv.devsetup"
44+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS) {
45+
$expectedPath = "$TestDrive/Users/TestUser/DevSetup/DevSetupEnvs/local/MyEnv.devsetup"
46+
}
47+
$result | Should -Be $expectedPath
48+
Assert-MockCalled Write-NewConfig -Exactly 1 -Scope It -ParameterFilter { $OutFile -eq $expectedPath }
49+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "exported to" -and $ForegroundColor -eq "Green" }
2350
}
2451
}
2552

2653
Context "When called with a valid path" {
2754
It "Should create the config file and return its path" {
28-
$result = Export-DevSetupEnv -Path "TestDrive:\MyCustomPath\MyEnv.devsetup"
29-
$result | Should -Be "TestDrive:\MyCustomPath\MyEnv.devsetup"
30-
Assert-MockCalled Write-NewConfig -Exactly 1 -Scope It -ParameterFilter { $OutFile -eq "TestDrive:\MyCustomPath\MyEnv.devsetup" }
31-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "exported to" -and $ForegroundColor -eq "Green" }
55+
if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows)) {
56+
$result = Export-DevSetupEnv -Path "$TestDrive\MyCustomPath\MyEnv.devsetup"
57+
$expectedPath = "$TestDrive\MyCustomPath\MyEnv.devsetup"
58+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux) {
59+
$result = Export-DevSetupEnv -Path "$TestDrive/MyCustomPath/MyEnv.devsetup"
60+
$expectedPath = "$TestDrive/MyCustomPath/MyEnv.devsetup"
61+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS) {
62+
$result = Export-DevSetupEnv -Path "$TestDrive/MyCustomPath/MyEnv.devsetup"
63+
$expectedPath = "$TestDrive/MyCustomPath/MyEnv.devsetup"
64+
}
65+
$result | Should -Be $expectedPath
66+
Assert-MockCalled Write-NewConfig -Exactly 1 -Scope It -ParameterFilter { $OutFile -eq $expectedPath }
67+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "exported to" -and $ForegroundColor -eq "Green" }
3268
}
3369
}
3470

3571
Context "When called with a name that needs sanitization" {
3672
It "Should sanitize the name and warn" {
3773
$result = Export-DevSetupEnv -Name "Data Science Environment!"
38-
$result | Should -Be "TestDrive:\DevSetupEnvs\local\DataScienceEnvironment.devsetup"
39-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "sanitized" -and $ForegroundColor -eq "Yellow" }
74+
if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows)) {
75+
$expectedPath = "$TestDrive\DevSetup\DevSetupEnvs\local\DataScienceEnvironment.devsetup"
76+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux) {
77+
$expectedPath = "$TestDrive/home/testuser/DevSetup/DevSetupEnvs/local/DataScienceEnvironment.devsetup"
78+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS) {
79+
$expectedPath = "$TestDrive/Users/TestUser/DevSetup/DevSetupEnvs/local/DataScienceEnvironment.devsetup"
80+
}
81+
$result | Should -Be $expectedPath
82+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "sanitized" -and $ForegroundColor -eq "Yellow" }
4083
}
4184
}
4285

4386
Context "When called with a path that needs sanitization" {
4487
It "Should sanitize the path and warn" {
45-
$result = Export-DevSetupEnv -Path "TestDrive:\MyCustomPath\MyEnv!.devsetup"
46-
$result | Should -Be "TestDrive:\MyCustomPath\MyEnv.devsetup"
47-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "sanitized" -and $ForegroundColor -eq "Yellow" }
88+
if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows)) {
89+
$result = Export-DevSetupEnv -Path "$TestDrive\MyCustomPath\MyEnv!.devsetup"
90+
$expectedPath = "$TestDrive\MyCustomPath\MyEnv.devsetup"
91+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux) {
92+
$result = Export-DevSetupEnv -Path "$TestDrive/MyCustomPath/MyEnv!.devsetup"
93+
$expectedPath = "$TestDrive/MyCustomPath/MyEnv.devsetup"
94+
} elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS) {
95+
$result = Export-DevSetupEnv -Path "$TestDrive/MyCustomPath/MyEnv!.devsetup"
96+
$expectedPath = "$TestDrive/MyCustomPath/MyEnv.devsetup"
97+
}
98+
$result | Should -Be $expectedPath
99+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "sanitized" -and $ForegroundColor -eq "Yellow" }
48100
}
49101
}
50102

@@ -53,7 +105,7 @@ Describe "Export-DevSetupEnv" {
53105
Mock Write-NewConfig { param($OutFile) $null }
54106
$result = Export-DevSetupEnv -Name "FailEnv"
55107
$result | Should -Be $null
56-
Assert-MockCalled Write-Error -Exactly 1 -Scope It -ParameterFilter { $Message -match "Failed to create configuration file" }
108+
Assert-MockCalled Write-StatusMessage -Exactly 1 -Scope It -ParameterFilter { $Message -match "Failed to create configuration file" -and $Verbosity -eq "Error" }
57109
}
58110
}
59111
}

DevSetup/Private/Commands/Export-DevSetupEnv.ps1

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
.EXAMPLE
2323
Export-DevSetupEnv -Name "MyCurrentSetup"
24-
24+
2525
Exports the current system state to a configuration file named "MyCurrentSetup.yaml".
2626
2727
.EXAMPLE
@@ -31,12 +31,12 @@
3131
} else {
3232
Write-Host "Export failed"
3333
}
34-
34+
3535
Demonstrates capturing the return value to verify export success.
3636
3737
.EXAMPLE
3838
Export-DevSetupEnv -Name "Data Science Environment!"
39-
39+
4040
The exclamation mark will be removed, resulting in "DataScienceEnvironment.yaml".
4141
A warning message will indicate the sanitization that occurred.
4242
@@ -65,7 +65,9 @@ Function Export-DevSetupEnv {
6565
[Parameter(Mandatory=$true, ParameterSetName="Export")]
6666
[string]$Name,
6767
[Parameter(Mandatory=$true, ParameterSetName="ExportPath")]
68-
[string]$Path
68+
[string]$Path,
69+
[Parameter(Mandatory=$false)]
70+
[switch]$DryRun
6971
)
7072
$OutFile = $null
7173
if($PSBoundParameters.ContainsKey('Name')) {
@@ -78,7 +80,7 @@ Function Export-DevSetupEnv {
7880
}
7981
$SanitizedEnvName = $Name -replace '[^a-zA-Z0-9\-\.]', ''
8082
if ($SanitizedEnvName -ne $Name) {
81-
Write-Host "EnvName sanitized from '$Name' to '$SanitizedEnvName' (removed non-alphanumeric characters)" -ForegroundColor Yellow
83+
Write-StatusMessage "EnvName sanitized from '$Name' to '$SanitizedEnvName' (removed non-alphanumeric characters)" -ForegroundColor Yellow
8284
}
8385

8486
$BasePath = Join-Path -Path (Get-DevSetupEnvPath) -ChildPath $Provider
@@ -96,25 +98,25 @@ Function Export-DevSetupEnv {
9698
if($Name -notlike "*.devsetup") {
9799
$Name = "$Name.devsetup"
98100
}
99-
101+
100102
$SanitizedEnvName = $Name -replace '[^a-zA-Z0-9\-\.]', ''
101103

102104
if ($SanitizedEnvName -ne $Name) {
103-
Write-Host "EnvName sanitized from '$Name' to '$SanitizedEnvName' (removed non-alphanumeric characters)" -ForegroundColor Yellow
105+
Write-StatusMessage "EnvName sanitized from '$Name' to '$SanitizedEnvName' (removed non-alphanumeric characters)" -ForegroundColor Yellow
104106
}
105107
$OutFile = Join-Path -Path $BasePath -ChildPath $SanitizedEnvName
106108
}
107109

108110
if(-not $OutFile) {
109-
Write-Error "Failed to determine output file path"
111+
Write-StatusMessage "Failed to determine output file path" -Verbosity Error
110112
return $null
111113
}
112114

113-
$config = Write-NewConfig -OutFile $OutFile
115+
$config = Write-NewConfig -OutFile $OutFile -DryRun:$DryRun
114116
if (-not $config) {
115-
Write-Error "Failed to create configuration file"
117+
Write-StatusMessage "Failed to create configuration file" -Verbosity Error
116118
return $null
117-
}
118-
Write-Host "Configuration file exported to: $OutFile" -ForegroundColor Green
119-
return $OutFile
119+
}
120+
Write-StatusMessage "Configuration file exported to: $OutFile" -ForegroundColor Green
121+
return $OutFile
120122
}

0 commit comments

Comments
 (0)