Skip to content

Commit 544ebcf

Browse files
Merge pull request #70 from WarehouseFinds/feature/dependencies
Refactor dependency resolution and update requirements format
2 parents dfe12b0 + 4ca7519 commit 544ebcf

File tree

3 files changed

+22
-76
lines changed

3 files changed

+22
-76
lines changed

.github/workflows/powershell-build-module.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ jobs:
135135
tag_name = 'v${{ env.majorMinorPatch }}'
136136
target_commitish = "main"
137137
previous_tag_name = $previousTag
138-
} | ConvertTo-Json
138+
}
139139
140140
$requestParams = @{
141141
Method = 'Post'
@@ -144,7 +144,7 @@ jobs:
144144
Authorization = "Bearer $env:GITHUB_TOKEN"
145145
Accept = 'application/vnd.github+json'
146146
}
147-
Body = $body
147+
Body = ($body | ConvertTo-Json)
148148
ContentType = 'application/json'
149149
}
150150
$result = Invoke-RestMethod @requestParams

.github/workflows/powershell-cache-dependencies.yml

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,27 @@ jobs:
1919
with:
2020
repository: ${{ github.repository }}
2121

22-
- name: Register PSRepositories
23-
shell: pwsh
24-
run: |
25-
# Register required PSRepositories
26-
$moduleRequirements = Import-PowerShellDataFile -Path './requirements.psd1'
27-
foreach ($repository in $moduleRequirements.Repositories) {
28-
$requestParams = @{
29-
Name = $repository.Name
30-
SourceLocation = $repository.SourceLocation
31-
PublishLocation = $repository.PublishLocation
32-
InstallationPolicy = $repository.InstallationPolicy
33-
ErrorAction = 'Stop'
34-
}
35-
[void] (Register-PSRepository @requestParams)
36-
}
37-
3822
- name: Resolve module dependencies
3923
id: resolve-dependencies
4024
shell: pwsh
4125
run: |
4226
# Resolve module dependencies from requirements.psd1
4327
$moduleRequirements = Import-PowerShellDataFile -Path './requirements.psd1'
44-
$packages = @($moduleRequirements.Packages)
4528
$moduleList = (
46-
$packages |
29+
$moduleRequirements.GetEnumerator() |
4730
ForEach-Object {
48-
$name = if ($_.Repository) {
49-
"$($_.Repository)\$($_.Name)"
31+
$moduleName = $_.Key
32+
$moduleInfo = $_.Value
33+
34+
$name = if ($moduleInfo.Repository -and $moduleInfo.Repository -ne 'PSGallery') {
35+
"$($moduleInfo.Repository)\$moduleName"
5036
}
5137
else {
52-
$_.Name
38+
$moduleName
5339
}
5440
55-
if ($_.Version -ne 'latest') {
56-
"$($name):$($_.Version)"
41+
if ($moduleInfo.Version -and $moduleInfo.Version -ne 'latest') {
42+
"$($name):$($moduleInfo.Version)"
5743
}
5844
else {
5945
"$($name)"
@@ -74,7 +60,6 @@ jobs:
7460
run: |
7561
# Verify that required modules are installed
7662
$moduleRequirements = Import-PowerShellDataFile -Path './requirements.psd1'
77-
$packages = @($moduleRequirements.Packages)
78-
foreach ($package in $packages) {
79-
Get-Module -ListAvailable -Name $package.Name -ErrorAction Stop
63+
foreach ($moduleName in $moduleRequirements.Keys) {
64+
Get-Module -ListAvailable -Name $moduleName -ErrorAction Stop
8065
}

requirements.psd1

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,11 @@
1-
# Project dependencies
1+
# PSDepend dependency specification
2+
# See https://github.com/RamblingCookieMonster/PSDepend for more information
23
@{
3-
Packages = @(
4-
@{
5-
Name = 'InvokeBuild'
6-
Repository = 'PSGallery'
7-
Type = 'Release'
8-
Version = '5.14.22'
9-
}
10-
@{
11-
Name = 'ModuleBuilder'
12-
Repository = 'PSGallery'
13-
Type = 'Release'
14-
Version = '3.1.8'
15-
}
16-
@{
17-
Name = 'Pester'
18-
Repository = 'PSGallery'
19-
Type = 'Release'
20-
Version = '5.7.1'
21-
}
22-
@{
23-
Name = 'PSScriptAnalyzer'
24-
Repository = 'PSGallery'
25-
Type = 'Release'
26-
Version = 'latest'
27-
}
28-
@{
29-
Name = 'InjectionHunter'
30-
Repository = 'PSGallery'
31-
Type = 'Release'
32-
Version = '1.0.0'
33-
}
34-
@{
35-
Name = 'Microsoft.PowerShell.PlatyPS'
36-
Repository = 'PSGallery'
37-
Type = 'Release'
38-
Version = '1.0.1'
39-
}
40-
)
41-
Repositories = @(
42-
# Default PSGallery repository, installed by PowerShellGet automatically
43-
<# @{
44-
Name = 'PSGallery'
45-
SourceLocation = 'https://www.powershellgallery.com/api/v2/'
46-
PublishLocation = 'https://www.powershellgallery.com/api/v2/package/'
47-
InstallationPolicy = 'Trusted'
48-
} #>
49-
)
4+
# Build and test dependencies
5+
'InvokeBuild' = @{ Version = '5.14.22'; Repository = 'PSGallery' }
6+
'ModuleBuilder' = @{ Version = '3.1.8'; Repository = 'PSGallery' }
7+
'Pester' = @{ Version = '5.7.1'; Repository = 'PSGallery' }
8+
'PSScriptAnalyzer' = @{ Version = 'latest'; Repository = 'PSGallery' }
9+
'InjectionHunter' = @{ Version = '1.0.0'; Repository = 'PSGallery' }
10+
'Microsoft.PowerShell.PlatyPS' = @{ Version = '1.0.1'; Repository = 'PSGallery' }
5011
}

0 commit comments

Comments
 (0)