Repository navigation
86 lines (78 loc) · 3.03 KB
/
Copy pathDeploy.yml
File metadata and controls
86 lines (78 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Deploy
on:
push:
branches: [ main ]
workflow_dispatch:
defaults:
run:
shell: pwsh
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Discover Modules to Publish
id: discover
shell: pwsh
run: |
if ('${{ github.event_name }}' -eq 'workflow_dispatch') {
# Manual run: consider every module a candidate; the publish step
# then skips any whose version is already on the gallery.
$modules = Get-ChildItem -Path Modules -Directory | Select-Object -ExpandProperty Name
} else {
$changed = git diff --name-only HEAD~ HEAD
$changed
$modules = @()
foreach ($file in $changed) {
$parts = $file -split '/'
if ($parts.Length -ge 2 -and $parts[0] -eq 'Modules') {
$modules += $parts[1]
}
}
$modules = $modules | Sort-Object -Unique
}
Write-Host "Modules to consider: $($modules -join ', ')"
"modules=$($modules -join ',')" >> $env:GITHUB_OUTPUT
- name: Install PSResourceGet
if: steps.discover.outputs.modules != ''
shell: pwsh
run: |
if (-not (Get-Module -ListAvailable -Name Microsoft.PowerShell.PSResourceGet)) {
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force -Scope CurrentUser
}
- name: Publish to PowerShell Gallery
if: steps.discover.outputs.modules != ''
shell: pwsh
env:
PSGALLERY_API_KEY: ${{ secrets.POWERSHELL_GALLERY_API_KEY }}
run: |
Import-Module Microsoft.PowerShell.PSResourceGet
# Publish in dependency order: leaf modules first, umbrella last.
$order = @(
'IntelliTect.Common',
'IntelliTect.File',
'IntelliTect.Git',
'IntelliTect.PSToolbox'
)
$changed = '${{ steps.discover.outputs.modules }}' -split ','
foreach ($name in $order) {
if ($changed -notcontains $name) { continue }
$path = Join-Path '.' 'Modules' $name
$manifestPath = Join-Path $path "$name.psd1"
if (-not (Test-Path $manifestPath)) {
Write-Warning "Manifest not found for $name at $manifestPath; skipping."
continue
}
$data = Import-PowerShellDataFile -Path $manifestPath
$version = $data.ModuleVersion
Write-Host "Checking PSGallery for $name $version ..."
$existing = Find-PSResource -Name $name -Version $version -Repository PSGallery -ErrorAction SilentlyContinue
if ($existing) {
Write-Host "$name $version already on PSGallery; skipping."
continue
}
Write-Host "Publishing $name $version ..."
Publish-PSResource -Path $path -ApiKey $env:PSGALLERY_API_KEY -Repository PSGallery -SkipModuleManifestValidate -Verbose
}