Repository navigation
Expand file tree
/
Copy pathrelease.ps1
More file actions
162 lines (131 loc) · 4.06 KB
/
Copy pathrelease.ps1
File metadata and controls
162 lines (131 loc) · 4.06 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
param(
[Parameter(Mandatory = $true)]
[string]$Tag
)
$ErrorActionPreference = "Stop"
$ProjectPath = ".\MibExplorer\MibExplorer.csproj"
$PublishDir = ".\MibExplorer\bin\Release\net8.0-windows\win-x64\publish"
$ArtifactsDir = ".\.artifacts"
$ZipName = "MibExplorer_$Tag" + "_win-x64.zip"
$ZipPath = Join-Path $ArtifactsDir $ZipName
$ReleaseNotes = ".\RELEASE_NOTES.md"
function Fail($msg) {
Write-Host ""
Write-Host "ERROR: $msg" -ForegroundColor Red
exit 1
}
function Ensure-Command($name) {
if (-not (Get-Command $name -ErrorAction SilentlyContinue)) {
Fail "$name is not installed or not in PATH."
}
}
function Write-Step($msg) {
Write-Host ""
Write-Host "==> $msg" -ForegroundColor Cyan
}
Write-Host ""
Write-Host "MibExplorer release script" -ForegroundColor Green
Write-Host "Tag: $Tag" -ForegroundColor Yellow
Write-Step "Checking required tools"
Ensure-Command git
Ensure-Command dotnet
Ensure-Command gh
Write-Step "Checking GitHub CLI authentication"
gh auth status | Out-Null
if ($LASTEXITCODE -ne 0) {
Fail "GitHub CLI is not authenticated. Run: gh auth login"
}
Write-Step "Checking git repository"
git rev-parse --is-inside-work-tree | Out-Null
if ($LASTEXITCODE -ne 0) {
Fail "Current folder is not inside a git repository."
}
Write-Step "Checking working tree"
$gitStatus = git status --porcelain
if ($gitStatus) {
Fail "Working tree is not clean. Commit or stash changes before running the release script."
}
Write-Step "Checking release notes"
if (-not (Test-Path $ReleaseNotes)) {
Fail "Release notes file not found: $ReleaseNotes"
}
$notesContent = Get-Content $ReleaseNotes -Raw
if ([string]::IsNullOrWhiteSpace($notesContent)) {
Fail "RELEASE_NOTES.md is empty."
}
Write-Step "Checking that tag does not already exist"
$localTag = git tag --list $Tag
if ($localTag) {
Fail "Tag '$Tag' already exists locally."
}
$remoteTag = git ls-remote --tags origin "refs/tags/$Tag"
if ($remoteTag) {
Fail "Tag '$Tag' already exists on remote."
}
Write-Step "Creating annotated tag"
git tag -a $Tag -m "Release $Tag"
if ($LASTEXITCODE -ne 0) {
Fail "Failed to create git tag."
}
Write-Step "Pushing tag"
git push origin $Tag
if ($LASTEXITCODE -ne 0) {
Fail "Failed to push tag."
}
Write-Step "Preparing artifacts folder"
if(-not (Test-Path $ArtifactsDir)) {
New-Item -ItemType Directory -Force -Path $ArtifactsDir | Out-Null
(Get-Item $ArtifactsDir).Attributes += 'Hidden'
}
if (Test-Path $ZipPath) {
Remove-Item $ZipPath -Force
}
if (Test-Path $PublishDir) {
Write-Step "Cleaning publish directory"
Remove-Item $PublishDir -Recurse -Force
}
Write-Step "Publishing application"
dotnet publish $ProjectPath `
-c Release `
-r win-x64 `
--self-contained true `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-p:EnableCompressionInSingleFile=true `
-p:PublishTrimmed=false `
-p:DebugType=None `
-p:DebugSymbols=false
if ($LASTEXITCODE -ne 0) {
Fail "dotnet publish failed."
}
if (-not (Test-Path $PublishDir)) {
Fail "Publish directory not found: $PublishDir"
}
Write-Step "Writing git-tag.txt"
Set-Content -Path (Join-Path $PublishDir "git-tag.txt") -Value $Tag -NoNewLine
Write-Step "Removing unnecessary publish files"
Get-ChildItem $PublishDir -Filter "*.pdb" -File -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Step "Creating zip"
Compress-Archive -Path "$PublishDir\*" -DestinationPath $ZipPath
if (-not (Test-Path $ZipPath)) {
Fail "Zip was not created: $ZipPath"
}
Write-Step "Creating GitHub release"
gh release create $Tag $ZipPath --title "MibExplorer $Tag" --notes-file $ReleaseNotes
if ($LASTEXITCODE -ne 0) {
Fail "Failed to create GitHub release."
}
Write-Step "Deleting local zip"
Remove-Item $ZipPath -Force
Write-Step "Resetting RELEASE_NOTES.md"
@"
# Release Notes
## Added
## Improved
## Fixed
## Cleanup
"@ | Set-Content $ReleaseNotes
Write-Host ""
Write-Host "Release completed successfully." -ForegroundColor Green
Write-Host "Tag: $Tag"
Write-Host "Release notes have been reset."