-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublish-ModuleToGitHub.ps1
More file actions
291 lines (227 loc) · 8.96 KB
/
Publish-ModuleToGitHub.ps1
File metadata and controls
291 lines (227 loc) · 8.96 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<#
.SYNOPSIS
Prepares and publishes the ClientTool module to GitHub.
.DESCRIPTION
This script automates the process of preparing your ClientTool module for GitHub publication.
It cleans up backup files, initializes git repository, and provides guidance for publishing.
.PARAMETER Clean
Remove backup and temporary files from the module directory.
.PARAMETER Init
Initialize git repository and add remote.
.PARAMETER Commit
Add, commit, and push files to GitHub.
.PARAMETER Tag
Create and push a version tag.
.PARAMETER All
Perform all steps (clean, init, commit, tag).
.EXAMPLE
.\Publish-ModuleToGitHub.ps1 -Clean
Removes backup files from the module directory.
.EXAMPLE
.\Publish-ModuleToGitHub.ps1 -All
Performs all publishing steps.
.NOTES
Author: BackupNerd
Version: 1.0.0
Date: 2025-11-18
#>
[CmdletBinding(DefaultParameterSetName='Help')]
param(
[Parameter(ParameterSetName='Clean')]
[switch]$Clean,
[Parameter(ParameterSetName='Init')]
[switch]$Init,
[Parameter(ParameterSetName='Commit')]
[switch]$Commit,
[Parameter(ParameterSetName='Tag')]
[switch]$Tag,
[Parameter(ParameterSetName='All')]
[switch]$All,
[Parameter()]
[string]$GitHubRepo = "https://github.com/BackupNerd/ClientTool.git",
[Parameter()]
[string]$Version = "1.1.0",
[Parameter()]
[string]$CommitMessage = "Version $Version - Production release with enhanced features"
)
$ModulePath = $PSScriptRoot
Write-Host "`n╔════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ ClientTool Module - GitHub Publishing Helper ║" -ForegroundColor Cyan
Write-Host "╚════════════════════════════════════════════════════════════════╝`n" -ForegroundColor Cyan
function Write-Step {
param([string]$Message)
Write-Host "`n▶ $Message" -ForegroundColor Yellow
}
function Write-Success {
param([string]$Message)
Write-Host " ✓ $Message" -ForegroundColor Green
}
function Write-Info {
param([string]$Message)
Write-Host " ℹ $Message" -ForegroundColor Cyan
}
function Clean-ModuleDirectory {
Write-Step "Cleaning backup and temporary files..."
$backupFiles = @(
"ClientTool.psm1.afterwhatif",
"ClientTool.psm1.beforestyle",
"ClientTool.psm1.beforewhatif",
"ClientTool.psm1.complete-20251118-115336",
"ClientTool.psm1.final-20251118-114951",
"ClientTool.psm1.withhelperexamples"
)
foreach ($file in $backupFiles) {
$filePath = Join-Path $ModulePath $file
if (Test-Path $filePath) {
Remove-Item $filePath -Force
Write-Success "Removed: $file"
}
}
Write-Success "Cleanup complete"
}
function Initialize-GitRepository {
Write-Step "Initializing Git repository..."
Push-Location $ModulePath
try {
# Check if git repo exists
$isRepo = git rev-parse --git-dir 2>$null
if (-not $isRepo) {
git init
Write-Success "Git repository initialized"
} else {
Write-Info "Git repository already exists"
}
# Add remote if not exists
$remotes = git remote
if ($remotes -notcontains 'origin') {
git remote add origin $GitHubRepo
Write-Success "Added remote: $GitHubRepo"
} else {
Write-Info "Remote 'origin' already exists"
git remote set-url origin $GitHubRepo
Write-Success "Updated remote URL: $GitHubRepo"
}
# Verify .gitignore exists
if (-not (Test-Path (Join-Path $ModulePath ".gitignore"))) {
Write-Warning ".gitignore file not found! Create it before committing."
} else {
Write-Success ".gitignore file found"
}
} finally {
Pop-Location
}
}
function Commit-AndPush {
Write-Step "Committing and pushing to GitHub..."
Push-Location $ModulePath
try {
# Check for changes
$status = git status --porcelain
if (-not $status) {
Write-Info "No changes to commit"
return
}
# Add all files
git add .
Write-Success "Files staged"
# Show what will be committed
Write-Info "Files to be committed:"
git status --short
# Commit
git commit -m $CommitMessage
Write-Success "Changes committed"
# Set branch to main
$currentBranch = git branch --show-current
if ($currentBranch -ne 'main') {
git branch -M main
Write-Success "Branch renamed to 'main'"
}
# Push
Write-Info "Pushing to GitHub..."
git push -u origin main
Write-Success "Pushed to GitHub"
} catch {
Write-Error "Failed to commit/push: $_"
} finally {
Pop-Location
}
}
function Create-VersionTag {
Write-Step "Creating version tag v$Version..."
Push-Location $ModulePath
try {
# Check if tag exists
$tagExists = git tag -l "v$Version"
if ($tagExists) {
Write-Warning "Tag v$Version already exists"
$response = Read-Host "Do you want to delete and recreate it? (y/N)"
if ($response -eq 'y') {
git tag -d "v$Version"
git push origin ":refs/tags/v$Version" 2>$null
Write-Success "Deleted existing tag"
} else {
return
}
}
# Create tag
git tag -a "v$Version" -m "Version $Version"
Write-Success "Created tag: v$Version"
# Push tag
git push origin "v$Version"
Write-Success "Pushed tag to GitHub"
Write-Info "Tag URL: $($GitHubRepo -replace '\.git$','')/releases/tag/v$Version"
} catch {
Write-Error "Failed to create tag: $_"
} finally {
Pop-Location
}
}
function Show-NextSteps {
Write-Host "`n╔════════════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ Next Steps ║" -ForegroundColor Green
Write-Host "╚════════════════════════════════════════════════════════════════╝" -ForegroundColor Green
Write-Host "`n1. Create GitHub Repository (if not exists):" -ForegroundColor Yellow
Write-Host " https://github.com/new" -ForegroundColor Cyan
Write-Host " Repository name: ClientTool" -ForegroundColor White
Write-Host " Description: PowerShell module for N-able Cove Data Protection ClientTool.exe`n" -ForegroundColor White
Write-Host "2. Create GitHub Release:" -ForegroundColor Yellow
Write-Host " $($GitHubRepo -replace '\.git$','')/releases/new" -ForegroundColor Cyan
Write-Host " Tag: v$Version" -ForegroundColor White
Write-Host " Title: ClientTool v$Version - Production Release" -ForegroundColor White
Write-Host " See CHANGELOG.md for release notes`n" -ForegroundColor White
Write-Host "3. Users can now install with:" -ForegroundColor Yellow
Write-Host @"
```powershell
`$modulePath = "`$env:USERPROFILE\Documents\PowerShell\Modules\ClientTool"
New-Item -ItemType Directory -Path `$modulePath -Force
Invoke-WebRequest -Uri "$($GitHubRepo -replace '\.git$','')/archive/refs/heads/main.zip" -OutFile "`$env:TEMP\ClientTool.zip"
Expand-Archive -Path "`$env:TEMP\ClientTool.zip" -DestinationPath "`$env:TEMP\ClientTool" -Force
Copy-Item -Path "`$env:TEMP\ClientTool\ClientTool-main\*" -Destination `$modulePath -Recurse -Force
Import-Module ClientTool
```
"@ -ForegroundColor Cyan
Write-Host "`n4. Optional - Publish to PowerShell Gallery:" -ForegroundColor Yellow
Write-Host " Publish-Module -Name ClientTool -NuGetApiKey YOUR-API-KEY`n" -ForegroundColor Cyan
Write-Host "For detailed instructions, see: PUBLISHING-GUIDE.md`n" -ForegroundColor White
}
# Main execution
if ($PSCmdlet.ParameterSetName -eq 'Help') {
Get-Help $MyInvocation.MyCommand.Path -Full
exit
}
if ($All -or $Clean) {
Clean-ModuleDirectory
}
if ($All -or $Init) {
Initialize-GitRepository
}
if ($All -or $Commit) {
Commit-AndPush
}
if ($All -or $Tag) {
Create-VersionTag
}
if ($All) {
Show-NextSteps
}
Write-Host "`n✓ Publishing process complete!`n" -ForegroundColor Green