Skip to content

Commit 46691f9

Browse files
authored
Add export (#24)
1 parent fbd8913 commit 46691f9

File tree

6 files changed

+114
-30
lines changed

6 files changed

+114
-30
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: Checkout Repository
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323

2424
- name: Upload module
25-
uses: actions/upload-artifact@v3
25+
uses: actions/upload-artifact@v4
2626
with:
2727
name: module
2828
path: ./src/
@@ -35,26 +35,20 @@ jobs:
3535
runs-on: ${{ matrix.os }}
3636
steps:
3737
- name: Checkout Repository
38-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
3939

4040
- name: Install PSWSMan
4141
if: runner.os != 'Windows'
42-
run: Install-Module PSWSMan -Force -AllowClobber; Install-WSMan
42+
run: Install-PSResource PSWSMan -TrustRepository; Install-WSMan
4343

4444
- name: Install PSDesiredStateConfiguration
45-
run: Install-Module PSDesiredStateConfiguration -Force -AllowClobber
45+
run: Install-PSResource PSDesiredStateConfiguration -TrustRepository
4646

47-
- name: Install AnyPackage
48-
run: Install-Module AnyPackage -Force -AllowClobber
49-
50-
- name: Install PowerShellGet
51-
run: Install-Module PowerShellGet -AllowPrerelease -Force -AllowClobber
52-
53-
- name: Install AnyPackage.PowerShellGet
54-
run: Install-Module AnyPackage.PowerShellGet -Force -AllowClobber
47+
- name: Install AnyPackage.PSResourceGet
48+
run: Install-PSResource AnyPackage.PSResourceGet -TrustRepository
5549

5650
- name: Download module
57-
uses: actions/download-artifact@v3
51+
uses: actions/download-artifact@v4
5852
with:
5953
name: module
6054
path: AnyPackageDsc
@@ -81,10 +75,10 @@ jobs:
8175
runs-on: windows-latest
8276
steps:
8377
- name: Checkout Repository
84-
uses: actions/checkout@v3
78+
uses: actions/checkout@v4
8579

8680
- name: Download module
87-
uses: actions/download-artifact@v3
81+
uses: actions/download-artifact@v4
8882
with:
8983
name: module
9084
path: module
@@ -117,7 +111,7 @@ jobs:
117111
Set-AuthenticodeSignature @config
118112
119113
- name: Upload module
120-
uses: actions/upload-artifact@v3
114+
uses: actions/upload-artifact@v4
121115
with:
122116
name: module-signed
123117
path: ./module/
@@ -129,15 +123,17 @@ jobs:
129123
steps:
130124

131125
- name: Download module
132-
uses: actions/download-artifact@v3
126+
uses: actions/download-artifact@v4
133127
with:
134128
name: module-signed
135129
path: '~/.local/share/powershell/Modules/AnyPackageDsc'
136130

137131
- name: Install AnyPackage
138-
run: Install-Module AnyPackage -Force -AllowClobber
132+
run: Install-PSResource AnyPackage -TrustRepository
139133

140134
- name: Publish Module
141135
env:
142136
NUGET_KEY: ${{ secrets.NUGET_KEY }}
143-
run: Publish-Module -Name AnyPackageDsc -NuGetApiKey $env:NUGET_KEY
137+
run: |
138+
$module = Get-Module AnyPackageDsc -ListAvailable
139+
Publish-PSResource $module.ModuleBase -ApiKey $env:NUGET_KEY

.github/workflows/lint-powershell.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,32 @@ jobs:
2424
runs-on: ubuntu-latest
2525
steps:
2626
- name: Checkout Repository
27-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4
28+
29+
- name: Move module
30+
run: |
31+
if ($IsWindows) {
32+
$path = "$HOME\Documents\PowerShell\Modules"
33+
} else {
34+
$path = "$HOME/.local/share/powershell/Modules"
35+
}
36+
37+
Copy-Item src AnyPackageDsc
38+
Copy-Item AnyPackageDsc $path
39+
Get-Module AnyPackageDsc -ListAvailable
2840
2941
- name: Install AnyPackage
30-
run: Install-Module AnyPackage -Force -AllowClobber
42+
run: Install-PSResource AnyPackage -TrustRepository
3143

3244
- name: Install ConvertToSARIF
33-
run: Install-Module ConvertToSARIF -Force
34-
35-
- name: Install PowerShellGet
36-
run: Install-Module PowerShellGet -Force -AllowClobber -AllowPrerelease
45+
run: Install-PSResource ConvertToSARIF -TrustRepository
3746

3847
- name: Run PSScriptAnalyzer
3948
run: |
40-
Import-Module AnyPackage, ConvertToSARIF, PowerShellGet -PassThru
41-
Invoke-ScriptAnalyzer -Path . -Recurse | ConvertTo-SARIF -FilePath results.sarif
49+
Import-Module AnyPackage, ConvertToSARIF -PassThru
50+
Invoke-ScriptAnalyzer -Path ./src -Recurse | ConvertTo-SARIF -FilePath results.sarif
4251
4352
- name: Upload SARIF results file
44-
uses: github/codeql-action/upload-sarif@v2
53+
uses: github/codeql-action/upload-sarif@v3
4554
with:
4655
sarif_file: results.sarif

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ AnyPackage DSC resources module.
1616
## Install AnyPackageDsc
1717

1818
```powershell
19-
Install-Module AnyPackageDsc
19+
Install-PSResource AnyPackageDsc
2020
```
2121

2222
## Documentation

src/AnyPackageDsc.psm1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ class Package {
4545
[DscProperty(NotConfigurable)]
4646
[APReason[]] $Reasons
4747

48+
static [Package[]] Export() {
49+
Get-PackageProvider -ListAvailable |
50+
Select-Object -ExpandProperty ModuleName -Unique |
51+
Import-Module
52+
53+
$packages = @()
54+
foreach ($installedPackage in (Get-Package -ErrorAction Stop)) {
55+
$package = [Package]::new()
56+
$package.Name = $installedPackage.Name
57+
$package.Provider = $installedPackage.Provider.FullName
58+
59+
if ($installedPackage.Version) {
60+
$package.Version = $installedPackage.Version
61+
$package.Prerelease = $installedPackage.Version.IsPrerelease
62+
} else {
63+
$package.Version = '*'
64+
}
65+
66+
$package.Source = $installedPackage.Source
67+
$packages += $package
68+
}
69+
70+
return $packages
71+
}
72+
4873
[Package] Get() {
4974
$currentState = [Package]@{
5075
Name = $this.Name
@@ -187,6 +212,24 @@ class Source {
187212
[DscProperty(NotConfigurable)]
188213
[APReason[]] $Reasons
189214

215+
static [Source[]] Export() {
216+
Get-PackageProvider -ListAvailable |
217+
Select-Object -ExpandProperty ModuleName -Unique |
218+
Import-Module
219+
220+
$sources = @()
221+
foreach ($installedSource in (Get-PackageSource -ErrorAction Stop)) {
222+
$source = [Source]::new()
223+
$source.Name = $installedSource.Name
224+
$source.Provider = $installedSource.Provider.FullName
225+
$source.Location = $installedSource.Location
226+
$source.Trusted = $installedSource.Trusted
227+
$sources += $source
228+
}
229+
230+
return $sources
231+
}
232+
190233
[Source] Get() {
191234
$currentState = [Source]@{
192235
Name = $this.Name

test/Package.Tests.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#requires -modules AnyPackageDsc, AnyPackage.PSResourceGet
2+
3+
using module AnyPackageDsc
4+
5+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
6+
param()
7+
8+
Describe 'Package' {
9+
Context 'Export' {
10+
BeforeAll {
11+
$results = [Package]::Export()
12+
}
13+
14+
It 'should return packages' {
15+
$results | Should -Not -BeNullOrEmpty
16+
}
17+
}
18+
}

test/Source.Tests.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#requires -modules AnyPackageDsc, AnyPackage.PSResourceGet
2+
3+
using module AnyPackageDsc
4+
5+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
6+
param()
7+
8+
Describe 'Source' {
9+
Context 'Export' {
10+
BeforeAll {
11+
$results = [Source]::Export()
12+
}
13+
14+
It 'should return sources' {
15+
$results | Should -Not -BeNullOrEmpty
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)