Skip to content
Open
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
78 changes: 78 additions & 0 deletions .github/workflows/preview-api-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Preview API Deployment

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
paths:
- 'apps/api/**'
- 'packages/**'
- 'package.json'
- 'pnpm-lock.yaml'
- '!**/*.md'
- '!**/README*'

concurrency:
group: preview-api-${{ github.event.pull_request.number }}-${{ github.sha }}
cancel-in-progress: false

jobs:
deploy:
name: Deploy Preview to Cloudflare Workers
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22

- name: Setup pnpm
uses: pnpm/action-setup@v5
with:
version: 10.14.0

- name: Cache pnpm store
uses: actions/cache@v5
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build and upload version
id: deploy
working-directory: apps/api
run: |
pnpm run build
pnpm dlx wrangler versions upload 2>&1 | tee deploy-output.txt
VERSION_ID=$(grep -oP 'Version ID: \K[a-f0-9-]+' deploy-output.txt)
PREVIEW_URL=$(grep -oP 'https://[a-zA-Z0-9.-]+\.workers\.dev' deploy-output.txt | head -1)
echo "version_id=$VERSION_ID" >> $GITHUB_OUTPUT
echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

- name: Comment on PR
if: steps.deploy.outputs.preview_url != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr comment ${{ github.event.pull_request.number }} --body "### Preview API Deployment

**Commit:** \`${{ github.sha }}\`
**Version ID:** \`${{ steps.deploy.outputs.version_id }}\`
**Preview URL:** ${{ steps.deploy.outputs.preview_url }}
**Deployed at:** $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
70 changes: 70 additions & 0 deletions .github/workflows/production-api-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Production API Deployment

on:
pull_request:
types: [closed]
branches:
- main
paths:
- 'apps/api/**'
- 'packages/**'
- 'package.json'
- 'pnpm-lock.yaml'
- '!**/*.md'
- '!**/README*'

concurrency:
group: production-api
cancel-in-progress: true

jobs:
deploy:
name: Deploy to Cloudflare Workers Production
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
contents: read
deployments: write

steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22

- name: Setup pnpm
uses: pnpm/action-setup@v5
with:
version: 10.14.0

- name: Cache pnpm store
uses: actions/cache@v5
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Deploy to production
working-directory: apps/api
run: pnpm run deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

- name: Create deployment summary
run: |
MERGE_COMMIT_SHA="${{ github.event.pull_request.merge_commit_sha }}"
echo "### Production API Deployment Successful" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${MERGE_COMMIT_SHA}\`" >> $GITHUB_STEP_SUMMARY
echo "**URL:** https://api.ahargunyllib.dev" >> $GITHUB_STEP_SUMMARY
echo "**Deployed at:** $(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
72 changes: 72 additions & 0 deletions .github/workflows/production-infra-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Production Infra Deployment

on:
pull_request:
types: [closed]
branches:
- main
paths:
- 'packages/infra/**'
- '!**/*.md'

concurrency:
group: production-infra
cancel-in-progress: false

jobs:
deploy:
name: Deploy Cloudflare Infrastructure
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22

- name: Setup pnpm
uses: pnpm/action-setup@v5
with:
version: 10.14.0

- name: Cache pnpm store
uses: actions/cache@v5
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Generate DB migrations
run: pnpm --filter @realm/db generate
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_D1_DATABASE_ID: ${{ secrets.CLOUDFLARE_D1_DATABASE_ID }}
CLOUDFLARE_D1_TOKEN: ${{ secrets.CLOUDFLARE_D1_TOKEN }}

- name: Deploy infrastructure
run: pnpm --filter @realm/infra deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ALCHEMY_STAGE: production

- name: Create deployment summary
run: |
MERGE_COMMIT_SHA="${{ github.event.pull_request.merge_commit_sha }}"
echo "### Infrastructure Deployment Successful" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${MERGE_COMMIT_SHA}\`" >> $GITHUB_STEP_SUMMARY
echo "**Resources:** D1 Database, KV Namespace, R2 Bucket, Queue, Worker" >> $GITHUB_STEP_SUMMARY
echo "**Deployed at:** $(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
7 changes: 6 additions & 1 deletion apps/server/package.json → apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "server",
"name": "api",
"type": "module",
"version": "0.0.1",
"scripts": {
Expand All @@ -11,10 +11,15 @@
"cf-typegen": "wrangler types --env-interface CloudflareBindings"
},
"dependencies": {
"@hono/swagger-ui": "^0.5.0",
"@realm/api": "workspace:*",
"@trpc/server": "^11.0.0",
"hono": "^4.7.9"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250620.0",
"@realm/tsconfig": "workspace:*",
"@types/node": "catalog:",
"typescript": "catalog:",
"wrangler": "^4.40.3"
}
Expand Down
34 changes: 34 additions & 0 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { swaggerUI } from "@hono/swagger-ui";
import { Hono } from "hono";
import {
appRouter,
createContext,
generateOpenAPIDocument,
type Env,
} from "@realm/api";

const app = new Hono<{ Bindings: Env }>();

app.get("/", (c) => c.json({ status: "ok" }));

app.all("/trpc/*", (c) =>
fetchRequestHandler({
endpoint: "/trpc",
req: c.req.raw,
router: appRouter,
createContext: () => createContext(c.env),
})
);

app.get("/swagger/spec", (c) => c.json(generateOpenAPIDocument()));
app.get("/swagger", swaggerUI({ url: "/swagger/spec" }));

export default {
fetch: app.fetch,
queue: (batch: MessageBatch, _env: Env) => {
for (const message of batch.messages) {
console.log("consumed from queue:", JSON.stringify(message.body));
}
},
} satisfies ExportedHandler<Env>;
Comment on lines +27 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify Cloudflare Workers types are configured in tsconfig

# Check if `@cloudflare/workers-types` is in dependencies
echo "=== Checking package.json for `@cloudflare/workers-types` ==="
fd -t f 'package.json' apps/api --exec cat {} | jq '.devDependencies["@cloudflare/workers-types"] // .dependencies["@cloudflare/workers-types"] // "NOT FOUND"'

# Check tsconfig for types configuration
echo -e "\n=== Checking tsconfig for types array ==="
fd -t f 'tsconfig.json' apps/api --exec cat {} | jq '.compilerOptions.types // "types not specified"'

Repository: ahargunyllib/realm

Length of output: 202


🏁 Script executed:

# Check the full tsconfig.json configuration
fd -t f 'tsconfig.json' apps/api --exec cat {}

Repository: ahargunyllib/realm

Length of output: 304


🏁 Script executed:

# Verify if the types are actually working without explicit configuration
# by checking if there are any type errors in the file or if the types resolve
fd -t f 'index.ts' apps/api --exec head -50 {}

Repository: ahargunyllib/realm

Length of output: 940


🏁 Script executed:

# Check the base tsconfig that's being extended
fd -t f 'base.json' packages/tsconfig --exec cat {}

Repository: ahargunyllib/realm

Length of output: 646


🏁 Script executed:

# Verify that the types can be resolved by checking if there are any TypeScript compilation issues
# Look for any type resolution in the extended config or if types are imported elsewhere
find apps/api -name '*.ts' -o -name '*.tsx' | xargs grep -l "MessageBatch\|ExportedHandler" | head -5

Repository: ahargunyllib/realm

Length of output: 118


🏁 Script executed:

# Check the worker-configuration.d.ts file to see if types are declared there
cat apps/api/worker-configuration.d.ts

Repository: ahargunyllib/realm

Length of output: 50375


🏁 Script executed:

# Check if `@cloudflare/workers-types` is properly included in the environment
# Look for reference comments or imports that pull in the Cloudflare Workers types
grep -r "reference\|cloudflare\|workers-types" apps/api --include="*.ts" --include="*.d.ts" --include="*.json"

Repository: ahargunyllib/realm

Length of output: 6448


Remove console.log from production code.

The queue handler uses console.log which violates coding guidelines. Replace with structured logging or remove if this is placeholder code.

Proposed fix to remove console.log
 export default {
   fetch: app.fetch,
   queue: (batch: MessageBatch, _env: Env) => {
     for (const message of batch.messages) {
-      console.log("consumed from queue:", JSON.stringify(message.body));
+      // TODO: Implement proper queue message processing
+      message.ack();
     }
   },
 } satisfies ExportedHandler<Env>;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default {
fetch: app.fetch,
queue: (batch: MessageBatch, _env: Env) => {
for (const message of batch.messages) {
console.log("consumed from queue:", JSON.stringify(message.body));
}
},
} satisfies ExportedHandler<Env>;
export default {
fetch: app.fetch,
queue: (batch: MessageBatch, _env: Env) => {
for (const message of batch.messages) {
// TODO: Implement proper queue message processing
message.ack();
}
},
} satisfies ExportedHandler<Env>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/index.ts` around lines 27 - 34, In the queue handler (the
function starting with "queue: (batch: MessageBatch, _env: Env) =>" iterating
over batch.messages), remove the console.log call and replace it with a
structured logging call using your application's logger (e.g., call
_env.logger.info or processLogger.info if available) or delete the loop if it
was placeholder code; ensure you log the relevant fields from message.body (not
raw JSON.stringify output) in a structured object to preserve typing and avoid
sensitive data exposure.

File renamed without changes.
Loading
Loading