t3-code-android-nightly/.repos/alchemy-effect/.github/workflows/website.yml
Julius Marminge e3c85ead63
chore(refs): sync Effect and Alchemy references to rc.115 and beta.78 (#12327)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-17 23:21:25 -07:00

238 lines
9.8 KiB
YAML

name: Website
on:
# Manual override — deploys unconditionally on whatever branch it's run
# from. Toggle `prod` to force a production deploy without a release.
workflow_dispatch:
inputs:
prod:
description: "Deploy to production (alchemy.run) instead of the branch stage"
type: boolean
default: false
# Release commits update package manifests, so packages/** keeps production
# deploys automatic without redeploying the site for unrelated main commits.
push:
branches:
- main
paths:
- "submodules/distilled"
- "website/**"
- "packages/**"
- "scripts/generate-api-reference.ts"
- "patches/**"
- "package.json"
- "pnpm-lock.yaml"
- "pnpm-workspace.yaml"
- "tsconfig.json"
- "turbo.json"
- ".github/workflows/website.yml"
pull_request:
# Label changes create and remove previews without needing another push.
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
- closed
paths:
- "submodules/distilled"
- "website/**"
- "packages/**"
- "scripts/generate-api-reference.ts"
- "patches/**"
- "package.json"
- "pnpm-lock.yaml"
- "pnpm-workspace.yaml"
- "tsconfig.json"
- "turbo.json"
- ".github/workflows/website.yml"
concurrency:
group: deploy-website-${{ github.event_name == 'pull_request' &&
format('pr-{0}', github.event.number) || (inputs.prod ||
startsWith(github.event.head_commit.message, 'chore(release):')) &&
'prod' || (github.ref == 'refs/heads/main' && 'main' || github.ref_name)
}}
# Deploy and destroy mutate the same stack and must finish atomically. Each
# run checks the PR's current state before mutation, so queued label events
# converge to the latest desired state even when GitHub reorders them.
cancel-in-progress: false
env:
STAGE: ${{ github.event_name == 'pull_request' && format('pr-{0}',
github.event.number) || (inputs.prod ||
startsWith(github.event.head_commit.message, 'chore(release):')) && 'prod' ||
(github.ref == 'refs/heads/main' && 'main' || github.ref_name) }}
jobs:
deploy:
name: Deploy
# Deploy every push to main. Release commits (`chore(release): x.y.z`)
# and dispatches with `prod` toggled deploy production; other main
# commits deploy to main.alchemy.run. On PRs, require BOTH:
# - the PR is internal (forks can't access bot/Cloudflare secrets
# so `create-github-app-token` would error immediately), AND
# - the PR carries the `deploy-website` label (opt-in — most PRs
# don't need a website preview, so default to skipping).
if: >-
(github.event_name != 'pull_request' ||
(github.event.pull_request.head.repo.full_name == github.repository &&
contains(github.event.pull_request.labels.*.name, 'deploy-website') &&
github.event.action != 'closed' &&
github.event.action != 'unlabeled' &&
(github.event.action != 'labeled' ||
github.event.label.name == 'deploy-website')))
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Checkout distilled
run: git submodule update --init --depth=1 --checkout -- submodules/distilled
# Mint a token for the alchemy-version-bot GitHub App so the PR
# preview comment (created via GitHub.Comment in alchemy.run.ts)
# posts under the bot's identity instead of `github-actions[bot]`.
# Same App as release.yml — its installation scopes already cover
# PR comments.
- name: Generate bot token
id: bot-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
app-id: ${{ secrets.ALCHEMY_VERSION_BOT_ID }}
private-key: ${{ secrets.ALCHEMY_VERSION_BOT_PRIVATE_KEY }}
- name: Restore Astro build cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: website/node_modules/.astro
key: website-astro-full-${{ runner.os }}-${{ github.event.pull_request.number || 'main' }}-${{ github.sha }}-${{ github.workflow }}-${{ github.run_attempt }}
restore-keys: |
website-astro-full-${{ runner.os }}-${{ github.event.pull_request.number || 'main' }}-${{ github.sha }}-
website-astro-full-${{ runner.os }}-${{ github.event.pull_request.number || 'main' }}-
website-astro-full-${{ runner.os }}-main-
- name: Restore Turbo cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ github.repository_id }}-${{ github.sha }}-${{ github.workflow }}-${{ github.run_attempt }}
restore-keys: |
turbo-${{ runner.os }}-${{ github.repository_id }}-${{ github.sha }}-
turbo-${{ runner.os }}-${{ github.repository_id }}-
- name: Setup pnpm, Node.js, Bun and install dependencies
uses: pnpm/setup@703c52620218391530e48b9e8870d5c0082e1b9b # v2.1.0
with:
cache: true
install: true
require-lockfile: true
- name: Check current preview state
if: github.event_name == 'pull_request'
id: preview-state
env:
GH_TOKEN: ${{ github.token }}
run: |
active="$(gh api "repos/$GITHUB_REPOSITORY/pulls/${{ github.event.number }}" \
--jq '[.state == "open", any(.labels[]; .name == "deploy-website")] | all')"
echo "active=$active" >> "$GITHUB_OUTPUT"
# Main/prod use the production account; PR stages use the test account.
- name: Deploy
if: >-
github.event_name != 'pull_request' ||
steps.preview-state.outputs.active == 'true'
working-directory: website
run: bun alchemy deploy --stage "$STAGE" --yes
env:
PULL_REQUEST: ${{ github.event.number }}
CLOUDFLARE_API_TOKEN: ${{ (env.STAGE == 'main' || env.STAGE == 'prod') && secrets.PROD_CLOUDFLARE_API_TOKEN || secrets.TEST_CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ (env.STAGE == 'main' || env.STAGE == 'prod') && secrets.PROD_CLOUDFLARE_ACCOUNT_ID || secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
BUILD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
GITHUB_TOKEN: ${{ steps.bot-token.outputs.token }}
# PR builds upload zero-traffic versions of this Worker. Refresh the
# parent from merged main using the same test account as PR previews.
- name: Deploy preview parent
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
working-directory: website
run: bun alchemy deploy --stage preview-base --yes
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
BUILD_SHA: ${{ github.sha }}
cleanup:
name: Cleanup
runs-on: blacksmith-4vcpu-ubuntu-2404
if: >-
github.event.pull_request.head.repo.full_name == github.repository &&
((github.event.action == 'closed' &&
contains(github.event.pull_request.labels.*.name, 'deploy-website')) ||
(github.event.action == 'unlabeled' &&
github.event.label.name == 'deploy-website'))
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Checkout distilled
run: git submodule update --init --depth=1 --checkout -- submodules/distilled
- name: Generate bot token
id: bot-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
app-id: ${{ secrets.ALCHEMY_VERSION_BOT_ID }}
private-key: ${{ secrets.ALCHEMY_VERSION_BOT_PRIVATE_KEY }}
- name: Setup pnpm, Node.js, Bun
uses: pnpm/setup@703c52620218391530e48b9e8870d5c0082e1b9b # v2.1.0
with:
cache: true
install: false
- name: Install dependencies
# Destroy evaluates the stack and calls providers; it does not build or
# bundle anything. Skip native postinstalls and the root prepare build.
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Check current preview state
id: preview-state
env:
GH_TOKEN: ${{ github.token }}
run: |
active="$(gh api "repos/$GITHUB_REPOSITORY/pulls/${{ github.event.number }}" \
--jq '[.state == "open", any(.labels[]; .name == "deploy-website")] | all')"
echo "active=$active" >> "$GITHUB_OUTPUT"
# Allowlist, not denylist: cleanup must only ever destroy pr-N stages,
# so refuse anything else outright (prod/main/preview-base) even if a
# future STAGE refactor changes what a pull_request event resolves to.
- name: Safety Check
if: steps.preview-state.outputs.active != 'true'
run: |-
case "${{ env.STAGE }}" in
pr-[0-9]*) ;;
*)
echo "ERROR: cleanup only destroys pr-* stages, got '${{ env.STAGE }}'"
exit 1
;;
esac
- name: Destroy Preview Environment
if: steps.preview-state.outputs.active != 'true'
working-directory: website
run: bun alchemy destroy --stage "$STAGE" --yes
env:
PULL_REQUEST: ${{ github.event.number }}
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
GITHUB_TOKEN: ${{ steps.bot-token.outputs.token }}