From b9171f01358fd39cc18c62c186f8b4a55e0b5245 Mon Sep 17 00:00:00 2001 From: Harxhit Date: Sun, 24 May 2026 17:07:11 +0530 Subject: [PATCH 1/3] fix: Fixed linting issues --- apps/backend/src/app.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/backend/src/app.ts b/apps/backend/src/app.ts index 6a937a88..f817eb46 100644 --- a/apps/backend/src/app.ts +++ b/apps/backend/src/app.ts @@ -1,30 +1,31 @@ -import Fastify from 'fastify'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import cookie from '@fastify/cookie'; import cors from '@fastify/cors'; import helmet from '@fastify/helmet'; import jwt from '@fastify/jwt'; -import cookie from '@fastify/cookie'; import multipart from '@fastify/multipart'; -import fastifyStatic from '@fastify/static'; import rateLimit from '@fastify/rate-limit'; -import path from 'path'; -import { fileURLToPath } from 'url'; +import fastifyStatic from '@fastify/static'; +import Fastify, {type FastifyInstance} from 'fastify'; import { prismaPlugin } from './plugins/prisma.js'; import { redisPlugin } from './plugins/redis.js'; +import { analyticsRoutes } from './routes/analytics.js'; import { authRoutes } from './routes/auth.js'; -import { profileRoutes } from './routes/profiles.js'; import { cardRoutes } from './routes/cards.js'; -import { publicRoutes } from './routes/public.js'; -import { followRoutes } from './routes/follow.js'; import { connectRoutes } from './routes/connect.js'; -import { analyticsRoutes } from './routes/analytics.js'; -import { nfcRoutes } from './routes/nfc.js'; import { eventRoutes } from './routes/event.js'; +import { followRoutes } from './routes/follow.js'; +import { nfcRoutes } from './routes/nfc.js'; +import { profileRoutes } from './routes/profiles.js'; +import { publicRoutes } from './routes/public.js'; import { validateEnv } from './utils/validateEnv.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -export async function buildApp() { +export async function buildApp():Promise { // Validate all required secrets before registering any plugin. // If validation fails the process exits here — no partially-initialised // auth state can exist because Fastify is not yet instantiated. @@ -93,7 +94,7 @@ export async function buildApp() { app.decorate('authenticate', async function (request: any, reply: any) { try { await request.jwtVerify(); - } catch (err) { + } catch (_err) { reply.status(401).send({ error: 'Unauthorized' }); } }); From c559916cc95beac093075cab9ea8a86a8c336a0c Mon Sep 17 00:00:00 2001 From: Harxhit Date: Mon, 1 Jun 2026 23:30:48 +0530 Subject: [PATCH 2/3] feat(ci): add selective monorepo CI and PR result comments --- .github/scripts/ciScript.js | 62 +++++++++++++++++ .github/scripts/commentResults.js | 83 ++++++++++++++++++++++ .github/workflows/ci.yml | 111 ++++++++++++++++++++++++++++++ apps/backend/package.json | 3 +- 4 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/ciScript.js create mode 100644 .github/scripts/commentResults.js create mode 100644 .github/workflows/ci.yml diff --git a/.github/scripts/ciScript.js b/.github/scripts/ciScript.js new file mode 100644 index 00000000..3bc26109 --- /dev/null +++ b/.github/scripts/ciScript.js @@ -0,0 +1,62 @@ +module.exports = async ({ github, context, core }) => { + const owner = context.repo.owner; + const repo = context.repo.repo; + const pr = context.payload.pull_request; + const prNumber = pr.number; + const prState = pr.state; + + const backendFiles = []; + const mobileFiles = []; + const webFiles = []; + + try { + if (prState === 'closed') { + console.log(`PR state is: ${prState}`); + return { + backendChanged: false, + mobileChanged: false, + webChanged: false + }; + } + + const changedFiles = await github.paginate( + github.rest.pulls.listFiles, + { + owner, + repo, + pull_number: prNumber + } + ); + + changedFiles.forEach((file) => { + const fileName = file.filename; + + if (fileName.startsWith('apps/backend/')) { + backendFiles.push(fileName); + } else if (fileName.startsWith('apps/mobile/')) { + mobileFiles.push(fileName); + } else if (fileName.startsWith('apps/web/')) { + webFiles.push(fileName); + } + }); + + console.log({ + backendFiles, + mobileFiles, + webFiles + }); + + core.setOutput("backendChanged",backendFiles.length > 0) + core.setOutput("mobileChanged",mobileFiles.length > 0) + core.setOutput("webChanged",webFiles.length > 0) + + } catch (error) { + console.error(error); + + return { + backendChanged: false, + mobileChanged: false, + webChanged: false + }; + } +}; \ No newline at end of file diff --git a/.github/scripts/commentResults.js b/.github/scripts/commentResults.js new file mode 100644 index 00000000..6e6c3f7a --- /dev/null +++ b/.github/scripts/commentResults.js @@ -0,0 +1,83 @@ +module.exports = async ({ github, context, backend, mobile, web }) => { + const owner = context.repo.owner; + const repo = context.repo.repo; + const pr = context.payload.pull_request; + const prNumber = pr.number; + + const statusEmoji = (status) => { + if (status === 'success') return '✅'; + if (status === 'failure') return '❌'; + if (status === 'skipped') return '⏭️'; + return '⚪'; + }; + + const statusLabel = (status) => { + if (status === 'skipped') return `${statusEmoji(status)} Skipped — no changes detected`; + return `${statusEmoji(status)} ${status}`; + }; + + const results = [backend, mobile, web]; + const allSkipped = results.every((s) => s === 'skipped'); + const anyFailure = results.some((s) => s === 'failure'); + const allPassed = results.every((s) => s === 'success' || s === 'skipped'); + + let title; + if (allSkipped) { + title = '⏭️ No changes detected — all checks skipped'; + } else if (anyFailure) { + title = '❌ Some checks failed'; + } else if (allPassed) { + title = '✅ All checks passed'; + } else { + title = '⚪ Checks completed'; + } + + const timestamp = new Date().toUTCString(); + + const body = `## CI Results — ${title} + +| Check | Status | +|---|---| +| 🖥️ Backend | ${statusLabel(backend)} | +| 📱 Mobile | ${statusLabel(mobile)} | +| 🌐 Web | ${statusLabel(web)} | + +> ⏭️ **Skipped** means no files were changed in that area — the check was not needed. + +--- +🕐 Last updated: \`${timestamp}\``; + + const COMMENT_MARKER = '## CI Results —'; + + try { + const comments = await github.paginate(github.rest.issues.listComments, { + owner, + repo, + issue_number: prNumber, + }); + + const existingComment = comments.find( + (c) => c.body && c.body.startsWith(COMMENT_MARKER) + ); + + if (existingComment) { + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: existingComment.id, + body, + }); + console.log(`Updated existing comment: ${existingComment.id}`); + } else { + await github.rest.issues.createComment({ + owner, + repo, + issue_number: prNumber, + body, + }); + console.log('Created new CI results comment'); + } + } catch (error) { + console.error('Failed to post comment:', error); + } +}; \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..27c30e79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,111 @@ +name: CI + +on: + pull_request_target: + types: [opened, synchronize, reopened] + +permissions: + pull-requests: write + +jobs: + detect-changes: + runs-on: ubuntu-latest + + outputs: + backendChanged: ${{ steps.detect.outputs.backendChanged }} + mobileChanged: ${{ steps.detect.outputs.mobileChanged }} + webChanged: ${{ steps.detect.outputs.webChanged }} + + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Detect changed files + id: detect + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const script = require('./.github/scripts/ciScript.js'); + return await script({ github, context, core }); + + backend-ci: + needs: detect-changes + if: needs.detect-changes.outputs.backendChanged == 'true' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + with: + node-version: 22 + + - uses: pnpm/action-setup@v6.0.8 + + - run: pnpm install + - run: cd apps/backend && pnpm lint + - run: cd apps/backend && pnpm test + - run: cd apps/backend && pnpm typecheck + + web-ci: + needs: detect-changes + if: needs.detect-changes.outputs.webChanged == 'true' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + with: + node-version: 22 + + - uses: pnpm/action-setup@v6.0.8 + + - run: pnpm install + - run: cd apps/web && pnpm check + - run: cd apps/web && pnpm build + + mobile-ci: + needs: detect-changes + if: needs.detect-changes.outputs.mobileChanged == 'true' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + with: + node-version: 22 + + - uses: pnpm/action-setup@v6.0.8 + + - run: pnpm install + - run: cd apps/mobile && pnpm lint + - run: cd apps/mobile && pnpm test + + comment-results: + needs: + - backend-ci + - web-ci + - mobile-ci + if: always() + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Comment results + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const script = require('./.github/scripts/commentResults.js'); + await script({ + github, + context, + backend: '${{ needs.backend-ci.result }}', + web: '${{ needs.web-ci.result }}', + mobile: '${{ needs.mobile-ci.result }}' + }); diff --git a/apps/backend/package.json b/apps/backend/package.json index 5406427f..8bc19bf8 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -14,7 +14,8 @@ "db:migrate": "prisma migrate dev", "db:deploy": "prisma migrate deploy", "db:seed": "tsx prisma/seed.ts", - "db:studio": "prisma studio" + "db:studio": "prisma studio", + "typecheck": "tsc --noEmit" }, "dependencies": { "@devcard/shared": "workspace:*", From 4d2d5405baeeb1dae031e2208691d397736b82ba Mon Sep 17 00:00:00 2001 From: Harxhit Date: Tue, 2 Jun 2026 00:37:46 +0530 Subject: [PATCH 3/3] fix(ci): improve selective checks and detailed PR comment reporting --- .github/scripts/ciScript.js | 37 +++++++++--- .github/scripts/commentResults.js | 98 ++++++++++++++++++------------- .github/workflows/ci.yml | 51 +++++++++++----- 3 files changed, 124 insertions(+), 62 deletions(-) diff --git a/.github/scripts/ciScript.js b/.github/scripts/ciScript.js index 3bc26109..810a91fb 100644 --- a/.github/scripts/ciScript.js +++ b/.github/scripts/ciScript.js @@ -40,15 +40,36 @@ module.exports = async ({ github, context, core }) => { } }); - console.log({ - backendFiles, - mobileFiles, - webFiles - }); + console.log({ + backendFiles, + mobileFiles, + webFiles + }); + + core.setOutput( + "backendFiles", + backendFiles + .map(file => file.replace("apps/backend/", "")) + .join(" ") + ) + + core.setOutput( + "mobileFiles", + mobileFiles + .map(file => file.replace("apps/mobile/", "")) + .join(" ") + ) + + core.setOutput( + "webFiles", + webFiles + .map(file => file.replace("apps/web/", "")) + .join(" ") + ) - core.setOutput("backendChanged",backendFiles.length > 0) - core.setOutput("mobileChanged",mobileFiles.length > 0) - core.setOutput("webChanged",webFiles.length > 0) + core.setOutput("backendChanged", backendFiles.length > 0) + core.setOutput("mobileChanged", mobileFiles.length > 0) + core.setOutput("webChanged", webFiles.length > 0) } catch (error) { console.error(error); diff --git a/.github/scripts/commentResults.js b/.github/scripts/commentResults.js index 6e6c3f7a..50cd1395 100644 --- a/.github/scripts/commentResults.js +++ b/.github/scripts/commentResults.js @@ -1,48 +1,65 @@ -module.exports = async ({ github, context, backend, mobile, web }) => { +module.exports = async ({ + github, + context, + backend, + mobile, + web, + backendLint, + backendTest, + backendTypecheck, + mobileLint, + mobileTest, + webCheck, + webBuild +}) => { const owner = context.repo.owner; const repo = context.repo.repo; - const pr = context.payload.pull_request; - const prNumber = pr.number; + const prNumber = context.payload.pull_request.number; - const statusEmoji = (status) => { + const emoji = (status) => { if (status === 'success') return '✅'; if (status === 'failure') return '❌'; if (status === 'skipped') return '⏭️'; return '⚪'; }; - const statusLabel = (status) => { - if (status === 'skipped') return `${statusEmoji(status)} Skipped — no changes detected`; - return `${statusEmoji(status)} ${status}`; + const label = (status) => { + if (!status) return '⚪ unknown'; + return `${emoji(status)} ${status}`; }; - const results = [backend, mobile, web]; - const allSkipped = results.every((s) => s === 'skipped'); - const anyFailure = results.some((s) => s === 'failure'); - const allPassed = results.every((s) => s === 'success' || s === 'skipped'); + const anyFailure = [ + backend, + mobile, + web + ].includes('failure'); - let title; - if (allSkipped) { - title = '⏭️ No changes detected — all checks skipped'; - } else if (anyFailure) { - title = '❌ Some checks failed'; - } else if (allPassed) { - title = '✅ All checks passed'; - } else { - title = '⚪ Checks completed'; - } + const title = anyFailure + ? '❌ Some checks failed' + : '✅ CI completed'; const timestamp = new Date().toUTCString(); const body = `## CI Results — ${title} +### 🖥️ Backend (${label(backend)}) | Check | Status | |---|---| -| 🖥️ Backend | ${statusLabel(backend)} | -| 📱 Mobile | ${statusLabel(mobile)} | -| 🌐 Web | ${statusLabel(web)} | +| Lint | ${label(backendLint)} | +| Test | ${label(backendTest)} | +| Typecheck | ${label(backendTypecheck)} | -> ⏭️ **Skipped** means no files were changed in that area — the check was not needed. +### 📱 Mobile (${label(mobile)}) +| Check | Status | +|---|---| +| Lint | ${label(mobileLint)} | +| Test | ${label(mobileTest)} | + +### 🌐 Web (${label(web)}) +| Check | Status | +|---|---| +| Check | ${label(webCheck)} | +| Build | ${label(webBuild)} | --- 🕐 Last updated: \`${timestamp}\``; @@ -50,34 +67,35 @@ module.exports = async ({ github, context, backend, mobile, web }) => { const COMMENT_MARKER = '## CI Results —'; try { - const comments = await github.paginate(github.rest.issues.listComments, { - owner, - repo, - issue_number: prNumber, - }); + const comments = await github.paginate( + github.rest.issues.listComments, + { + owner, + repo, + issue_number: prNumber + } + ); - const existingComment = comments.find( - (c) => c.body && c.body.startsWith(COMMENT_MARKER) + const existing = comments.find( + c => c.body && c.body.startsWith(COMMENT_MARKER) ); - if (existingComment) { + if (existing) { await github.rest.issues.updateComment({ owner, repo, - comment_id: existingComment.id, - body, + comment_id: existing.id, + body }); - console.log(`Updated existing comment: ${existingComment.id}`); } else { await github.rest.issues.createComment({ owner, repo, issue_number: prNumber, - body, + body }); - console.log('Created new CI results comment'); } - } catch (error) { - console.error('Failed to post comment:', error); + } catch (err) { + console.error(err); } }; \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27c30e79..25f71019 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,14 +15,16 @@ jobs: backendChanged: ${{ steps.detect.outputs.backendChanged }} mobileChanged: ${{ steps.detect.outputs.mobileChanged }} webChanged: ${{ steps.detect.outputs.webChanged }} + backendFiles: ${{ steps.detect.outputs.backendFiles }} + mobileFiles: ${{ steps.detect.outputs.mobileFiles }} + webFiles: ${{ steps.detect.outputs.webFiles }} steps: - - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd - name: Detect changed files id: detect - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | @@ -44,9 +46,18 @@ jobs: - uses: pnpm/action-setup@v6.0.8 - run: pnpm install - - run: cd apps/backend && pnpm lint - - run: cd apps/backend && pnpm test - - run: cd apps/backend && pnpm typecheck + + - name: Backend lint + id: backend_lint + run: cd apps/backend && pnpm eslint ${{ needs.detect-changes.outputs.backendFiles }} + + - name: Backend test + id: backend_test + run: cd apps/backend && pnpm test ${{ needs.detect-changes.outputs.backendFiles }} + + - name: Backend typecheck + id: backend_typecheck + run: cd apps/backend && pnpm typecheck ${{ needs.detect-changes.outputs.backendFiles }} web-ci: needs: detect-changes @@ -63,8 +74,14 @@ jobs: - uses: pnpm/action-setup@v6.0.8 - run: pnpm install - - run: cd apps/web && pnpm check - - run: cd apps/web && pnpm build + + - name: Web check + id: web_check + run: cd apps/web && pnpm check + + - name: Web build + id: web_build + run: cd apps/web && pnpm build mobile-ci: needs: detect-changes @@ -81,8 +98,14 @@ jobs: - uses: pnpm/action-setup@v6.0.8 - run: pnpm install - - run: cd apps/mobile && pnpm lint - - run: cd apps/mobile && pnpm test + + - name: Mobile lint + id: mobile_lint + run: cd apps/mobile && pnpm eslint ${{ needs.detect-changes.outputs.mobileFiles }} + + - name: Mobile test + id: mobile_test + run: cd apps/mobile && pnpm test comment-results: needs: @@ -93,8 +116,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd - name: Comment results uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 @@ -102,10 +124,11 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const script = require('./.github/scripts/commentResults.js'); - await script({ + + await script({ github, context, backend: '${{ needs.backend-ci.result }}', web: '${{ needs.web-ci.result }}', mobile: '${{ needs.mobile-ci.result }}' - }); + }); \ No newline at end of file