Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions .github/scripts/deploy-vercel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# docs/WEB_EXPORT.md.
#
# Inputs (environment):
# EVENT_NAME, GIT_REF, IN_TARGET (blank = preview), ALIAS_PREVIEW, BUILD_COMMIT, VERCEL_TOKEN
# EVENT_NAME, GIT_REF, IN_TARGET (blank = preview), SLOT_NUMBER, BUILD_COMMIT, VERCEL_TOKEN

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
Expand All @@ -15,11 +15,14 @@ $PSNativeCommandUseErrorActionPreference = $true
Copy-Item infra/vercel/vercel.json build/web/vercel.json -Force
npm i -g vercel@latest

# Target is STATED, not inferred from the ref. It used to be "main means --prod",
# which made a dispatch the wrong branch away from silently publishing to
# maze.ryankelly.dev -- an unacceptable footgun now that agents dispatch this
# workflow to get preview URLs (see docs/BUILD_VERIFICATION.md).
$target = if ($env:EVENT_NAME -eq 'push') { 'production' }
# Determine if this deploy targets a preview slot (slot/1..3)
$slot = if ($env:GIT_REF -match '^refs/heads/slot/([0-9]+)$') { $Matches[1] }
elseif (![string]::IsNullOrWhiteSpace($env:SLOT_NUMBER)) { $env:SLOT_NUMBER }
else { $null }

# Target is STATED, not inferred from the ref.
$target = if ($env:EVENT_NAME -eq 'push' -and $env:GIT_REF -eq 'refs/heads/main') { 'production' }
elseif ($slot) { 'slot' }
elseif ([string]::IsNullOrWhiteSpace($env:IN_TARGET)) { 'preview' }
else { $env:IN_TARGET }

Expand All @@ -33,15 +36,11 @@ if ($target -eq 'production') {
$url = (vercel deploy build/web --yes --token=$env:VERCEL_TOKEN) | Select-Object -Last 1
}

# ALIAS_PREVIEW=true pins this deploy to the stable bisect/inspection URL
# preview-maze.ryankelly.dev. Preview-only by design: production already has its own
# alias, and pinning a prod deploy here would silently repurpose the bisect URL.
if ($env:ALIAS_PREVIEW -eq 'true') {
if ($target -ne 'preview') {
throw "alias_preview=true is only valid with deploy_target=preview (got $target)."
}
vercel alias set $url preview-maze.ryankelly.dev --token=$env:VERCEL_TOKEN
Write-Host "DEPLOY_ALIAS=https://preview-maze.ryankelly.dev"
# Alias preview slot if slot is specified (e.g. p1.maze.ryankelly.dev)
if ($slot) {
$aliasDomain = "p$slot.maze.ryankelly.dev"
vercel alias set $url $aliasDomain --token=$env:VERCEL_TOKEN
Write-Host "DEPLOY_ALIAS=https://$aliasDomain"
}

"url=$url" >> $env:GITHUB_OUTPUT
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/web-export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name: Web Export & Deploy

on:
push:
branches: [main]
branches: [main, "slot/*"]
paths:
- "scripts/**"
- "scenes/**"
Expand All @@ -47,6 +47,12 @@ on:
default: "preview"
type: choice
options: ["preview", "production"]
slot:
description: "Preview slot (1..3) to alias this deployment (e.g. 1 -> p1.maze.ryankelly.dev)"
required: false
default: ""
type: choice
options: ["", "1", "2", "3"]
godot_fork_tag:
description: "Override patched-editor release tag (blank = .github/web-toolchain.env)"
required: false
Expand All @@ -55,11 +61,6 @@ on:
description: "Override export-template folder name (blank = .github/web-toolchain.env)"
required: false
default: ""
alias_preview:
description: "Alias this deploy to preview-maze.ryankelly.dev (for bisecting old commits without touching prod)"
type: boolean
required: false
default: false
issue_comment:
types: [created]

Expand Down Expand Up @@ -111,7 +112,7 @@ jobs:
EVENT_NAME: ${{ github.event_name }}
GIT_REF: ${{ github.ref }}
IN_TARGET: ${{ github.event.inputs.deploy_target }}
ALIAS_PREVIEW: ${{ github.event.inputs.alias_preview }}
SLOT_NUMBER: ${{ github.event.inputs.slot }}
BUILD_COMMIT: ${{ steps.export.outputs.build_commit }}
run: '& "$env:GITHUB_WORKSPACE/.github/scripts/deploy-vercel.ps1"'

Expand Down Expand Up @@ -261,7 +262,7 @@ jobs:
# ALIAS_PREVIEW likewise: a /preview gets its own throwaway URL and must not
# commandeer the stable preview-maze.ryankelly.dev bisect alias.
IN_TARGET: "preview"
ALIAS_PREVIEW: "false"
SLOT_NUMBER: ""
EVENT_NAME: ${{ github.event_name }}
GIT_REF: ${{ github.ref }}
BUILD_COMMIT: ${{ steps.export.outputs.build_commit }}
Expand Down
Loading