Skip to content
Open
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
76 changes: 48 additions & 28 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ concurrency:
jobs:
deploy:
if: ${{ github.event_name != 'merge_group' }}
# Seeding now writes to a local SQLite file and is bulk-imported into the
# fresh Turso preview DB in one operation, so it no longer streams thousands
# of latency-bound round-trips that killed Blacksmith runners mid-seed.
# Moving this job onto a Blacksmith runner is now a trivial follow-up — see
# NWACus/web#1143.
runs-on: ubuntu-latest
environment: Preview
env:
Expand All @@ -22,7 +27,7 @@ jobs:
run: curl -sSfL https://get.tur.so/install.sh | bash
env:
TURSO_INSTALL_SKIP_SIGNUP: 'true'
- name: Create a new database for the preview
- name: Compute the preview database name
id: database
run: |
set -o errexit
Expand All @@ -42,13 +47,53 @@ jobs:
echo "ref=${ref}" >> "${GITHUB_OUTPUT}"

name="payloadcms-preview-${ref}"
echo "name=${name}" >> "${GITHUB_OUTPUT}"
- name: 🏗 Setup repo
uses: actions/checkout@v4
- name: 🏗 Setup pnpm
uses: pnpm/action-setup@v4
- name: 🏗 Setup Node
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: pnpm
- name: 📦 Install dependencies
run: pnpm ii
shell: bash
- name: Seed a local SQLite database
# Seed against a local file instead of streaming thousands of per-row
# writes to remote Turso. This is the same fast path the CI build job
# uses: NODE_ENV is overridden off `production` so the SQLite adapter
# runs in push mode and builds the current schema directly from the
# Payload config (running migrations from zero isn't viable — a data
# migration reads collections whose block tables a later migration
# adds). The resulting schema matches what the deployed preview expects.
run: pnpm seed:standalone
env:
NODE_ENV: development
DATABASE_URI: 'file:./preview-seed.db'
PAYLOAD_SEED_PASSWORD: '${{ secrets.PAYLOAD_SEED_PASSWORD }}'
PAYLOAD_SECRET: '${{ secrets.PAYLOAD_SECRET }}'
- name: Create the preview database from the seeded file
# Bulk-import the seeded local DB into a fresh Turso DB in one operation.
# We use `--from-dump` (plain SQL) rather than `--from-file`: the latter
# requires WAL mode and mis-parses valid WAL databases on sqlite3 >= 3.50
# (tursodatabase/turso-cli#1030), whereas a `.dump` is runner-agnostic.
run: |
set -o errexit
set -o nounset
set -o pipefail

name="${{ steps.database.outputs.name }}"

sqlite3 ./preview-seed.db .dump > ./preview-seed.sql

/home/runner/.turso/turso org switch nwac
if /home/runner/.turso/turso db show "${name}"; then
/home/runner/.turso/turso db destroy "${name}" --yes
fi
/home/runner/.turso/turso db create "${name}" --wait
/home/runner/.turso/turso db create "${name}" --from-dump ./preview-seed.sql --wait
/home/runner/.turso/turso db shell "${name}" .tables
echo "name=${name}" >> "${GITHUB_OUTPUT}"
env:
TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
- name: Record database connection URI and token
Expand All @@ -62,18 +107,6 @@ jobs:
echo "token=$(/home/runner/.turso/turso db tokens create "${{ steps.database.outputs.name }}")" >> "${GITHUB_OUTPUT}"
env:
TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
- name: 🏗 Setup repo
uses: actions/checkout@v4
- name: 🏗 Setup pnpm
uses: pnpm/action-setup@v4
- name: 🏗 Setup Node
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: pnpm
- name: 📦 Install dependencies
run: pnpm ii
shell: bash
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Generate preview domain names
Expand Down Expand Up @@ -101,19 +134,6 @@ jobs:
run: echo -n "${{ steps.domains.outputs.preview_alias }}" | vercel env add NEXT_PUBLIC_ROOT_DOMAIN preview ${{ github.head_ref }} --no-sensitive --force --token=${{ secrets.VERCEL_TOKEN }}
- name: Pull Vercel Environment Variables into .env file
run: vercel env pull --yes --environment=preview --git-branch="${{ github.head_ref }}" --token=${{ secrets.VERCEL_TOKEN }} .env
- name: Run database migrations
run: pnpm migrate
env:
DATABASE_URI: '${{ steps.connection.outputs.uri }}'
DATABASE_AUTH_TOKEN: '${{ steps.connection.outputs.token }}'
PAYLOAD_SECRET: '${{ secrets.PAYLOAD_SECRET }}'
- name: Seed the database
run: pnpm seed:standalone
env:
DATABASE_URI: '${{ steps.connection.outputs.uri }}'
DATABASE_AUTH_TOKEN: '${{ steps.connection.outputs.token }}'
PAYLOAD_SEED_PASSWORD: '${{ secrets.PAYLOAD_SEED_PASSWORD }}'
PAYLOAD_SECRET: '${{ secrets.PAYLOAD_SECRET }}'
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --git-branch="${{ github.head_ref }}" --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
Expand Down
Loading