From 12a79b38de25f1ab4ec05cb28f716b3080ee8d68 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 18 Nov 2026 13:49:14 +0000 Subject: [PATCH] Add bilingual private-safe activity heatmap and scoped prune-free CI --- .gitea/workflows/deploy.yml | 21 +++++++++- ops/Dockerfile | 16 ++++++++ ops/deploy-frontend.sh | 17 ++++++++ ops/frontend.compose.yml | 8 ++++ src/__tests__/activity.test.tsx | 13 ++++++ src/app/(routes)/(website)/(home)/page.tsx | 2 + .../components/activity/activity-grid.tsx | 40 +++++++++++++++++++ .../components/activity/activity.tsx | 12 ++++++ src/app/api/revision/route.ts | 4 ++ 9 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 ops/Dockerfile create mode 100644 ops/deploy-frontend.sh create mode 100644 ops/frontend.compose.yml create mode 100644 src/__tests__/activity.test.tsx create mode 100644 src/app/(routes)/(website)/components/activity/activity-grid.tsx create mode 100644 src/app/(routes)/(website)/components/activity/activity.tsx create mode 100644 src/app/api/revision/route.ts diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 539d2d4..e50d5d3 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -24,5 +24,22 @@ jobs: echo "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -p 2234 -H 172.17.0.1 >> ~/.ssh/known_hosts - - name: Deploy - run: ssh -p 2234 devops@172.17.0.1 'bash /opt/services/parsa/frontend/deploy.sh' + - name: Deploy reviewed scoped frontend release + env: + RELEASE_SHA: ${{ gitea.sha }} + run: | + case "$RELEASE_SHA" in ''|*[!0-9a-f]*) exit 1;; esac + test "${#RELEASE_SHA}" = 40 + ssh -p 2234 devops@172.17.0.1 "bash -s -- $RELEASE_SHA" <<'REMOTE' + set -euo pipefail + expected=$1 + cd /opt/services/parsa/frontend/repo + test -z "$(git status --porcelain --untracked-files=normal)" + export GIT_SSH_COMMAND='ssh -i /home/devops/.ssh/deploy_key -o StrictHostKeyChecking=no' + git fetch origin main + test "$(git rev-parse origin/main)" = "$expected" + git merge --ff-only "$expected" + bash -n ops/deploy-frontend.sh + sudo install -m 0755 ops/deploy-frontend.sh /opt/services/parsa/frontend/deploy.sh + bash /opt/services/parsa/frontend/deploy.sh "$expected" + REMOTE diff --git a/ops/Dockerfile b/ops/Dockerfile new file mode 100644 index 0000000..a949169 --- /dev/null +++ b/ops/Dockerfile @@ -0,0 +1,16 @@ +FROM node:22-alpine AS builder +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci --ignore-scripts --registry=https://registry.npmjs.org +COPY . . +ENV NEXT_TELEMETRY_DISABLED=1 +RUN npm run build +FROM node:22-alpine +WORKDIR /app +ENV NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 PORT=3000 HOSTNAME=0.0.0.0 +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +USER node +EXPOSE 3000 +CMD ["node", "server.js"] diff --git a/ops/deploy-frontend.sh b/ops/deploy-frontend.sh new file mode 100644 index 0000000..8083e0e --- /dev/null +++ b/ops/deploy-frontend.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail +expected=${1:?immutable revision required} +[[ "$expected" =~ ^[0-9a-f]{40}$ ]] +cd /opt/services/parsa/frontend/repo +test "$(git rev-parse HEAD)" = "$expected" +test -z "$(git status --porcelain --untracked-files=normal)" +export PARSA_RELEASE_SHA="$expected" +DOCKER_BUILDKIT=0 docker compose -f /opt/services/parsa/frontend/compose.yml -f ops/frontend.compose.yml build frontend +docker compose -f /opt/services/parsa/frontend/compose.yml -f ops/frontend.compose.yml up -d --no-deps --no-build frontend +for i in {1..40}; do + if [ "$(curl --max-time 15 -fsS https://parsaaghayi.ir/api/revision || true)" = "$expected" ]; then + echo "Frontend verified revision: $expected"; exit 0 + fi + sleep 3 +done +exit 1 diff --git a/ops/frontend.compose.yml b/ops/frontend.compose.yml new file mode 100644 index 0000000..8290d33 --- /dev/null +++ b/ops/frontend.compose.yml @@ -0,0 +1,8 @@ +services: + frontend: + build: + dockerfile: /opt/services/parsa/frontend/repo/ops/Dockerfile + environment: + PARSA_RELEASE_SHA: ${PARSA_RELEASE_SHA:?required} + labels: + org.opencontainers.image.revision: ${PARSA_RELEASE_SHA:?required} diff --git a/src/__tests__/activity.test.tsx b/src/__tests__/activity.test.tsx new file mode 100644 index 0000000..72fc8d9 --- /dev/null +++ b/src/__tests__/activity.test.tsx @@ -0,0 +1,13 @@ +import { render, screen, fireEvent } from '@testing-library/react'; +import { describe, it, expect } from 'vitest'; +import ActivityGrid, { ActivityData } from '../app/(routes)/(website)/components/activity/activity-grid'; +const data: ActivityData = { + timezone: 'Asia/Tehran', from: '2025-11-19', to: '2026-11-18', updated_at: '2026-11-18T10:00:00+03:30', + days: Array.from({length:365}, (_, i) => ({ date: new Date(Date.UTC(2025,10,19+i)).toISOString().slice(0,10), count: i === 364 ? 3 : 0 })), + stats: {total:3, active_days:1, daily_average:0.01, longest_streak:1}, months:[{month:'2026-11',count:3}] +}; +describe('Activity aggregate view (isolated fixtures)', () => { + it('shows honest unavailable without invented statistics', () => { render(); expect(screen.getByRole('status')).toHaveTextContent('unavailable'); expect(screen.queryByText('Active days')).not.toBeInTheDocument(); }); + it('renders daily accessible selection and real supplied stats', () => { const {container}=render(); const days=screen.getAllByRole('button'); expect(days).toHaveLength(365); fireEvent.click(days[364]); expect(container.querySelector('[aria-live]')).toHaveTextContent('3 contributions'); expect(screen.getByText('Daily average')).toBeInTheDocument(); }); + it('renders Persian with RTL and translated state', () => {const {container}=render(); expect(container.querySelector('section')).toHaveAttribute('dir','rtl'); expect(screen.getByText('روز فعال')).toBeInTheDocument(); }); +}); diff --git a/src/app/(routes)/(website)/(home)/page.tsx b/src/app/(routes)/(website)/(home)/page.tsx index 8963dbf..c995253 100644 --- a/src/app/(routes)/(website)/(home)/page.tsx +++ b/src/app/(routes)/(website)/(home)/page.tsx @@ -4,6 +4,7 @@ import AboutMe from "../components/aboutMe/aboutMe"; import Services from "../components/services/services"; import MyProjects from "../components/projects/projects"; import Hero from "../components/hero/hero"; +import Activity from "../components/activity/activity"; import { getDictionary } from "@/app/lib/functions/dictionaries"; import { getDefaultLocale } from "@/app/lib/functions/utils"; import { Metadata } from "next"; @@ -64,6 +65,7 @@ export default async function Home() {
+ (null); + const number = new Intl.NumberFormat(fa ? "fa-IR" : "en-US"); + const date = (value: string) => new Intl.DateTimeFormat(fa ? "fa-IR" : "en-GB", { dateStyle: "medium", timeZone: "Asia/Tehran" }).format(new Date(value + "T12:00:00+03:30")); + const valid = data && Array.isArray(data.days) && data.days.length === 365 && data.stats && Array.isArray(data.months); + const dayLabel = (day: { date: string; count: number }) => `${date(day.date)} — ${number.format(day.count)} ${fa ? "مشارکت" : "contributions"}`; + const tones = ["bg-muted", "bg-orange-200 dark:bg-orange-950", "bg-orange-300 dark:bg-orange-800", "bg-orange-500", "bg-orange-700 dark:bg-orange-400"]; + return
+

GITEA / {fa ? "فعالیت مهندسی" : "ENGINEERING ACTIVITY"}

+

{fa ? "یک سال ساختن، روز به روز" : "A year of building, day by day"}

+

{fa ? "مشارکت‌های عمومی و خصوصی؛ فقط تعداد روزانه، بدون نام یا محتوای مخزن. ۳۶۵ روز اخیر بر اساس زمان تهران. مشارکت با تعداد کامیت برابر نیست." : "Public and private contributions, shared only as daily counts. No repository names or content. Last 365 days in Tehran time; contributions are not commit counts."}

+ {!valid ?

{fa ? "اطلاعات فعالیت اکنون در دسترس نیست. لطفاً بعداً صفحه را تازه کنید." : "Activity is unavailable right now. Please refresh later."}

: <> +
{[ + [fa ? "مشارکت" : "Contributions", data.stats.total], + [fa ? "روز فعال" : "Active days", data.stats.active_days], + [fa ? "میانگین روزانه" : "Daily average", data.stats.daily_average], + [fa ? "طولانی‌ترین زنجیره روزانه" : "Longest daily streak", data.stats.longest_streak], + ].map(([label, value]) =>
{label}
{number.format(Number(value))}
)}
+
+
+ {Array.from({ length: new Date(data.from + "T12:00:00Z").getUTCDay() }, (_, i) => )} + {data.days.map(day =>
+
+

{selected ? dayLabel(data.days.find(d => d.date === selected)!) : fa ? "برای جزئیات، یک روز را انتخاب کنید. برای دیدن تمام سال به کناره‌ها پیمایش کنید." : "Select a day for details. Scroll sideways to explore the full year."}

+
{fa ? "کمتر" : "Less"}{tones.map(tone => )}{fa ? "بیشتر" : "More"}
+
{fa ? "مجموع ماهانه (ماه‌های میلادی)" : "Monthly totals (Gregorian months)"}
{data.months.map(month =>
{month.month}
{number.format(month.count)}
)}
+

{date(data.from)} — {date(data.to)} · {fa ? "آخرین دریافت:" : "Fetched:"} {new Intl.DateTimeFormat(fa ? "fa-IR" : "en-GB", { dateStyle: "medium", timeStyle: "short", timeZone: "Asia/Tehran" }).format(new Date(data.updated_at))} · {fa ? "زمان تهران · تازه‌سازی تا ۵ دقیقه" : "Tehran time · refreshes within 5 minutes"}

+ } +
; +} diff --git a/src/app/(routes)/(website)/components/activity/activity.tsx b/src/app/(routes)/(website)/components/activity/activity.tsx new file mode 100644 index 0000000..7d1fd44 --- /dev/null +++ b/src/app/(routes)/(website)/components/activity/activity.tsx @@ -0,0 +1,12 @@ +import ActivityGrid, { ActivityData } from "./activity-grid"; + +export default async function Activity({ locale }: { locale: string }) { + let data: ActivityData | null = null; + try { + const response = await fetch("https://backend.parsaaghayi.ir/api/website/activity", { + cache: "no-store", signal: AbortSignal.timeout(12000), + }); + if (response.ok) data = await response.json(); + } catch { /* Honest unavailable state; no synthetic activity. */ } + return ; +} diff --git a/src/app/api/revision/route.ts b/src/app/api/revision/route.ts new file mode 100644 index 0000000..2ae3952 --- /dev/null +++ b/src/app/api/revision/route.ts @@ -0,0 +1,4 @@ +export const dynamic = "force-dynamic"; +export function GET() { + return new Response(process.env.PARSA_RELEASE_SHA || "development", { headers: { "Content-Type": "text/plain", "Cache-Control": "no-store" } }); +}