publish-event-config.ps1 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. param(
  2. [Parameter(Position = 0)]
  3. [string]$Target = "all",
  4. [switch]$DryRun
  5. )
  6. $ErrorActionPreference = "Stop"
  7. $projectRoot = $PSScriptRoot
  8. $uploadScript = Join-Path $projectRoot "oss-html.ps1"
  9. if (-not (Test-Path $uploadScript)) {
  10. throw ("Upload script not found: {0}" -f $uploadScript)
  11. }
  12. $publishTargets = @{
  13. "classic-sequential" = @{
  14. LocalPath = "event/classic-sequential.json"
  15. RemotePath = "gotomars/event/classic-sequential.json"
  16. PublicUrl = "https://oss-mbh5.colormaprun.com/gotomars/event/classic-sequential.json"
  17. }
  18. "score-o" = @{
  19. LocalPath = "event/score-o.json"
  20. RemotePath = "gotomars/event/score-o.json"
  21. PublicUrl = "https://oss-mbh5.colormaprun.com/gotomars/event/score-o.json"
  22. }
  23. }
  24. function Assert-JsonConfig {
  25. param(
  26. [string]$ConfigPath,
  27. [string]$ConfigName
  28. )
  29. if (-not (Test-Path $ConfigPath)) {
  30. throw ("Config file not found: {0}" -f $ConfigPath)
  31. }
  32. $raw = Get-Content -LiteralPath $ConfigPath -Raw -Encoding UTF8
  33. try {
  34. $parsed = $raw | ConvertFrom-Json
  35. } catch {
  36. throw ("JSON parse failed: {0}`n{1}" -f $ConfigPath, $_.Exception.Message)
  37. }
  38. if (-not $parsed.schemaVersion) {
  39. throw ("Missing schemaVersion: {0}" -f $ConfigPath)
  40. }
  41. if (-not $parsed.game) {
  42. throw ("Missing game block: {0}" -f $ConfigPath)
  43. }
  44. if (-not $parsed.game.mode) {
  45. throw ("Missing game.mode: {0}" -f $ConfigPath)
  46. }
  47. Write-Host ("[OK] {0} schemaVersion={1} game.mode={2}" -f $ConfigName, $parsed.schemaVersion, $parsed.game.mode)
  48. }
  49. function Publish-ConfigTarget {
  50. param(
  51. [string]$ConfigName,
  52. [hashtable]$Config
  53. )
  54. $localPath = Join-Path $projectRoot $Config.LocalPath
  55. $remotePath = $Config.RemotePath
  56. $publicUrl = $Config.PublicUrl
  57. Assert-JsonConfig -ConfigPath $localPath -ConfigName $ConfigName
  58. if ($DryRun) {
  59. Write-Host ("[DRY-RUN] Skip upload: {0} -> {1}" -f $localPath, $remotePath)
  60. Write-Host ("[DRY-RUN] Public URL: {0}" -f $publicUrl)
  61. return
  62. }
  63. Write-Host ("[UPLOAD] {0} -> {1}" -f $localPath, $remotePath)
  64. & $uploadScript cp-up $localPath $remotePath
  65. if ($LASTEXITCODE -ne 0) {
  66. throw ("Upload failed: {0}" -f $ConfigName)
  67. }
  68. Write-Host ("[DONE] {0} published" -f $ConfigName)
  69. Write-Host ("[URL] {0}" -f $publicUrl)
  70. }
  71. $selectedTargets = if ($Target -eq "all") {
  72. $publishTargets.Keys | Sort-Object
  73. } else {
  74. @($Target)
  75. }
  76. foreach ($selectedTarget in $selectedTargets) {
  77. if (-not $publishTargets.ContainsKey($selectedTarget)) {
  78. $supported = ($publishTargets.Keys + "all" | Sort-Object) -join ", "
  79. throw ("Unsupported publish target: {0}. Allowed: {1}" -f $selectedTarget, $supported)
  80. }
  81. Publish-ConfigTarget -ConfigName $selectedTarget -Config $publishTargets[$selectedTarget]
  82. }