-
Notifications
You must be signed in to change notification settings - Fork 9
840 lines (755 loc) · 38.4 KB
/
Copy pathrelease.yml
File metadata and controls
840 lines (755 loc) · 38.4 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
name: MSUF
run-name: Publish ${{ inputs.tag_name || github.ref_name }}
on:
push:
tags:
- "[0-9]*"
- "v[0-9]*"
- "MSUF_[0-9]*"
workflow_dispatch:
inputs:
tag_name:
description: Release tag to publish
required: true
type: string
prerelease:
description: Publish as alpha/beta on GitHub or CurseForge; Wago rejects prerelease tags
required: true
default: false
type: boolean
release_name:
description: Display name for GitHub, Wago, and CurseForge
required: false
type: string
publish_target:
description: Publish destination
required: true
default: github
type: choice
options:
- all
- github
- wago
- curseforge
- wago+curseforge
permissions:
contents: write
jobs:
build:
if: github.repository == 'Mapkov2/MidnightSimpleUnitFrames'
runs-on: ubuntu-latest
env:
RELEASE_VERSION: ${{ inputs.tag_name || github.ref_name }}
RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }}
RELEASE_NAME_INPUT: ${{ inputs.release_name }}
RELEASE_PUBLISH_TARGET_INPUT: ${{ inputs.publish_target }}
steps:
- uses: actions/checkout@v5
with:
ref: ${{ inputs.tag_name || github.ref_name }}
fetch-depth: 0
# A bulk `git push --tags` can surface forgotten local beta tags months
# later. Prerelease tags are publishable only when they point at the
# current main commit; stale alpha/beta/RC refs fail before any package or
# external upload is created.
- name: Reject stale prerelease tags
shell: pwsh
run: |
function Test-PrereleaseSignal([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return $false }
$v = $value.Trim()
return (
($v -match '(?i)(alpha|beta|rc|pre|preview)') -or
($v -match '(?i)\d+(?:\.\d+)*[AB]\d+(?:$|[^A-Za-z0-9])') -or
($v -match '(?i)(^|[^A-Za-z0-9])[AB]\d+(?:$|[^A-Za-z0-9])')
)
}
$tag = $env:RELEASE_VERSION
if (Test-PrereleaseSignal $tag) {
git fetch --no-tags origin "+refs/heads/main:refs/remotes/origin/main"
if ($LASTEXITCODE -ne 0) {
throw "Could not resolve origin/main for prerelease freshness validation."
}
$tagCommit = (git rev-list -n 1 "refs/tags/$tag" 2>$null)
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($tagCommit)) {
throw "Could not resolve prerelease tag '$tag' to a commit."
}
$mainCommit = (git rev-parse "refs/remotes/origin/main" 2>$null)
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($mainCommit)) {
throw "Could not resolve origin/main to a commit."
}
$tagCommit = $tagCommit.Trim()
$mainCommit = $mainCommit.Trim()
if ($tagCommit -ne $mainCommit) {
throw "Refusing stale prerelease tag '$tag' at $tagCommit; current origin/main is $mainCommit. Push only the intended current release tag, never 'git push --tags'."
}
Write-Host "Prerelease tag '$tag' is current at origin/main $mainCommit."
}
# Verification (static checks, core smokes, search-index check) is
# local-only and deliberately absent from the repo, so this workflow
# packages and publishes without re-running it. Run the suite on the
# dev machine before tagging.
- name: Resolve publish target
id: publish
shell: pwsh
run: |
$target = $env:RELEASE_PUBLISH_TARGET_INPUT
$tag = $env:RELEASE_VERSION
$tagContents = ""
if (-not [string]::IsNullOrWhiteSpace($tag)) {
$tagRef = "refs/tags/$tag"
git fetch --force origin "$($tagRef):$($tagRef)" 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Warning "Could not fetch tag annotation for '$tag'. Falling back to workflow input/default publish target."
}
$tagContentLines = @(git for-each-ref $tagRef --format='%(contents)' 2>$null)
if ($LASTEXITCODE -ne 0) {
$tagContents = ""
} else {
$tagContents = $tagContentLines -join [Environment]::NewLine
}
}
# A manual dispatch is an explicit recovery/routing instruction and
# takes precedence over the immutable release tag annotation.
if ($env:GITHUB_EVENT_NAME -ne "workflow_dispatch" -and
-not [string]::IsNullOrWhiteSpace($tagContents)) {
$match = [regex]::Match($tagContents, '(?im)^\s*publish-target\s*:\s*(all|github|wago|curseforge|wago\+curseforge)\s*$')
if ($match.Success) {
$target = $match.Groups[1].Value
}
}
# Fail closed: an unannotated tag may create a GitHub release, but it
# must never upload to Wago or CurseForge implicitly.
if ([string]::IsNullOrWhiteSpace($target)) {
$target = "github"
}
$target = $target.Trim().ToLowerInvariant()
if ($target -notin @("all", "github", "wago", "curseforge", "wago+curseforge")) {
throw "Invalid publish target '$target'. Use all, github, wago, curseforge, or wago+curseforge."
}
$isPrereleaseTag = (
($tag -match '(?i)(alpha|beta|rc|pre|preview)') -or
($tag -match '(?i)\d+(?:\.\d+)*[AB]\d+(?:$|[^A-Za-z0-9])') -or
($tag -match '(?i)(^|[^A-Za-z0-9])[AB]\d+(?:$|[^A-Za-z0-9])')
)
if ($isPrereleaseTag -and $target -in @("all", "wago")) {
throw "Wago prerelease publishing is disabled. Tag '$tag' must use publish-target: curseforge or publish-target: github."
}
$publishToGitHub = $target -eq "all" -or $target -eq "github"
$publishToWago = $target -eq "all" -or $target -eq "wago" -or $target -eq "wago+curseforge"
$publishToCurseForge = $target -eq "all" -or $target -eq "curseforge" -or $target -eq "wago+curseforge"
"PUBLISH_TARGET=$target" >> $env:GITHUB_ENV
"PUBLISH_TO_GITHUB=$($publishToGitHub.ToString().ToLowerInvariant())" >> $env:GITHUB_ENV
"PUBLISH_TO_WAGO=$($publishToWago.ToString().ToLowerInvariant())" >> $env:GITHUB_ENV
"PUBLISH_TO_CURSEFORGE=$($publishToCurseForge.ToString().ToLowerInvariant())" >> $env:GITHUB_ENV
"target=$target" >> $env:GITHUB_OUTPUT
"publish_to_github=$($publishToGitHub.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT
"publish_to_wago=$($publishToWago.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT
"publish_to_curseforge=$($publishToCurseForge.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT
Write-Host "Publish target: $target. GitHub=$publishToGitHub Wago=$publishToWago CurseForge=$publishToCurseForge."
- 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 ($env:PUBLISH_TO_WAGO -eq "true" -and [string]::IsNullOrWhiteSpace($env:WAGO_API_TOKEN)) {
$missing += "secret WAGO_API_TOKEN"
}
if ($env:PUBLISH_TO_CURSEFORGE -eq "true" -and [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: |
function Test-AlphaReleaseSignal([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return $false }
$v = $value.Trim()
return (
($v -match '(?i)alpha') -or
($v -match '(?i)\d+(?:\.\d+)*A\d+(?:$|[^A-Za-z0-9])') -or
($v -match '(?i)(^|[^A-Za-z0-9])A\d+(?:$|[^A-Za-z0-9])')
)
}
function Test-BetaReleaseSignal([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return $false }
$v = $value.Trim()
return (
($v -match '(?i)beta') -or
($v -match '(?i)\d+(?:\.\d+)*B\d+(?:$|[^A-Za-z0-9])') -or
($v -match '(?i)(^|[^A-Za-z0-9])B\d+(?:$|[^A-Za-z0-9])')
)
}
function Test-PrereleaseSignal([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return $false }
return ((Test-AlphaReleaseSignal $value) -or (Test-BetaReleaseSignal $value) -or ($value.Trim() -match '(?i)(rc|pre|preview)'))
}
function Normalize-ReleaseInput([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return "" }
$v = $value.Trim()
$v = $v -replace '^refs/tags/', ''
$v = $v -replace '(?i)^MSUF[\s._-]*', ''
$v = $v -replace '^v(?=\d)', ''
return $v
}
function Get-FileFirstLine([string]$path) {
if (-not (Test-Path -LiteralPath $path)) { return "" }
$line = Get-Content -LiteralPath $path | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -First 1
if ($line) { return $line.Trim() }
return ""
}
function Get-TocVersion([string]$path) {
if (-not (Test-Path -LiteralPath $path)) { return "" }
$content = Get-Content -LiteralPath $path -Raw
$match = [regex]::Match($content, '(?m)^##\s+Version:\s*(.+?)\s*$')
if ($match.Success) { return $match.Groups[1].Value.Trim() }
return ""
}
function Convert-AlphaTagToReleaseName([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return "" }
$v = Normalize-ReleaseInput $value
if ($v -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?:alpha|a)[\s._-]*(?<number>\d+(?:\.\d+)*))\s*$') {
$base = (($Matches["base"] -split '\.') | ForEach-Object { [int]$_ }) -join "."
$number = (($Matches["number"] -split '\.') | ForEach-Object { [int]$_ }) -join "."
return "MSUF_${base}A$number"
}
return ""
}
$tag = $env:RELEASE_VERSION
$eventIsPrerelease = $env:RELEASE_IS_PRERELEASE -eq "true"
$tagContents = ""
$tagContentLines = @(git for-each-ref "refs/tags/$tag" --format='%(contents)' 2>$null)
if ($LASTEXITCODE -eq 0) {
$tagContents = $tagContentLines -join [Environment]::NewLine
}
$tagRequestsCurseForgeBeta = -not [string]::IsNullOrWhiteSpace($tagContents) -and
[regex]::IsMatch($tagContents, '(?im)^\s*curseforge-channel\s*:\s*beta\s*$')
$curseForgeGameVersion = ""
if (-not [string]::IsNullOrWhiteSpace($tagContents)) {
$gameVersionMatches = [regex]::Matches($tagContents, '(?im)^\s*curseforge-game-version\s*:\s*(\d+\.\d+\.\d+)\s*$')
if ($gameVersionMatches.Count -gt 1) {
throw "Release tag '$tag' declares curseforge-game-version more than once."
}
if ($gameVersionMatches.Count -eq 1) {
$curseForgeGameVersion = $gameVersionMatches[0].Groups[1].Value
}
}
$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)) {
$alphaReleaseName = Convert-AlphaTagToReleaseName $tag
if (-not [string]::IsNullOrWhiteSpace($alphaReleaseName)) {
$releaseName = $alphaReleaseName
} else {
$displayVersion = Normalize-ReleaseInput $tag
if ($displayVersion -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre|a|b)[\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 ".")
}
$channelKey = $Matches["channel"].ToLowerInvariant()
if ($channelKey -eq "a") { $channelKey = "alpha" }
if ($channelKey -eq "b") { $channelKey = "beta" }
$channel = (Get-Culture).TextInfo.ToTitleCase($channelKey) -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()
# CurseForge file labels follow the compact project convention and
# must never inherit a descriptive annotated-tag subject. Stability
# is carried separately by CF_RELEASE_TYPE.
$curseForgeVersion = Normalize-ReleaseInput $tag
if ($curseForgeVersion -notmatch '^[0-9][0-9A-Za-z._-]*$') {
throw "Cannot derive a safe CurseForge display version from tag '$tag'."
}
$curseForgeDisplayName = "MSUF_$curseForgeVersion"
$versionFileValue = Get-FileFirstLine "VERSION"
$tocVersionValue = Get-TocVersion "MidnightSimpleUnitFrames/MidnightSimpleUnitFrames.toc"
$releaseSignals = @($tag, $releaseName, $versionFileValue, $tocVersionValue)
$hasAlphaSignal = @($releaseSignals | Where-Object { Test-AlphaReleaseSignal $_ } | Select-Object -First 1).Count -gt 0
$hasPrereleaseSignal = @($releaseSignals | Where-Object { Test-PrereleaseSignal $_ } | Select-Object -First 1).Count -gt 0
$isPrerelease = $eventIsPrerelease -or $hasPrereleaseSignal
if ($hasAlphaSignal) {
$wagoStability = "alpha"
$curseForgeType = "alpha"
} elseif ($isPrerelease) {
$wagoStability = "beta"
$curseForgeType = "beta"
} else {
$wagoStability = "stable"
$curseForgeType = if ($tagRequestsCurseForgeBeta) { "beta" } else { "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
"CURSEFORGE_DISPLAY_NAME=$curseForgeDisplayName" >> $env:GITHUB_ENV
"CURSEFORGE_GAME_VERSION=$curseForgeGameVersion" >> $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
"curseforge_display_name=$curseForgeDisplayName" >> $env:GITHUB_OUTPUT
$curseForgeGameVersionLabel = if ($curseForgeGameVersion) { $curseForgeGameVersion } else { "highest declared TOC interface" }
Write-Host "Release $tag uses name '$releaseName', CurseForge name '$curseForgeDisplayName', Wago stability '$wagoStability', CurseForge type '$curseForgeType', and CurseForge game version '$curseForgeGameVersionLabel' (CurseForge beta override=$tagRequestsCurseForgeBeta)."
- name: Enforce prerelease channels for prerelease tags
shell: pwsh
run: |
function Test-AlphaReleaseSignal([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return $false }
$v = $value.Trim()
return (
($v -match '(?i)alpha') -or
($v -match '(?i)\d+(?:\.\d+)*A\d+(?:$|[^A-Za-z0-9])') -or
($v -match '(?i)(^|[^A-Za-z0-9])A\d+(?:$|[^A-Za-z0-9])')
)
}
function Test-BetaReleaseSignal([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return $false }
$v = $value.Trim()
return (
($v -match '(?i)beta') -or
($v -match '(?i)\d+(?:\.\d+)*B\d+(?:$|[^A-Za-z0-9])') -or
($v -match '(?i)(^|[^A-Za-z0-9])B\d+(?:$|[^A-Za-z0-9])')
)
}
function Test-PrereleaseSignal([AllowNull()][string]$value) {
if ([string]::IsNullOrWhiteSpace($value)) { return $false }
return ((Test-AlphaReleaseSignal $value) -or (Test-BetaReleaseSignal $value) -or ($value.Trim() -match '(?i)(rc|pre|preview)'))
}
function Get-FileFirstLine([string]$path) {
if (-not (Test-Path -LiteralPath $path)) { return "" }
$line = Get-Content -LiteralPath $path | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -First 1
if ($line) { return $line.Trim() }
return ""
}
function Get-TocVersion([string]$path) {
if (-not (Test-Path -LiteralPath $path)) { return "" }
$content = Get-Content -LiteralPath $path -Raw
$match = [regex]::Match($content, '(?m)^##\s+Version:\s*(.+?)\s*$')
if ($match.Success) { return $match.Groups[1].Value.Trim() }
return ""
}
$alphaSignals = @(
$env:RELEASE_VERSION,
$env:RELEASE_NAME,
(Get-FileFirstLine "VERSION"),
(Get-TocVersion "MidnightSimpleUnitFrames/MidnightSimpleUnitFrames.toc")
) | Where-Object { Test-AlphaReleaseSignal $_ }
$prereleaseSignals = @(
$env:RELEASE_VERSION,
$env:RELEASE_NAME,
(Get-FileFirstLine "VERSION"),
(Get-TocVersion "MidnightSimpleUnitFrames/MidnightSimpleUnitFrames.toc")
) | Where-Object { Test-PrereleaseSignal $_ }
if ($alphaSignals) {
if ($env:WAGO_STABILITY -ne "alpha" -or $env:CF_RELEASE_TYPE -ne "alpha") {
throw "Alpha signal '$($alphaSignals[0])' must publish as alpha. Got Wago '$env:WAGO_STABILITY' and CurseForge '$env:CF_RELEASE_TYPE'."
}
}
if ($prereleaseSignals) {
if ($env:WAGO_STABILITY -eq "stable" -or $env:CF_RELEASE_TYPE -eq "release") {
throw "Prerelease signal '$($prereleaseSignals[0])' must not publish as stable/release. Got Wago '$env:WAGO_STABILITY' and CurseForge '$env:CF_RELEASE_TYPE'."
}
if ($env:PUBLISH_TO_WAGO -eq "true") {
throw "Wago prerelease publishing is disabled. Refusing '$($prereleaseSignals[0])'."
}
}
# The authoritative Assistant release gate is part of the local-only
# verification suite and no longer runs here. Run it on the dev machine
# before tagging a stable release, where the Assistant is promised to be
# complete.
- name: Build AddOns zip
shell: pwsh
run: |
# Fail-closed helper stages MidnightSimpleUnitFrames plus MidnightSimpleUnitFrames_Assistant.
& "./.github/scripts/build_release_package.ps1" -ReleaseVersion $env:RELEASE_VERSION -OutputDirectory "dist"
- 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 '(?i)^MSUF[\s._-]*', ''
$v = $v -replace '^v(?=\d)', ''
if ($v -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre|a|b)[\s._-]*(?<number>\d+(?:\.\d+)*))?\s*$') {
$base = (($Matches["base"] -split '\.') | ForEach-Object { [int]$_ }) -join "x"
if ([string]::IsNullOrWhiteSpace($Matches["channel"])) { return $base }
$channel = $Matches["channel"].ToLowerInvariant()
if ($channel -eq "a") { $channel = "alpha" }
if ($channel -eq "b") { $channel = "beta" }
$number = ""
if (-not [string]::IsNullOrWhiteSpace($Matches["number"])) {
$number = (($Matches["number"] -split '\.') | ForEach-Object { [int]$_ }) -join "x"
}
return ($base + $channel + $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 '(?i)^MSUF[\s._-]*', ''
$v = $v -replace '^v(?=\d)', ''
if ($v -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre|a|b)[\s._-]*(?<number>\d+)\.\d+(?:\.\d+)*)\s*$') {
$base = (($Matches["base"] -split '\.') | ForEach-Object { [int]$_ }) -join "."
$channel = $Matches["channel"].ToLowerInvariant()
if ($channel -eq "a") { $channel = "alpha" }
if ($channel -eq "b") { $channel = "beta" }
return Normalize-Key ($base + " " + $channel + " " + $Matches["number"])
}
return ""
}
function Convert-TagToDisplay([string]$tag) {
$display = $tag -replace '^refs/tags/', ''
$display = $display -replace '(?i)^MSUF[\s._-]*', ''
$display = $display -replace '^v(?=\d)', ''
if ($display -match '^(?<base>\d+(?:\.\d+)*)(?:[\s._-]*(?<channel>alpha|beta|rc|pre|a|b)[\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 ".")
}
$channelKey = $Matches["channel"].ToLowerInvariant()
if ($channelKey -eq "a") { $channelKey = "alpha" }
if ($channelKey -eq "b") { $channelKey = "beta" }
$channel = (Get-Culture).TextInfo.ToTitleCase($channelKey) -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
# Distribution pages always receive only this version's patch notes.
# The long-form migration/archive document is never a publish source.
$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')."
}
# msuf-menu-link comments are private metadata for the interactive
# in-game changelog. Discord and distribution sites do not all honor
# HTML comments, so never include them in public release notes.
$notes = [string[]]@($lines[$start..($end - 1)] | Where-Object {
$_ -notmatch '^\s*<!--\s*msuf-menu-link:\s*(?:\{.*\}|none)\s*-->\s*$'
})
function Close-List {
if ($script:InList) {
$script:HtmlLines += "</ul>"
$script:InList = $false
}
}
function Add-HtmlLine([string]$line) {
$trimmed = $line.Trim()
if ($trimmed -match '^<!--\s*msuf-menu-link:') {
return
}
if ([string]::IsNullOrWhiteSpace($trimmed)) {
Close-List
return
}
if ($trimmed -match '^#\s+(.+?)\s*$') {
Close-List
$script:HtmlLines += ("<h1>" + [System.Net.WebUtility]::HtmlEncode($Matches[1].Trim()) + "</h1>")
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
[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
if: steps.publish.outputs.publish_to_github == 'true'
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 }}
# Wago runs only for an explicit stable `publish-target: wago|all|wago+curseforge` tag
# annotation or workflow_dispatch target. Alpha, beta, RC, pre and preview
# builds are rejected before packaging and again inside this upload step.
- name: Upload to Wago
if: steps.publish.outputs.publish_to_wago == 'true'
shell: pwsh
env:
WAGO_API_TOKEN: ${{ secrets.WAGO_API_TOKEN }}
run: |
function Get-TocField {
param(
[Parameter(Mandatory = $true)][string]$Content,
[Parameter(Mandatory = $true)][string]$Name
)
$match = [regex]::Match($Content, "(?m)^##\s+$([regex]::Escape($Name)):\s*(.+?)\s*$")
if ($match.Success) {
return $match.Groups[1].Value.Trim()
}
return $null
}
function Convert-RetailInterfaceToPatch {
param([Parameter(Mandatory = $true)][int]$Interface)
if ($Interface -lt 100000) {
throw "Retail interface value must be six digits. Got: $Interface"
}
$major = [math]::Floor($Interface / 10000)
$minor = [math]::Floor(($Interface % 10000) / 100)
$patch = $Interface % 100
return "$major.$minor.$patch"
}
$zip = Get-ChildItem -Path dist -Filter "*.zip" | Select-Object -First 1
if (-not $zip) {
throw "No release zip found in dist."
}
if ([string]::IsNullOrWhiteSpace($env:WAGO_API_TOKEN)) {
throw "WAGO_API_TOKEN is missing."
}
if ($env:WAGO_STABILITY -notin @("stable", "beta", "alpha")) {
throw "Invalid Wago stability '$env:WAGO_STABILITY'."
}
# Second lock: Wago must always be an explicit publish destination.
if ($env:PUBLISH_TARGET -notin @("all", "wago", "wago+curseforge")) {
throw "Refusing Wago upload for publish target '$env:PUBLISH_TARGET'."
}
$tocContent = Get-Content -LiteralPath "MidnightSimpleUnitFrames/MidnightSimpleUnitFrames.toc" -Raw
$projectId = Get-TocField -Content $tocContent -Name "X-Wago-ID"
if ([string]::IsNullOrWhiteSpace($projectId)) {
throw "No Wago project id found in TOC."
}
$tocVersion = Get-TocField -Content $tocContent -Name "Version"
$versionFileValue = ""
if (Test-Path -LiteralPath "VERSION") {
$versionFileValue = Get-Content -LiteralPath "VERSION" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -First 1
}
$alphaSignals = @($env:RELEASE_VERSION, $env:RELEASE_NAME, $versionFileValue, $tocVersion) | Where-Object {
if ([string]::IsNullOrWhiteSpace($_)) {
$false
} else {
$v = $_.Trim()
(
($v -match '(?i)alpha') -or
($v -match '(?i)\d+(?:\.\d+)*A\d+(?:$|[^A-Za-z0-9])') -or
($v -match '(?i)(^|[^A-Za-z0-9])A\d+(?:$|[^A-Za-z0-9])')
)
}
}
if ($alphaSignals -and $env:WAGO_STABILITY -ne "alpha") {
throw "Alpha signal '$($alphaSignals[0])' must upload to Wago as alpha. Got '$env:WAGO_STABILITY'."
}
$prereleaseSignals = @($env:RELEASE_VERSION, $env:RELEASE_NAME, $versionFileValue, $tocVersion) | Where-Object {
if ([string]::IsNullOrWhiteSpace($_)) {
$false
} else {
$v = $_.Trim()
(
($v -match '(?i)(alpha|beta|rc|pre|preview)') -or
($v -match '(?i)\d+(?:\.\d+)*[AB]\d+(?:$|[^A-Za-z0-9])') -or
($v -match '(?i)(^|[^A-Za-z0-9])[AB]\d+(?:$|[^A-Za-z0-9])')
)
}
}
if ($prereleaseSignals -and $env:WAGO_STABILITY -eq "stable") {
throw "Prerelease signal '$($prereleaseSignals[0])' must not upload to Wago as stable."
}
if ($prereleaseSignals) {
throw "Wago prerelease publishing is disabled. Refusing '$($prereleaseSignals[0])'."
}
$releaseNotesPath = "dist/RELEASE_NOTES.md"
if (-not (Test-Path -LiteralPath $releaseNotesPath)) {
throw "Current release notes are missing: $releaseNotesPath"
}
$interfaceField = Get-TocField -Content $tocContent -Name "Interface"
$interfaces = $interfaceField -split ',' |
ForEach-Object { $_.Trim() } |
Where-Object { $_ -match '^\d+$' } |
ForEach-Object { [int]$_ }
if (-not $interfaces) {
throw "No numeric retail interface found in TOC."
}
$retailPatch = Convert-RetailInterfaceToPatch -Interface (($interfaces | Measure-Object -Maximum).Maximum)
$metadata = [ordered]@{
label = $env:RELEASE_NAME
stability = $env:WAGO_STABILITY
changelog = Get-Content -LiteralPath $releaseNotesPath -Raw
supported_retail_patch = $retailPatch
} | ConvertTo-Json -Depth 5 -Compress
$headers = @{
Authorization = "Bearer $env:WAGO_API_TOKEN"
Accept = "application/json"
}
$form = @{
metadata = $metadata
file = Get-Item -LiteralPath $zip.FullName
}
Invoke-RestMethod -Method Post -Uri "https://addons.wago.io/api/projects/$projectId/version" -Headers $headers -Form $form | Out-Null
Write-Host "Uploaded $($zip.FullName) to Wago project $projectId as $env:RELEASE_NAME / $env:RELEASE_VERSION ($env:WAGO_STABILITY, retail $retailPatch)."
- name: Upload to CurseForge
if: steps.publish.outputs.publish_to_curseforge == 'true'
shell: pwsh
env:
CF_API_KEY: ${{ secrets.CF_API_KEY || secrets.CURSEFORGE }}
run: |
function Get-TocField {
param(
[Parameter(Mandatory = $true)][string]$Content,
[Parameter(Mandatory = $true)][string]$Name
)
$match = [regex]::Match($Content, "(?m)^##\s+$([regex]::Escape($Name)):\s*(.+?)\s*$")
if ($match.Success) {
return $match.Groups[1].Value.Trim()
}
return $null
}
function Convert-RetailInterfaceToPatch {
param([Parameter(Mandatory = $true)][int]$Interface)
if ($Interface -lt 100000) {
throw "Retail interface value must be six digits. Got: $Interface"
}
$major = [math]::Floor($Interface / 10000)
$minor = [math]::Floor(($Interface % 10000) / 100)
$patch = $Interface % 100
return "$major.$minor.$patch"
}
$zip = Get-ChildItem -Path dist -Filter "*.zip" | Select-Object -First 1
if (-not $zip) {
throw "No release zip found in dist."
}
if ([string]::IsNullOrWhiteSpace($env:CF_API_KEY)) {
throw "CF_API_KEY is missing."
}
if ($env:CF_RELEASE_TYPE -notin @("release", "beta", "alpha")) {
throw "Invalid CurseForge release type '$env:CF_RELEASE_TYPE'."
}
$tocContent = Get-Content -LiteralPath "MidnightSimpleUnitFrames/MidnightSimpleUnitFrames.toc" -Raw
$projectId = Get-TocField -Content $tocContent -Name "X-Curse-Project-ID"
if ([string]::IsNullOrWhiteSpace($projectId)) {
throw "No CurseForge project id found in TOC."
}
$interfaceField = Get-TocField -Content $tocContent -Name "Interface"
$interfaces = $interfaceField -split ',' |
ForEach-Object { $_.Trim() } |
Where-Object { $_ -match '^\d+$' } |
ForEach-Object { [int]$_ }
if (-not $interfaces) {
throw "No numeric retail interface found in TOC."
}
$declaredRetailPatches = @($interfaces | ForEach-Object { Convert-RetailInterfaceToPatch -Interface $_ })
$retailPatch = Convert-RetailInterfaceToPatch -Interface (($interfaces | Measure-Object -Maximum).Maximum)
if (-not [string]::IsNullOrWhiteSpace($env:CURSEFORGE_GAME_VERSION)) {
$requestedRetailPatch = $env:CURSEFORGE_GAME_VERSION.Trim()
if ($requestedRetailPatch -notin $declaredRetailPatches) {
throw "CurseForge game version '$requestedRetailPatch' is absent from the declared TOC interfaces [$($declaredRetailPatches -join ', ')]."
}
$retailPatch = $requestedRetailPatch
}
$changelogPath = "dist/RELEASE_NOTES_CF.html"
$changelogType = "html"
if (-not (Test-Path -LiteralPath $changelogPath)) {
$changelogPath = "dist/RELEASE_NOTES.md"
$changelogType = "markdown"
}
$metadata = [ordered]@{
changelog = Get-Content -LiteralPath $changelogPath -Raw
changelogType = $changelogType
displayName = $env:CURSEFORGE_DISPLAY_NAME
gameVersionNames = @($retailPatch)
releaseType = $env:CF_RELEASE_TYPE
} | ConvertTo-Json -Depth 5 -Compress
$headers = @{
"X-Api-Token" = $env:CF_API_KEY
Accept = "application/json"
}
$form = @{
metadata = $metadata
file = Get-Item -LiteralPath $zip.FullName
}
$result = Invoke-RestMethod -Method Post -Uri "https://wow.curseforge.com/api/projects/$projectId/upload-file" -Headers $headers -Form $form
$fileId = if ($result -and $result.id) { $result.id } else { "(unknown file id)" }
Write-Host "Uploaded $($zip.FullName) to CurseForge project $projectId as $env:CURSEFORGE_DISPLAY_NAME / $env:RELEASE_VERSION ($env:CF_RELEASE_TYPE, retail $retailPatch, file $fileId)."