-
Notifications
You must be signed in to change notification settings - Fork 4
304 lines (277 loc) · 13.2 KB
/
release.yml
File metadata and controls
304 lines (277 loc) · 13.2 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
292
293
294
295
296
297
298
299
300
301
302
303
304
name: MSUF
run-name: Publish ${{ github.event.release.tag_name || inputs.tag_name || github.ref_name }}
on:
push:
tags:
- "[0-9]*"
- "v[0-9]*"
release:
types:
- published
workflow_dispatch:
inputs:
tag_name:
description: Release tag to publish
required: true
type: string
prerelease:
description: Publish as beta on Wago and CurseForge
required: true
default: false
type: boolean
release_name:
description: Display name for GitHub, Wago, and CurseForge
required: false
type: string
permissions:
contents: write
jobs:
build:
if: github.repository == 'Mapkov2/MidnightSimpleUnitFrames'
runs-on: ubuntu-latest
env:
RELEASE_VERSION: ${{ github.event.release.tag_name || inputs.tag_name || github.ref_name }}
RELEASE_IS_PRERELEASE: ${{ github.event.release.prerelease || inputs.prerelease }}
RELEASE_NAME_INPUT: ${{ github.event.release.name || inputs.release_name }}
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.release.tag_name || inputs.tag_name || github.ref_name }}
fetch-depth: 0
- name: Validate publishing config
shell: pwsh
env:
WAGO_API_TOKEN: ${{ secrets.WAGO_API_TOKEN }}
CF_API_KEY: ${{ secrets.CF_API_KEY || secrets.CURSEFORGE }}
run: |
$expectedRepository = "Mapkov2/MidnightSimpleUnitFrames"
if ($env:GITHUB_REPOSITORY -ne $expectedRepository) {
throw "Publishing is only allowed from '$expectedRepository'. Current repository is '$($env:GITHUB_REPOSITORY)'."
}
$missing = @()
if ([string]::IsNullOrWhiteSpace($env:WAGO_API_TOKEN)) {
$missing += "secret WAGO_API_TOKEN"
}
if ([string]::IsNullOrWhiteSpace($env:CF_API_KEY)) {
$missing += "secret CF_API_KEY"
}
if ($missing.Count -gt 0) {
throw "Missing release publishing config: $($missing -join ', ')"
}
- name: Resolve release channel
id: channel
shell: pwsh
run: |
$tag = $env:RELEASE_VERSION
$isPrerelease = $env:RELEASE_IS_PRERELEASE -eq "true" -or $tag -match '(?i)(alpha|beta|rc|pre)'
$releaseName = $env:RELEASE_NAME_INPUT
if ([string]::IsNullOrWhiteSpace($releaseName)) {
$tagSubject = git for-each-ref "refs/tags/$tag" --format='%(contents:subject)' 2>$null
if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($tagSubject)) {
$releaseName = $tagSubject.Trim()
}
}
if ([string]::IsNullOrWhiteSpace($releaseName)) {
$displayVersion = $tag -replace '^refs/tags/', ''
$displayVersion = $displayVersion -replace '^v(?=\d)', ''
if ($displayVersion -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre)[\s._-]*(?<number>\d+(?:\.\d+)*))?\s*$') {
$base = (($Matches["base"] -split '\.') | ForEach-Object { [int]$_ }) -join "."
if ([string]::IsNullOrWhiteSpace($Matches["channel"])) {
$displayVersion = $base
} else {
$number = ""
if (-not [string]::IsNullOrWhiteSpace($Matches["number"])) {
$number = " " + ((($Matches["number"] -split '\.') | ForEach-Object { [int]$_ }) -join ".")
}
$channel = (Get-Culture).TextInfo.ToTitleCase($Matches["channel"].ToLowerInvariant()) -replace '\bRc\b', 'RC'
$displayVersion = ($base + " " + $channel + $number).Trim()
}
} else {
$displayVersion = $displayVersion -replace '(?i)[\-_]?beta[\-_.]?(\d+)', ' Beta $1'
$displayVersion = $displayVersion -replace '(?i)[\-_]?alpha[\-_.]?(\d+)', ' Alpha $1'
$displayVersion = $displayVersion -replace '(?i)[\-_]?rc[\-_.]?(\d+)', ' RC $1'
$displayVersion = $displayVersion -replace '[-_]+', ' '
$displayVersion = ($displayVersion -replace '\s+', ' ').Trim()
}
$releaseName = "MSUF $displayVersion"
}
$releaseName = ($releaseName -replace '[\r\n]+', ' ').Trim()
if ($tag -match '(?i)alpha') {
$wagoStability = "alpha"
$curseForgeType = "alpha"
} elseif ($isPrerelease) {
$wagoStability = "beta"
$curseForgeType = "beta"
} else {
$wagoStability = "stable"
$curseForgeType = "release"
}
"RELEASE_IS_PRERELEASE=$($isPrerelease.ToString().ToLowerInvariant())" >> $env:GITHUB_ENV
"WAGO_STABILITY=$wagoStability" >> $env:GITHUB_ENV
"CF_RELEASE_TYPE=$curseForgeType" >> $env:GITHUB_ENV
"RELEASE_NAME=$releaseName" >> $env:GITHUB_ENV
"release_is_prerelease=$($isPrerelease.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT
"github_make_latest=$(if ($isPrerelease) { 'false' } else { 'true' })" >> $env:GITHUB_OUTPUT
"release_name=$releaseName" >> $env:GITHUB_OUTPUT
Write-Host "Release $tag uses name '$releaseName', Wago stability '$wagoStability', and CurseForge type '$curseForgeType'."
- name: Build AddOns zip
shell: pwsh
run: |
./tools/update-addon-changelog.ps1 -Version $env:RELEASE_VERSION
./tools/package-release.ps1 -Version $env:RELEASE_VERSION
- name: Write GitHub release notes
shell: pwsh
run: |
function Normalize-Key([string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return "" }
$v = $value.Trim()
$v = $v -replace '^refs/tags/', ''
$v = $v -replace '^v(?=\d)', ''
if ($v -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre)[\s._-]*(?<number>\d+(?:\.\d+)*))?\s*$') {
$base = (($Matches["base"] -split '\.') | ForEach-Object { [int]$_ }) -join "x"
if ([string]::IsNullOrWhiteSpace($Matches["channel"])) { return $base }
$number = ""
if (-not [string]::IsNullOrWhiteSpace($Matches["number"])) {
$number = (($Matches["number"] -split '\.') | ForEach-Object { [int]$_ }) -join "x"
}
return ($base + $Matches["channel"].ToLowerInvariant() + $number)
}
return (($v.ToLowerInvariant()) -replace '[^a-z0-9]+', '')
}
function Get-PrereleaseFallbackKey([string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return "" }
$v = $value.Trim()
$v = $v -replace '^refs/tags/', ''
$v = $v -replace '^v(?=\d)', ''
if ($v -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre)[\s._-]*(?<number>\d+)\.\d+(?:\.\d+)*)\s*$') {
$base = (($Matches["base"] -split '\.') | ForEach-Object { [int]$_ }) -join "."
return Normalize-Key ($base + " " + $Matches["channel"] + " " + $Matches["number"])
}
return ""
}
function Convert-TagToDisplay([string]$tag) {
$display = $tag -replace '^refs/tags/', ''
$display = $display -replace '^v(?=\d)', ''
if ($display -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre)[\s._-]*(?<number>\d+(?:\.\d+)*))?\s*$') {
$base = (($Matches["base"] -split '\.') | ForEach-Object { [int]$_ }) -join "."
if ([string]::IsNullOrWhiteSpace($Matches["channel"])) { return $base }
$number = ""
if (-not [string]::IsNullOrWhiteSpace($Matches["number"])) {
$number = " " + ((($Matches["number"] -split '\.') | ForEach-Object { [int]$_ }) -join ".")
}
$channel = (Get-Culture).TextInfo.ToTitleCase($Matches["channel"].ToLowerInvariant()) -replace '\bRc\b', 'RC'
return ($base + " " + $channel + $number).Trim()
}
$display = $display -replace '(?i)[\-_]?beta[\-_.]?(\d+)', ' Beta $1'
$display = $display -replace '(?i)[\-_]?alpha[\-_.]?(\d+)', ' Alpha $1'
$display = $display -replace '(?i)[\-_]?rc[\-_.]?(\d+)', ' RC $1'
$display = $display -replace '(?i)[\-_]?pre[\-_.]?(\d+)', ' Pre $1'
$display = $display -replace '[-_]+', ' '
return (($display -replace '\s+', ' ').Trim())
}
$tag = $env:RELEASE_VERSION
$display = Convert-TagToDisplay $tag
$wanted = @(
(Normalize-Key $tag),
(Normalize-Key $display),
(Get-PrereleaseFallbackKey $tag),
(Get-PrereleaseFallbackKey $display)
) | Where-Object { $_ } | Select-Object -Unique
$lines = [regex]::Split((Get-Content -LiteralPath "CHANGELOG.md" -Raw), "\r?\n")
$start = -1
$end = $lines.Count
for ($i = 0; $i -lt $lines.Count; $i++) {
if ($lines[$i] -match '^##\s+(.+?)(?:\s+-\s+\d{4}-\d{2}-\d{2})?\s*$') {
if ($wanted -contains (Normalize-Key $Matches[1])) {
$start = $i
for ($j = $i + 1; $j -lt $lines.Count; $j++) {
if ($lines[$j] -match '^##\s+') {
$end = $j
break
}
}
break
}
}
}
if ($start -lt 0) {
throw "Could not find CHANGELOG.md section for release '$tag' ('$display')."
}
function Close-List {
if ($script:InList) {
$script:HtmlLines += "</ul>"
$script:InList = $false
}
}
function Add-HtmlLine([string]$line) {
$trimmed = $line.Trim()
if ([string]::IsNullOrWhiteSpace($trimmed)) {
Close-List
return
}
if ($trimmed -match '^###\s+(.+?)\s*$') {
Close-List
$script:HtmlLines += ("<h3>" + [System.Net.WebUtility]::HtmlEncode($Matches[1].Trim()) + "</h3>")
return
}
if ($trimmed -match '^##\s+(.+?)(?:\s+-\s+(\d{4}-\d{2}-\d{2}))?\s*$') {
Close-List
$title = [System.Net.WebUtility]::HtmlEncode($Matches[1].Trim())
if ($Matches.ContainsKey(2) -and -not [string]::IsNullOrWhiteSpace($Matches[2])) {
$title += " - " + [System.Net.WebUtility]::HtmlEncode($Matches[2].Trim())
}
$script:HtmlLines += ("<h2>" + $title + "</h2>")
return
}
if ($trimmed -match '^\-\s+(.+?)\s*$') {
if (-not $script:InList) {
$script:HtmlLines += "<ul>"
$script:InList = $true
}
$script:HtmlLines += ("<li>" + [System.Net.WebUtility]::HtmlEncode($Matches[1].Trim()) + "</li>")
return
}
Close-List
$script:HtmlLines += ("<p>" + [System.Net.WebUtility]::HtmlEncode($trimmed) + "</p>")
}
New-Item -ItemType Directory -Force -Path "dist" | Out-Null
$notes = [string[]]$lines[$start..($end - 1)]
[System.IO.File]::WriteAllText("dist/RELEASE_NOTES.md", (($notes -join [Environment]::NewLine).TrimEnd() + [Environment]::NewLine), [System.Text.UTF8Encoding]::new($false))
$script:HtmlLines = @()
$script:InList = $false
foreach ($line in $notes) {
Add-HtmlLine $line
}
Close-List
[System.IO.File]::WriteAllText("dist/RELEASE_NOTES_CF.html", (($script:HtmlLines -join [Environment]::NewLine).TrimEnd() + [Environment]::NewLine), [System.Text.UTF8Encoding]::new($false))
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.RELEASE_VERSION }}
name: ${{ steps.channel.outputs.release_name }}
files: dist/*.zip
body_path: dist/RELEASE_NOTES.md
fail_on_unmatched_files: true
overwrite_files: true
prerelease: ${{ steps.channel.outputs.release_is_prerelease }}
make_latest: ${{ steps.channel.outputs.github_make_latest }}
- name: Upload to Wago
shell: pwsh
env:
WAGO_API_TOKEN: ${{ secrets.WAGO_API_TOKEN }}
run: |
$zip = Get-ChildItem -Path dist -Filter "*.zip" | Select-Object -First 1
if (-not $zip) {
throw "No release zip found in dist."
}
if ($env:RELEASE_IS_PRERELEASE -eq "true") {
./tools/publish-wago.ps1 -Version $env:RELEASE_VERSION -ReleaseName $env:RELEASE_NAME -ZipPath $zip.FullName -ChangelogPath "dist/RELEASE_NOTES.md" -Stability $env:WAGO_STABILITY -Prerelease
} else {
./tools/publish-wago.ps1 -Version $env:RELEASE_VERSION -ReleaseName $env:RELEASE_NAME -ZipPath $zip.FullName -ChangelogPath "dist/RELEASE_NOTES.md" -Stability $env:WAGO_STABILITY
}
- name: Upload to CurseForge
uses: BigWigsMods/packager@v2
env:
CF_API_KEY: ${{ secrets.CF_API_KEY || secrets.CURSEFORGE }}
with:
args: -g retail -m .pkgmeta -n "{package-name}{project-version}:${{ steps.channel.outputs.release_name }}"