From b9171f01358fd39cc18c62c186f8b4a55e0b5245 Mon Sep 17 00:00:00 2001 From: Harxhit Date: Sun, 24 May 2026 17:07:11 +0530 Subject: [PATCH 1/2] 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 6c0a36667210c605dfa886ed7d510c3d7ff0f799 Mon Sep 17 00:00:00 2001 From: Harxhit Date: Tue, 2 Jun 2026 00:49:40 +0530 Subject: [PATCH 2/2] 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