Repository navigation
125 lines (97 loc) · 3.65 KB
/
Copy pathpublishtopsgallery.yml
File metadata and controls
125 lines (97 loc) · 3.65 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Publish Monkey365 to PowerShell Gallery
on:
workflow_dispatch:
release:
types:
- published
permissions:
contents: read
jobs:
publish:
name: Publish Monkey365
runs-on: windows-latest
steps:
- name: Checkout released source
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ github.event.release.tag_name || github.ref }}
- name: Publish Monkey365
shell: powershell
env:
NUGET_KEY: ${{ secrets.PSGALLERY }}
run: |
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
if ([string]::IsNullOrWhiteSpace($env:NUGET_KEY)) {
throw "The PSGALLERY repository secret is missing or empty."
}
Write-Host "PowerShell version: $($PSVersionTable.PSVersion)"
Write-Host "Workspace: $env:GITHUB_WORKSPACE"
Write-Host "Ref: $env:GITHUB_REF"
Install-PackageProvider `
-Name NuGet `
-MinimumVersion 2.8.5.201 `
-Force
Set-PSRepository `
-Name PSGallery `
-InstallationPolicy Trusted
$moduleSource = Join-Path $env:GITHUB_WORKSPACE 'src/monkey365'
$moduleManifests = @(
Get-ChildItem `
-Path $moduleSource `
-Filter '*.psd1' `
-File
)
if ($moduleManifests.Count -ne 1) {
$found = $moduleManifests.FullName -join ', '
throw "Expected exactly one root module manifest, found $($moduleManifests.Count): $found"
}
$moduleManifest = $moduleManifests[0]
$manifest = Test-ModuleManifest -Path $moduleManifest.FullName
$moduleName = $moduleManifest.BaseName
$prerelease = $manifest.PrivateData.PSData.Prerelease
if ([string]::IsNullOrWhiteSpace($prerelease)) {
$version = $manifest.Version.ToString()
}
else {
$version = '{0}-{1}' -f (
$manifest.Version.ToString(),
$prerelease.TrimStart('-')
)
}
Write-Host "Module: $moduleName"
Write-Host "Version: $version"
$modulePath = Join-Path $env:RUNNER_TEMP $moduleName
New-Item -Path $modulePath -ItemType Directory -Force | Out-Null
Get-ChildItem -Path $moduleSource -Force |
Copy-Item -Destination $modulePath -Recurse -Force
Copy-Item `
-LiteralPath (Join-Path $env:GITHUB_WORKSPACE 'LICENSE') `
-Destination $modulePath
$stagedManifest = Join-Path $modulePath "$moduleName.psd1"
if (-not (Test-Path -LiteralPath $stagedManifest)) {
throw "Staged module manifest not found: $stagedManifest"
}
Test-ModuleManifest -Path $stagedManifest | Out-Null
$findParameters = @{
Name = $moduleName
RequiredVersion = $version
Repository = 'PSGallery'
ErrorAction = 'SilentlyContinue'
}
if ($prerelease) {
$findParameters.AllowPrerelease = $true
}
$existingModule = Find-Module @findParameters
if ($existingModule) {
Write-Host "$moduleName $version is already published."
exit 0
}
Publish-Module `
-Path $modulePath `
-Repository PSGallery `
-NuGetApiKey $env:NUGET_KEY `
-Force `
-Verbose
Write-Host "Publish request completed for $moduleName $version."