Skip to content
Closed
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
57 changes: 54 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,59 @@ jobs:
- name: Run unit tests
run: pnpm test:unit run

# One production build for Node, which every e2e job serves.
build:
timeout-minutes: 15
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: pnpm/action-setup@v4
- name: Get pnpm store directory
shell: bash
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
# The build inlines the database URL and token into dist/, which is a
# public artifact, so it gets a local database seeded from db/data, never
# the production one. The e2e jobs need it at this same path.
- name: Seed a local database
run: |
pnpm exec drizzle-kit push
pnpm db:seed
env:
ASTRO_DB_REMOTE_URL: file:${{ github.workspace }}/ci.db
- name: Build the site
run: pnpm exec astro build
env:
E2E_PRODUCTION: 1
ASTRO_DB_REMOTE_URL: file:${{ github.workspace }}/ci.db
- name: Check the build holds no credentials
run: |
if grep -rElI 'libsql://|eyJ[A-Za-z0-9_-]{10,}\.' dist/; then
echo "::error::dist/ contains a database URL or a JWT"
exit 1
fi
- uses: actions/upload-artifact@v4
with:
name: dist
path: |
dist/
ci.db
retention-days: 1

e2e:
name: e2e (${{ matrix.project }})
needs: build
timeout-minutes: 30
runs-on: ubuntu-24.04
strategy:
Expand Down Expand Up @@ -97,11 +148,11 @@ jobs:
- name: Install Playwright system dependencies
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: pnpm exec playwright install-deps ${{ matrix.project }}
- uses: actions/download-artifact@v4
with:
name: dist
- name: Run Playwright tests
run: pnpm exec playwright test --project=${{ matrix.project }}
env:
ASTRO_DB_REMOTE_URL: ${{ secrets.ASTRO_DB_REMOTE_URL }}
ASTRO_DB_APP_TOKEN: ${{ secrets.ASTRO_DB_APP_TOKEN }}
- uses: actions/upload-artifact@v4
if: always()
with:
Expand Down
8 changes: 8 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Whatnot podcast).
- **E2E tests only:** `pnpm test:e2e` (Playwright, auto-starts dev server)
- **E2E on another port:** `E2E_PORT=4340 pnpm test:e2e` (default 4321, where
outside CI Playwright reuses whatever server is running; use a free port in a worktree)
- **E2E against the production build:** `E2E_PRODUCTION=1 pnpm exec astro build`,
then `E2E_PRODUCTION=1 pnpm test:e2e`. CI always does this. `E2E_PRODUCTION`
swaps in `@astrojs/node` (Vercel's adapter has no preview server), and
Playwright serves `dist/` with `node dist/server/entry.mjs`. The build keeps
Vercel's image service, so pages carry the same `/_vercel/image` URLs, but
nothing resizes them and those images 404. CI builds against a local SQLite
database seeded from `db/data`, never the production one, because the build inlines
the database URL and token into `dist/`, which CI uploads as a public artifact
- **Seed remote DB:** `pnpm db:seed`
- **Push schema to DB:** `pnpm db:push`
- **Drizzle Studio:** `pnpm db:studio`
Expand Down
48 changes: 30 additions & 18 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import process from 'node:process';

import node from '@astrojs/node';
import vercel from '@astrojs/vercel';
import { defineConfig } from 'astro/config';
import starpod from 'starpod';

import starpodConfig from './starpod.config';

const imagesConfig = {
formats: ['image/avif'],
minimumCacheTTL: 3600,
remotePatterns: [{ protocol: 'https' }, { protocol: 'http' }],
sizes: [160, 320, 640, 1280]
};

// CI's e2e suite builds for Node, which `astro preview` serves.
const e2e = !!process.env.E2E_PRODUCTION;

// https://astro.build/config
export default defineConfig({
output: 'static',
adapter: vercel({
imageService: true,
imagesConfig: {
formats: ['image/avif'],
minimumCacheTTL: 3600,
remotePatterns: [
{
protocol: 'https'
adapter: e2e
? node({ mode: 'standalone' })
: vercel({
imageService: true,
imagesConfig,
webAnalytics: { enabled: true }
}),
/* Vercel's image service writes the same /_vercel/image URLs, so the e2e
build resizes no images, which takes minutes with sharp. */
image: e2e
? {
service: {
entrypoint: '@astrojs/vercel/build-image-service',
config: imagesConfig
},
{
protocol: 'http'
}
],
sizes: [160, 320, 640, 1280]
},
webAnalytics: {
enabled: true
}
}),
breakpoints: imagesConfig.sizes
}
: undefined,
site: 'https://whiskey.fm',
integrations: [starpod(starpodConfig, { database: true })],
// These were specific redirects we needed for our podcast, if you do not have any routes to redirect, you can safely remove this.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"devDependencies": {
"@astrojs/check": "^0.9.9",
"@astrojs/node": "^10.1.4",
"@eslint/js": "^9.39.4",
"@playwright/test": "^1.60.0",
"@testing-library/jest-dom": "^6.9.1",
Expand Down
11 changes: 8 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { defineConfig, devices } from '@playwright/test';

const port = process.env.E2E_PORT || '4321';
const baseURL = `http://localhost:${port}`;
/* CI tests a production build for Node, which a build job leaves in dist/.
Locally the dev server is quicker to iterate against; E2E_PRODUCTION=1
serves an existing build instead. */
const production = !!(process.env.CI || process.env.E2E_PRODUCTION);

/**
* Read environment variables from file.
Expand All @@ -21,7 +25,7 @@ export default defineConfig({
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* CI runs one browser per job; two workers fit its four cores beside the
dev server. */
server. */
workers: process.env.CI ? 2 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
Expand Down Expand Up @@ -72,9 +76,10 @@ export default defineConfig({
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: `pnpm exec astro dev --port ${port}`,
command: production
? `PORT=${port} node dist/server/entry.mjs`
: `pnpm exec astro dev --port ${port}`,
url: baseURL,
reuseExistingServer: !process.env.CI,
timeout: 180 * 1000
Expand Down
Loading
Loading