Skip to content

Commit

Permalink
chore: Run tests against local build in CI (#273)
Browse files Browse the repository at this point in the history
Remove Vercel preview dependency for CI tests.
  • Loading branch information
rmarescu authored Jan 15, 2025
1 parent b8151ff commit 4daaa26
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 25 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/shortest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ jobs:
timeout-minutes: 10

env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
CLERK_PUBLISHABLE_KEY: ${{ secrets.CLERK_PUBLISHABLE_KEY }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }}
MAILOSAUR_API_KEY: ${{ secrets.MAILOSAUR_API_KEY }}
MAILOSAUR_SERVER_ID: ${{ secrets.MAILOSAUR_SERVER_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

steps:
- uses: actions/checkout@v4

# Setup pnpm first
- uses: pnpm/action-setup@v2
with:
version: 8

# Then setup Node with pnpm caching
- uses: actions/setup-node@v4
with:
node-version: 20
Expand All @@ -34,20 +30,29 @@ jobs:
- name: Install dependencies
run: pnpm install --no-frozen-lockfile

- name: Pull and set up .env.local
run: |
pnpm dlx vercel pull --environment=preview --token=$VERCEL_TOKEN
cp .vercel/.env.preview.local .env.local
test -f .env.local || (echo ".env.local not created" && exit 1)
- name: Setup database
run: |
pnpm drizzle-kit generate
pnpm db:migrate
pnpm db:seed
- name: Install Playwright
run: pnpm exec playwright install chromium

- name: Wait for Vercel preview deployment
uses: patrickedqvist/wait-for-vercel-preview@v1.3.2
id: waitFor
with:
token: ${{ secrets.GITHUB_TOKEN }}
max_timeout: 300
- name: Build app
run: pnpm build

- name: Start app in background
run: pnpm start -p 3000 & sleep 10

- name: Run Shortest tests
env:
SHORTEST_TEST_BASE_URL: ${{ steps.waitFor.outputs.url }}
run: pnpm shortest --headless --target=${{ steps.waitFor.outputs.url }}
run: pnpm shortest --headless

- name: Upload artifacts
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion lib/db/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dotenv from "dotenv";
import { sql } from "drizzle-orm";
import { db, client } from "@/lib/db/drizzle";

dotenv.config();
dotenv.config({ path: ".env.local" });

async function cleanup() {
try {
Expand Down
3 changes: 2 additions & 1 deletion lib/db/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "@/lib/db/schema";

dotenv.config();
// Load .env and .env.local
dotenv.config({ path: ".env.local" });

if (!process.env.POSTGRES_URL) {
throw new Error("POSTGRES_URL environment variable is not set");
Expand Down
2 changes: 1 addition & 1 deletion lib/db/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { migrate } from "drizzle-orm/postgres-js/migrator";

import { client, db } from "@/lib/db/drizzle";

dotenv.config();
dotenv.config({ path: ".env.local" });

async function main() {
await migrate(db, {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
"db:cleanup": "tsx lib/db/cleanup.ts",
"stripe:webhooks": "stripe listen --forward-to http://localhost:3000/api/stripe/webhook",
"setup": "npx tsx lib/setup.ts",

"pkg:build": "cd packages/shortest && pnpm build",
"pkg:dev": "cd packages/shortest && pnpm dev",
"pkg:test": "cd packages/shortest && pnpm shortest",
"pkg:test:src": "npx tsx packages/shortest/src/cli/bin.ts",

"test": "pnpm shortest",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand Down Expand Up @@ -92,6 +90,7 @@
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "^8.18.2",
"@vitejs/plugin-react": "^4.3.1",
"dotenv": "^8.0.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.31.0",
Expand Down
1 change: 0 additions & 1 deletion packages/shortest/src/browser/integrations/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class GitHubTool {

constructor(secret?: string) {
dotenv.config({ path: ".env.local" });
dotenv.config({ path: ".env" });

this.totpSecret = secret || process.env.GITHUB_TOTP_SECRET || "";

Expand Down
2 changes: 0 additions & 2 deletions packages/shortest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ if (!global.__shortest__) {
// Attach to global scope
global.expect = global.__shortest__.expect;

dotenv.config({ path: join(process.cwd(), ".env") });
dotenv.config({ path: join(process.cwd(), ".env.local") });
}

Expand All @@ -65,7 +64,6 @@ function validateConfig(config: Partial<ShortestConfig>) {
export async function initialize() {
if (globalConfig) return globalConfig;

dotenv.config({ path: join(process.cwd(), ".env") });
dotenv.config({ path: join(process.cwd(), ".env.local") });

const configFiles = [
Expand Down
Loading

0 comments on commit 4daaa26

Please sign in to comment.