diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..4cc199b --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,293 @@ +name: CI + +# PRs always run: `build` is the required status check of main's branch protection, so +# a paths-ignore here would leave docs-only PRs waiting forever for a check that never +# starts. Pushes to main may still skip docs-only changes — they deploy nothing either. +# NOTE: use `*.md` (root-level) — NOT `**/*.md` — because blog/story content lives at +# src/content/**/*.{md,mdx}. +# +# A push to main (and a dispatch on main) also deploys: the `deploy` job below. +on: + pull_request: + # Dispatched on content/bump by content-bump.yml (PRs opened with GITHUB_TOKEN don't + # trigger pull_request workflows), so the required `build` check exists for them. + workflow_dispatch: + push: + branches: [main] + paths-ignore: ["poli0981.dev-docs/**", "*.md", "LICENSE"] + +# Explicit, and granted per job: a grant made up here would reach every job, one added +# later included. +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + # Cancel superseded PR runs; let main runs finish. + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + build: + runs-on: ubuntu-latest + # A hung `wrangler dev` in the smoke test must not hold a runner for six hours. + timeout-minutes: 30 + # Job-level too, so a second job added later can't silently inherit something wider. + permissions: + contents: read + steps: + # Actions are pinned to commit SHAs, not tags: a tag is mutable, so `@v7` would + # execute whatever that tag points at on the day CI runs. Dependabot's + # github-actions ecosystem updates the pins and keeps the version comment in sync. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 # check-exif diffs changed images against the base ref + # src/content is a submodule (poli0981/content). Without this the content + # collections resolve to an empty directory and the build fails on the + # first getCollection() call. + submodules: recursive + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + cache: npm + + # No dependency lifecycle script runs in CI at all (docs 06 §6, anti-worm). None is + # needed: esbuild, workerd and sharp take their platform binaries from + # optionalDependencies — their install scripts only re-verify them — and lefthook's + # only installs git hooks. Local installs stay guarded by package.json#allowScripts + # plus .npmrc strict-allow-scripts. + - name: Install + run: npm ci --ignore-scripts + + # …which also means npm's own strict-allow-scripts check never runs here. This keeps + # the alarm: any lockfile package with an install script must be on allowScripts. + - name: Install scripts allow-listed + run: npm run check-install-scripts + + # Binding types live in the gitignored worker-configuration.d.ts files, generated from + # the wrangler configs; both type checks fail without them. No auth needed. + # --strict-vars=false (in the script): `vars` are typed as string, not their literal + # value, so code comparing e.g. GATE_MODE against "on" typechecks whatever it is set to. + - name: Generate Cloudflare binding types + run: | + npm run types + npm run types:widgets + + - name: Format check + run: npm run format:check + + - name: Lint + run: npm run lint + + # .astro, .svelte and .ts through Volar — the TypeScript 6 API (TS 7.0 has none). + - name: Type check (astro check) + run: npm run check + + # Every .ts file again with the native TypeScript 7 compiler, plus the widgets worker + # (a separate TS project). The version line makes a bin mix-up impossible to miss. + - name: Type check (TypeScript 7) + run: | + node node_modules/@typescript/native/bin/tsc --version + npm run typecheck + + - name: Dead code + run: npm run knip + + # node:test + V8 coverage. Fails under 80% lines. + - name: Unit tests (coverage) + run: npm run test:coverage + + - name: Audit (prod deps, high+) + run: npm audit --omit=dev --audit-level=high + + # THIRD-PARTY-NOTICES.md must match the direct dependencies, and every license must be + # either on the allowlist or explicitly reviewed (docs 08 §6). + - name: Third-party notices + run: npm run gen-notices -- --check + + # The same policy over every package in package-lock.json, transitive dependencies and + # each platform's binaries included; anything outside it needs a per-package review. + - name: Licences (whole dependency tree) + run: npm run check-licenses + + # Fail if any changed image under src/assets/ still carries GPS or a camera serial. + - name: Check EXIF (changed images) + env: + DIFF_BASE: ${{ github.event.pull_request.base.sha || github.event.before }} + run: npm run check-exif -- --changed + + - name: Build + run: npm run build + + # src/worker.ts fronts every page, so a crash there would take the static site down + # too. Boot the built worker locally (wrangler dev, simulated bindings, no auth) and + # probe pages, revalidation, HEAD, redirects, 404s, assets, the gate and the API. + - name: Smoke test built worker + run: npm run smoke + + # Accessibility gate (ACCESSIBILITY.md). The same build is served by `astro preview` + # (workerd, real bindings, no bot gate without its secrets) and driven by Chrome. + # axe-core scans every page in the sitemap and the dialogs while open; the keyboard, + # reflow and forced-colours checks follow. Runs inside this job because `build` is + # the required status check. + # + # GitHub's ubuntu image shipped Google Chrome; the Gitea runner's image + # (docker.gitea.com/runner-images) has none, so the job takes Playwright's own + # Chromium at the version the lockfile pins (A11Y_CHANNEL=bundled, tests/a11y/ + # support.ts), cached per Playwright version. An image that has Chrome keeps using it. + # The job container runs as root; Playwright starts Chromium without its sandbox by + # default (chromiumSandbox: false), which is what a root user needs. + - name: Which Chrome + id: chrome + run: | + if [ -x /usr/bin/google-chrome ]; then + echo "system=true" >> "$GITHUB_OUTPUT" + else + echo "system=false" >> "$GITHUB_OUTPUT" + echo "playwright=$(node -p "require('playwright/package.json').version")" >> "$GITHUB_OUTPUT" + fi + + - name: Cache Playwright's Chromium + id: pw-cache + if: steps.chrome.outputs.system != 'true' + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.cache/ms-playwright + key: playwright-chromium-${{ runner.os }}-${{ steps.chrome.outputs.playwright }} + + # A cache hit restores the browser, not the system libraries it links. + - name: Playwright's Chromium + if: steps.chrome.outputs.system != 'true' + env: + CACHE_HIT: ${{ steps.pw-cache.outputs.cache-hit }} + run: | + if [ "$CACHE_HIT" = "true" ]; then + npx playwright install-deps chromium + else + npx playwright install --with-deps chromium + fi + echo "A11Y_CHANNEL=bundled" >> "$GITHUB_ENV" + + # One step, server and tests together: the Gitea runner (act) ends what a step started + # in the background when that step ends. And on 127.0.0.1 explicitly: in the runner's + # container `localhost` made the preview listen on ::1 only, while Node's fetch in the + # tests went to 127.0.0.1 (PR #1's first runs: ECONNREFUSED on 4321). + - name: Accessibility tests (axe + keyboard) + env: + A11Y_BASE_URL: http://127.0.0.1:4321 + run: | + npm run preview -- --host 127.0.0.1 > "$RUNNER_TEMP/preview.log" 2>&1 & + preview=$! + up=false + for i in $(seq 1 60); do + if curl -sf -o /dev/null http://127.0.0.1:4321/; then + echo "preview up after ${i}s"; up=true; break + fi + sleep 1 + done + if [ "$up" != true ]; then + echo "preview server never came up"; cat "$RUNNER_TEMP/preview.log"; exit 1 + fi + status=0 + npm run test:a11y || status=$? + if [ "$status" -ne 0 ]; then + echo "--- preview server log (last 100 lines) ---" + tail -n 100 "$RUNNER_TEMP/preview.log" || true + fi + kill "$preview" 2>/dev/null || true + exit "$status" + + # Content publish, second half (content-bump.yml is the first): when the admin's publish + # dispatched this run on content/bump and `build` passed, merge the content/bump PR + # (Markdown/JSON only — an MDX publish waits for a review) and dispatch this workflow on + # main, which deploys. The dispatch is needed because nothing the job token does starts a + # workflow, its merge commit included. If the merge is refused, the job fails and says so + # on the PR; a merge by hand deploys as usual. + publish: + needs: build + if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/content/bump' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write # the merge + pull-requests: write # the merge, a comment when it fails + actions: write # dispatch ci.yml on main + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Merge the publish PR and deploy main + env: + TOKEN: ${{ github.token }} + API: ${{ github.api_url }} + REPO: ${{ github.repository }} + SHA: ${{ github.sha }} + run: node scripts/content-publish.mjs merge + + # Production. Cloudflare Workers Builds pulled from GitHub and stopped with it, so main + # deploys from here (migration decision D3): after `build` passed on the same commit, + # rebuild with the production settings and `wrangler deploy` at 100%. Nothing else + # deploys: PRs and other branches get no preview versions, which would put the Cloudflare + # token within reach of a PR's code (Gitea gives same-repo PRs the secrets, Renovate's + # included). + # + # The workflow's concurrency group keeps main runs in order and never cancels one, so two + # quick merges deploy one after the other, the newer last. The runner lives on the + # maintainer's PC: a merge made while it is off deploys when it comes back. + deploy: + needs: build + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + submodules: recursive # the content, and HEAD:src/content for /api/health + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + cache: npm + + - name: Install + run: npm ci --ignore-scripts + + # What Workers Builds' build variables did: the Turnstile site key (public — every + # gated page carries it) is inlined into the client, and the Cloudflare Web Analytics + # beacon is switched on for production builds only (astro.config.mjs). GITHUB_SHA, + # which Gitea sets too, becomes the commit /api/health reports. + - name: Build (production) + env: + PUBLIC_TURNSTILE_SITE_KEY: "0x4AAAAAAD5Cup6ayN5o78wu" + PUBLIC_CF_BEACON: "true" + run: npm run build + + # Token scope (docs 07): Account → Workers Scripts: Edit, plus what the bindings + # need to resolve (KV, R2, routes and custom domains on the zone). User-level + # Actions secrets on Gitea, shared by the web repos. Plain `wrangler` finds the + # generated config on its own: the build writes .wrangler/deploy/config.json + # pointing at dist/server/wrangler.json. + - name: Deploy to Cloudflare Workers + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + WRANGLER_SEND_METRICS: "false" + run: npx wrangler deploy --message "main ${GITHUB_SHA:0:7}" + + # The deploy is live when the site says so: /api/health reports the commit of the + # build it runs (src/lib/version.ts). + - name: Live + run: | + for i in $(seq 1 30); do + live=$(curl -fsS https://poli0981.dev/api/health | node -e ' + let s = ""; process.stdin.on("data", (d) => (s += d)); + process.stdin.on("end", () => { try { console.log(JSON.parse(s).version.commit ?? ""); } catch { console.log(""); } }); + ' || true) + if [ "$live" = "$GITHUB_SHA" ]; then echo "live: $live"; exit 0; fi + sleep 4 + done + echo "::error::/api/health still reports ${live:-nothing}, not $GITHUB_SHA" + exit 1 diff --git a/.gitea/workflows/content-bump.yml b/.gitea/workflows/content-bump.yml new file mode 100644 index 0000000..e54e9a0 --- /dev/null +++ b/.gitea/workflows/content-bump.yml @@ -0,0 +1,87 @@ +name: Content publish + +# "Publish" in the admin (admin.poli0981.dev) dispatches this, and so does every admin save. +# It points the src/content submodule at poli0981/content's main, commits that on the +# content/bump branch, opens (or updates) a PR, and starts CI on the bump commit. When only +# Markdown/JSON changed, CI's `publish` job merges the PR once `build` passed there and +# starts the deploy of main (ci.yml). +# +# Why a workflow: the admin's token never pushes code to this repository; the most it can +# do here is start this workflow. MDX runs code at build time, so a publish that touches +# anything other than .md/.json waits for a human review instead of merging itself. +# +# Gitea, not GitHub (migration decision D5): `gh` is gone, the PR and the CI dispatch are +# plain calls to Gitea's API with the job token. A PR opened with the job token starts no +# workflow, so CI is dispatched on content/bump. Whether the PR merges by itself is in its +# body (`` or ``), where the admin reads it: +# Gitea's API has no auto-merge field. +on: + workflow_dispatch: + +permissions: {} + +# One run at a time, never cancelled: a run waiting behind a running one reads the newest +# content main when it starts, so quick saves in a row end in one more publish, not many. +concurrency: + group: content-bump + cancel-in-progress: false + +jobs: + bump: + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write # push content/bump + pull-requests: write # open or update the PR, comment on it + actions: write # dispatch ci.yml on the bump commit + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + submodules: true + + - name: Point src/content at content main + id: bump + run: | + git -C src/content fetch --quiet origin main + old=$(git rev-parse HEAD:src/content) + new=$(git -C src/content rev-parse FETCH_HEAD) + echo "new=$new" >> "$GITHUB_OUTPUT" + if [ "$old" = "$new" ]; then + echo "Already published ($new)." + echo "changed=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + files=$(git -C src/content diff --name-only "$old" "$new") + echo "$files" + if echo "$files" | grep -qvE '\.(md|json)$'; then auto=false; else auto=true; fi + git -C src/content checkout --quiet "$new" + { + echo "changed=true" + echo "auto=$auto" + echo "files<> "$GITHUB_OUTPUT" + + - name: Commit and push content/bump + if: steps.bump.outputs.changed == 'true' + env: + NEW: ${{ steps.bump.outputs.new }} + FILES: ${{ steps.bump.outputs.files }} + run: | + git config user.name "Content publish" + git config user.email "actions@noreply.git.poli0981.dev" + git switch --create content/bump + git add src/content + git commit --quiet -m "chore(content): publish ${NEW:0:7}" -m "$FILES" + git push --force --quiet origin content/bump + + - name: Open or update the PR, queue CI + if: steps.bump.outputs.changed == 'true' + env: + TOKEN: ${{ github.token }} + API: ${{ github.api_url }} + REPO: ${{ github.repository }} + NEW: ${{ steps.bump.outputs.new }} + AUTO: ${{ steps.bump.outputs.auto }} + run: node scripts/content-publish.mjs open diff --git a/.gitea/workflows/lighthouse.yml b/.gitea/workflows/lighthouse.yml new file mode 100644 index 0000000..9e47bef --- /dev/null +++ b/.gitea/workflows/lighthouse.yml @@ -0,0 +1,148 @@ +name: Lighthouse + +# docs 14 §3: assert the perf budget on a preview build — WARN ONLY, never blocking. +# Lighthouse numbers move with runner load, so a hard gate here would block deploys on +# noise rather than on regressions. The job is advisory by construction: assertions are +# `warn`, and it is not a required check of main's branch protection (Gitea still shows a +# failed run red, continue-on-error or not). Per the doc, act when it goes red twice in a +# row rather than on a single bad run. +on: + pull_request: + paths-ignore: ["poli0981.dev-docs/**", "*.md", "LICENSE"] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lighthouse: + runs-on: ubuntu-latest + timeout-minutes: 30 + # The whole point: informative, never a blocker. + continue-on-error: true + permissions: + contents: read + env: + # Lighthouse CI itself, at a pinned version (released 2026-11-11). It was bundled in + # treosh/lighthouse-ci-action, which the Gitea runner cannot unpack (two files in its + # node_modules differ only in case, and the runner's action cache sits on a + # case-insensitive Windows disk). npx installs it in the job container instead; the + # job holds no secret. Bump by hand: Renovate does not read this line. + LHCI_VERSION: 0.16.1 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + submodules: recursive # src/content, or the build has no content to measure + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + cache: npm + + # Same as ci.yml: no dependency lifecycle scripts in CI. + - name: Install + run: npm ci --ignore-scripts + + - name: Generate Cloudflare binding types + run: npm run types + + - name: Build + run: npm run build + + # GitHub's image shipped Google Chrome; the Gitea runner's image has none, so Lighthouse + # gets Playwright's Chromium at the version the lockfile pins (CHROME_PATH is what + # chrome-launcher reads). The job runs as root, where Chrome refuses to start with its + # sandbox on: lighthouserc.json passes --no-sandbox (the pages are this build, on + # localhost). + - name: Chrome for Lighthouse + run: | + if [ -x /usr/bin/google-chrome ]; then + echo "CHROME_PATH=/usr/bin/google-chrome" >> "$GITHUB_ENV" + else + npx playwright install --with-deps chromium + echo "CHROME_PATH=$(node -p "require('playwright').chromium.executablePath()")" >> "$GITHUB_ENV" + fi + + # Cloudflare's edge compresses every text response in production; the preview does not. + # Lighthouse measures through nginx (gzip — a little larger than the edge's brotli) so + # its simulated phone downloads about the bytes a real one would (home HTML 108 KB raw, + # 25–30 KB compressed), not three to four times as many. GitHub's image had nginx and a + # user with sudo; the Gitea runner's job container runs as root and has no nginx. + - name: nginx for the compressing proxy + run: | + SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO=sudo + if ! command -v nginx >/dev/null; then + $SUDO apt-get update -qq + $SUDO apt-get install -y -qq --no-install-recommends nginx + fi + cat > "$RUNNER_TEMP/nginx.conf" <<'EOF' + events {} + http { + access_log off; + gzip on; + gzip_proxied any; + gzip_comp_level 6; + gzip_vary on; + gzip_types text/css text/javascript application/javascript application/json + application/manifest+json application/xml image/svg+xml; + server { + listen 127.0.0.1:4322; + location / { + proxy_pass http://127.0.0.1:4321; + proxy_http_version 1.1; + proxy_set_header Accept-Encoding ""; + } + } + } + EOF + $SUDO nginx -t -c "$RUNNER_TEMP/nginx.conf" + + # Everything that has to stay up runs in this one step: the Gitea runner (act) ends what + # a step started in the background when that step ends. `astro preview` boots the built + # worker in workerd with the real bindings and _headers, so the numbers reflect + # production rather than a bare static server. + # + # Four representative pages (docs 14 §3): home, a blog post, a story chapter, a gallery + # album — the heaviest template of each kind — collected and asserted against + # lighthouserc.json (warn-only). Nothing is uploaded to Google's public storage. + - name: Lighthouse + run: | + SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO=sudo + # 127.0.0.1, not localhost: in the runner's container `localhost` binds ::1 only. + npm run preview -- --host 127.0.0.1 > "$RUNNER_TEMP/preview.log" 2>&1 & + $SUDO nginx -c "$RUNNER_TEMP/nginx.conf" + up=false + for i in $(seq 1 60); do + if curl -sf -o /dev/null http://127.0.0.1:4322/; then + echo "preview up after ${i}s"; up=true; break + fi + sleep 1 + done + if [ "$up" != true ]; then + echo "preview server never came up"; cat "$RUNNER_TEMP/preview.log"; exit 1 + fi + # --ignore-scripts: nothing in Lighthouse CI needs an install script, and the repo's + # .npmrc (strict-allow-scripts) would refuse any it does not know. + lhci() { npx --yes --ignore-scripts "@lhci/cli@${LHCI_VERSION}" "$@"; } + lhci collect --config=./lighthouserc.json \ + --url=http://127.0.0.1:4322/ \ + --url=http://127.0.0.1:4322/blog/lan-dau-viet-truyen/ \ + --url=http://127.0.0.1:4322/truyen/dem-khong-tieng/chuong-01/ \ + --url=http://127.0.0.1:4322/gallery/game/ + lhci assert --config=./lighthouserc.json + + # The reports, kept even when an assertion warns. An upload never decides the job. + - name: Keep the reports + if: ${{ !cancelled() }} + continue-on-error: true + uses: christopherhx/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7 # v4 + with: + name: lighthouse-reports + path: .lighthouseci/ + if-no-files-found: ignore + retention-days: 14 diff --git a/.gitea/workflows/qodana.yml b/.gitea/workflows/qodana.yml new file mode 100644 index 0000000..009d50f --- /dev/null +++ b/.gitea/workflows/qodana.yml @@ -0,0 +1,131 @@ +name: Qodana + +# JetBrains Qodana (Qodana for JS, WebStorm's inspections) over the whole repository: on every +# PR, on main and by hand. Settings live in qodana.yaml; its failThreshold makes any finding +# fail the scan. Results go to Qodana Cloud (the project token is the QODANA_TOKEN secret) and +# into the `qodana-report` artifact (SARIF + HTML report): Gitea has no code-scanning UI, so +# the SARIF upload of the GitHub days is gone. +# +# The Qodana CLI, not JetBrains/qodana-action (which relies on GitHub's APIs for annotations +# and comments), at a pinned version, SHA-256 verified — the version and checksum the ops +# repo's reusable-qodana.yml pins. Renovate does not update it (it is not an action): bump +# both together, by hand. A local job rather than a caller of that reusable workflow: the +# scan needs this repo's generated binding types first, and the ops tag callers pin +# (v2026.11.1) predates the reusable one. +# +# Advisory, not required: branch protection requires only CI's `build`. Renovate's PRs skip +# it — Gitea gives a same-repo PR the repository's secrets, and a Renovate run installs the +# very update under review, so no token goes near it — as does a run without the token. +on: + pull_request: + push: + branches: [main] + paths-ignore: ["poli0981.dev-docs/**", "*.md", "LICENSE"] + workflow_dispatch: + +# Explicit, and granted on the job. +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + # Cancel superseded PR runs; let main runs finish. + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + qodana: + name: Qodana for JS + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + env: + QODANA_CLI_VERSION: 2026.3.1 + QODANA_CLI_SHA256: dae6d31f481ed15c6c016fd746e907978f0c1437010326fa04a92f13c7c52338 # qodana_linux_x86_64.tar.gz + steps: + - name: Check for QODANA_TOKEN + id: token + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} + ACTOR: ${{ github.actor }} + AUTHOR: ${{ github.event.pull_request.user.login }} + run: | + if [ "$ACTOR" = renovate-bot ] || [ "$AUTHOR" = renovate-bot ]; then + echo "present=false" >> "$GITHUB_OUTPUT" + echo "::notice::Qodana skipped — a Renovate pull request installs the update under review, so no token goes near it." + elif [ -n "$QODANA_TOKEN" ]; then + echo "present=true" >> "$GITHUB_OUTPUT" + else + echo "present=false" >> "$GITHUB_OUTPUT" + echo "::notice::Qodana skipped — QODANA_TOKEN is not available to this run." + fi + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: steps.token.outputs.present == 'true' + with: + fetch-depth: 0 + submodules: recursive + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + if: steps.token.outputs.present == 'true' + with: + node-version-file: .nvmrc + cache: npm + + # Same rules as ci.yml: no dependency lifecycle script runs in CI, and any lockfile + # package with an install script must be on package.json#allowScripts. + - name: Install + if: steps.token.outputs.present == 'true' + run: npm ci --ignore-scripts + + - name: Install scripts allow-listed + if: steps.token.outputs.present == 'true' + run: npm run check-install-scripts + + # Gitignored, generated types the TypeScript service needs to resolve imports of + # cloudflare:workers, astro:content and friends. + - name: Generate types + if: steps.token.outputs.present == 'true' + run: | + npm run types + npm run types:widgets + npm run astro -- sync + + - name: Install the Qodana CLI ${{ env.QODANA_CLI_VERSION }} + if: steps.token.outputs.present == 'true' + run: | + set -euo pipefail + tmp="${RUNNER_TEMP:-/tmp}" + tgz="$tmp/qodana.tar.gz" + curl --proto '=https' -fsSL --retry 3 -o "$tgz" \ + "https://github.com/JetBrains/qodana-cli/releases/download/v${QODANA_CLI_VERSION}/qodana_linux_x86_64.tar.gz" + echo "${QODANA_CLI_SHA256} $tgz" | sha256sum -c - + mkdir -p "$tmp/qodana-cli" + tar -xzf "$tgz" -C "$tmp/qodana-cli" qodana + echo "$tmp/qodana-cli" >> "$GITHUB_PATH" + + # Whole repository every time (it is small), so the quality gate in qodana.yaml always + # judges the full picture rather than the files a PR happens to touch. Native mode + # (qodana.yaml: withinDocker: false): the job already is a container. + - name: Qodana scan + if: steps.token.outputs.present == 'true' + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} + QODANA_ENDPOINT: https://qodana.cloud + run: | + qodana --version + qodana scan --within-docker false \ + --results-dir "${RUNNER_TEMP:-/tmp}/qodana/results" \ + --cache-dir "${RUNNER_TEMP:-/tmp}/qodana/cache" + + # !cancelled(), not the implicit success(): a scan that finds something fails, and + # those are exactly the findings the report must keep. An upload never decides the job. + - name: Keep the report + if: ${{ !cancelled() && steps.token.outputs.present == 'true' }} + continue-on-error: true + uses: christopherhx/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7 # v4 + with: + name: qodana-report + path: ${{ runner.temp }}/qodana/results/ + if-no-files-found: ignore + retention-days: 14 diff --git a/.gitea/workflows/security.yml b/.gitea/workflows/security.yml new file mode 100644 index 0000000..cdf1613 --- /dev/null +++ b/.gitea/workflows/security.yml @@ -0,0 +1,37 @@ +# Security checks from the ops repo (poli0981/.github, runbook §3.5 item 2 and §4.3). +# +# secrets → gitleaks over the whole git history; fails on a finding +# sast → Opengrep: the workflow, Dockerfile and shell rules always, plus the +# JavaScript / TypeScript rules (`node: true`); the SARIF report is an +# artifact, since Gitea has no code-scanning UI +# deps → osv-scanner over package-lock.json; fails on a known vulnerability +# +# It replaces osv-scanner.yml (Google's reusable workflow, which uploaded SARIF to GitHub +# code scanning): the dependency scan is the same database over the same lockfile, now +# next to the secrets and SAST checks. ci.yml keeps its per-PR `npm audit` gate. +# +# The reusable workflow is pinned to the commit of the ops repo's tag. Renovate does not +# bump this pin: the `# ops …` comment is no version it reads (runbook §3.2 item 3). +# Move it by hand when the ops repo is tagged. No secrets: nothing here needs a token. +name: Security + +on: + push: + branches: [main] + pull_request: + schedule: + # Wednesdays 14:13 UTC = 21:13 Vietnam: inside the 13:00–16:00 UTC window when the + # runner's PC is on, on this repo's slot in the ops repo's cron registry. + - cron: "13 14 * * 3" + workflow_dispatch: + +# Explicit, never inherited, and granted on the job. +permissions: {} + +jobs: + security: + permissions: + contents: read + uses: poli0981/.github/.gitea/workflows/security.yml@2a255e0e9a60541da5c25fb4ad5cc24bd353d543 # ops v2026.11.1 + with: + node: true diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4f13706..69f7bd8 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -7,10 +7,10 @@ body: attributes: value: | Cảm ơn bạn đã báo lỗi. / Thanks for reporting. - Nhanh hơn: nút "Báo lỗi" ngay trên trang gửi kèm trang và môi trường đang dùng (báo cáo đó đi - vào một repo riêng, không hiện ở đây). / Quicker: the "Report a problem" button on the page - itself sends the page and environment along (those reports go to a private repository and - do not show up here). + Nhanh hơn: nút "Báo lỗi" ngay trên trang gửi kèm trang và môi trường đang dùng (báo cáo đó + thành issue bảo mật, chỉ chủ repo xem được). / Quicker: the "Report a problem" button on the + page itself sends the page and environment along (those reports become confidential issues + only the maintainer can see). Dự án đang ở chế độ bảo trì: form này dành cho lỗi, không dành cho đề xuất tính năng — xem CONTRIBUTING.md. / The project is in maintenance mode: this form is for bugs, not feature requests — see CONTRIBUTING.md. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 2fe006f..8902ed5 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,13 +1,12 @@ # Maintenance mode (CONTRIBUTING.md): issues are for bugs, accessibility and language problems. -# Questions and ideas go to Discussions; security problems are reported privately. +# Gitea reads these forms; outsiders file issues on the GitLab mirror (.gitlab/issue_templates). blank_issues_enabled: false contact_links: - name: Question or idea · Câu hỏi hoặc ý tưởng - url: https://github.com/poli0981/poli0981-dev/discussions + url: mailto:code@poli0981.dev about: >- - The project is in maintenance mode and takes no new features — ask or talk ideas over in - Discussions. · Dự án đang ở chế độ bảo trì, không nhận tính năng mới — hỏi hoặc trao đổi - ý tưởng trong Discussions. + The project is in maintenance mode and takes no new features — ask or share ideas by e-mail. + · Dự án đang ở chế độ bảo trì, không nhận tính năng mới — hỏi hoặc gửi ý tưởng qua e-mail. - name: Security vulnerability · Lỗ hổng bảo mật - url: https://github.com/poli0981/poli0981-dev/security/policy - about: Report it privately, never in a public issue. · Báo riêng, không mở issue công khai. + url: https://git.poli0981.dev/poli0981/poli0981-dev/src/branch/main/SECURITY.md + about: Report it by e-mail, never in a public issue. · Báo qua e-mail, không mở issue công khai. diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index e8a870e..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,45 +0,0 @@ -version: 2 -updates: - # Root npm project. `/workers/widgets` is omitted on purpose: that worker is - # dependency-free (no package.json, the YouTube RSS is hand-parsed), so there is no - # manifest for Dependabot to read. Add an entry the day that worker gains a package.json. - - package-ecosystem: npm - directory: "/" - schedule: - interval: weekly - day: monday - # Supply-chain hardening (docs 06 §6): never propose a release younger than three days. - # Malicious publishes — the Shai-Hulud shape — are usually caught and pulled within hours. - cooldown: - default-days: 3 - open-pull-requests-limit: 8 - groups: - astro: - patterns: ["astro", "@astrojs/*"] - # The type-checking toolchain moves together: typescript-eslint pins the TypeScript - # versions it accepts. - typescript: - patterns: ["typescript", "typescript-eslint"] - dev-tools: - dependency-type: development - ignore: - # `typescript` stays on 6.x on purpose. TypeScript 7.0 ships no JS API, and astro - # check (Volar), typescript-eslint and svelte2tsx all need one. TS 7 itself is the - # `@typescript/native` alias (npm:typescript@7) — and Dependabot skips every `npm:` - # alias, so that one is bumped by hand (docs 17). Lift this ignore once those tools - # support TypeScript 7.1's new API. - - dependency-name: typescript - update-types: ["version-update:semver-major"] - # prettier-plugin-astro 1.x reflows `{expr}` onto separate lines in 50 - # .astro files, which inserts whitespace text nodes inside inline elements. That is a - # visual change, not a formatting one — it needs its own PR with a rendered diff. - - dependency-name: prettier-plugin-astro - update-types: ["version-update:semver-major"] - - - package-ecosystem: github-actions - directory: "/" - schedule: - interval: weekly - day: monday - cooldown: - default-days: 3 diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 9963c7a..23982c4 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -4,8 +4,8 @@ ## Kind of change -The project is in maintenance mode ([CONTRIBUTING.md](https://github.com/poli0981/poli0981-dev/blob/main/CONTRIBUTING.md)): -new features are not accepted, and a `feat:` pull request is closed automatically. +The project is in maintenance mode ([CONTRIBUTING.md](https://git.poli0981.dev/poli0981/poli0981-dev/src/branch/main/CONTRIBUTING.md)): +new features are not accepted, and a `feat:` pull request is closed. - [ ] Dependency update - [ ] Security fix (High/Critical advisory, or a runtime vulnerability) @@ -20,7 +20,7 @@ new features are not accepted, and a `feat:` pull request is closed automaticall ## Accessibility (only if the interface changed) -See [`ACCESSIBILITY.md`](https://github.com/poli0981/poli0981-dev/blob/main/ACCESSIBILITY.md). +See [`ACCESSIBILITY.md`](https://git.poli0981.dev/poli0981/poli0981-dev/src/branch/main/ACCESSIBILITY.md). `npm run test:a11y` covers what a machine can check; the rest is by hand. - [ ] Works with the keyboard alone, start to finish; focus is visible and never lands under a fixed bar diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index af13bab..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,196 +0,0 @@ -name: CI - -# PRs always run: `build` is a required status check in the main ruleset, so a -# paths-ignore here would leave docs-only PRs waiting forever for a check that never -# starts. Pushes to main may still skip docs-only changes. NOTE: use `*.md` (root-level) -# — NOT `**/*.md` — because blog/story content lives at src/content/**/*.{md,mdx}. -on: - pull_request: - # Dispatched on content/bump by content-bump.yml (PRs opened with GITHUB_TOKEN don't - # trigger pull_request workflows), so the required `build` check exists for them. - workflow_dispatch: - push: - branches: [main] - paths-ignore: ["poli0981.dev-docs/**", "*.md", "LICENSE"] - -# Explicit — a missing block makes GitHub default every scope to `none`. -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - # Cancel superseded PR runs; let main runs finish. - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - -jobs: - build: - runs-on: ubuntu-latest - # A hung `wrangler dev` in the smoke test must not hold a runner for six hours. - timeout-minutes: 30 - # Job-level too, so a second job added later can't silently inherit something wider. - permissions: - contents: read - steps: - # Actions are pinned to commit SHAs, not tags: a tag is mutable, so `@v7` would - # execute whatever that tag points at on the day CI runs. Dependabot's - # github-actions ecosystem updates the pins and keeps the version comment in sync. - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 # check-exif diffs changed images against the base ref - # src/content is a submodule (poli0981/content). Without this the content - # collections resolve to an empty directory and the build fails on the - # first getCollection() call. - submodules: recursive - - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version-file: .nvmrc - cache: npm - - # No dependency lifecycle script runs in CI at all (docs 06 §6, anti-worm). None is - # needed: esbuild, workerd and sharp take their platform binaries from - # optionalDependencies — their install scripts only re-verify them — and lefthook's - # only installs git hooks. Local installs stay guarded by package.json#allowScripts - # plus .npmrc strict-allow-scripts. - - name: Install - run: npm ci --ignore-scripts - - # …which also means npm's own strict-allow-scripts check never runs here. This keeps - # the alarm: any lockfile package with an install script must be on allowScripts. - - name: Install scripts allow-listed - run: npm run check-install-scripts - - # Binding types live in the gitignored worker-configuration.d.ts files, generated from - # the wrangler configs; both type checks fail without them. No auth needed. - # --strict-vars=false (in the script): `vars` are typed as string, not their literal - # value, so code comparing e.g. GATE_MODE against "on" typechecks whatever it is set to. - - name: Generate Cloudflare binding types - run: | - npm run types - npm run types:widgets - - - name: Format check - run: npm run format:check - - - name: Lint - run: npm run lint - - # .astro, .svelte and .ts through Volar — the TypeScript 6 API (TS 7.0 has none). - - name: Type check (astro check) - run: npm run check - - # Every .ts file again with the native TypeScript 7 compiler, plus the widgets worker - # (a separate TS project). The version line makes a bin mix-up impossible to miss. - - name: Type check (TypeScript 7) - run: | - node node_modules/@typescript/native/bin/tsc --version - npm run typecheck - - - name: Dead code - run: npm run knip - - # node:test + V8 coverage. Fails under 80% lines; writes coverage/lcov.info for the - # SonarCloud job below. - - name: Unit tests (coverage) - run: npm run test:coverage - - - name: Audit (prod deps, high+) - run: npm audit --omit=dev --audit-level=high - - # THIRD-PARTY-NOTICES.md must match the direct dependencies, and every license must be - # either on the allowlist or explicitly reviewed (docs 08 §6). - - name: Third-party notices - run: npm run gen-notices -- --check - - # The same policy over every package in package-lock.json, transitive dependencies and - # each platform's binaries included; anything outside it needs a per-package review. - - name: Licences (whole dependency tree) - run: npm run check-licenses - - # Fail if any changed image under src/assets/ still carries GPS or a camera serial. - - name: Check EXIF (changed images) - env: - DIFF_BASE: ${{ github.event.pull_request.base.sha || github.event.before }} - run: npm run check-exif -- --changed - - - name: Build - run: npm run build - - # src/worker.ts fronts every page, so a crash there would take the static site down - # too. Boot the built worker locally (wrangler dev, simulated bindings, no auth) and - # probe pages, revalidation, HEAD, redirects, 404s, assets, the gate and the API. - - name: Smoke test built worker - run: npm run smoke - - # Accessibility gate (ACCESSIBILITY.md). The same build is served by `astro preview` - # (workerd, real bindings, no bot gate without its secrets) and driven with the - # runner's own Chrome — Playwright downloads no browser. axe-core scans every page in - # the sitemap and the dialogs while open; the keyboard, reflow and forced-colours - # checks follow. Runs inside this job because `build` is the required status check. - - name: Start preview server - run: | - npm run preview > "$RUNNER_TEMP/preview.log" 2>&1 & - for i in $(seq 1 60); do - if curl -sf -o /dev/null http://localhost:4321/; then - echo "preview up after ${i}s"; exit 0 - fi - sleep 1 - done - echo "preview server never came up"; cat "$RUNNER_TEMP/preview.log"; exit 1 - - - name: Accessibility tests (axe + keyboard) - run: npm run test:a11y - - - name: Preview server log (on failure) - if: failure() - run: tail -n 100 "$RUNNER_TEMP/preview.log" || true - - - name: Upload coverage - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: coverage - path: coverage/lcov.info - retention-days: 7 - if-no-files-found: error - - # Deployment is Cloudflare Workers Builds (connected to this repo), not GitHub - # Actions — this workflow is CI gates only. Workers Builds settings (docs 07): deploy - # command `npx wrangler deploy` on main, version command `npx wrangler versions upload` - # on every other branch. Plain `wrangler` finds the generated config on its own: the - # build writes .wrangler/deploy/config.json pointing at dist/server/wrangler.json. - - # The SonarCloud analysis (automatic analysis is switched off; this is the only one). - # Needs SONAR_TOKEN, which Dependabot runs and forks never get, so those skip it, as do - # the content/bump dispatches (content only, no code to analyze). - sonarcloud: - needs: build - if: >- - github.event_name == 'push' || - (github.event_name == 'pull_request' && - github.event.pull_request.head.repo.full_name == github.repository && - github.actor != 'dependabot[bot]') - runs-on: ubuntu-latest - timeout-minutes: 15 - permissions: - contents: read - pull-requests: read - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 # blame data and new-code detection need the whole history - - - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: coverage - path: coverage - - # Settings live in sonar-project.properties. On pull requests the job waits for the - # quality gate and fails with it, so a red gate is visible on the PR; on main it only - # reports (the gate there is a trend, not a merge decision). - - name: SonarCloud scan - uses: SonarSource/sonarqube-scan-action@59202af334b4ba7b5db01b701b8e79f8b3bef0f4 # v8.5.0 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: >- - ${{ github.event_name == 'pull_request' && '-Dsonar.qualitygate.wait=true -Dsonar.qualitygate.timeout=300' || '' }} diff --git a/.github/workflows/content-bump.yml b/.github/workflows/content-bump.yml deleted file mode 100644 index 1cd6535..0000000 --- a/.github/workflows/content-bump.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Content publish - -# "Publish" in the admin (admin.poli0981.dev) dispatches this. It points the src/content -# submodule at poli0981/content's main, commits that on the content/bump branch, opens -# (or updates) a PR and, when only Markdown/JSON changed, enables auto-merge. CI then runs -# on the bump commit; when the required `build` check passes the PR merges itself and -# Workers Builds deploys main. -# -# Why a workflow: the admin's token can write ONLY the content repo (+ dispatch this). If -# it leaked, the worst case is content edits — never code pushed to this repo. MDX runs -# code at build time, so anything other than .md/.json waits for a human review. -on: - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: content-bump - cancel-in-progress: false - -jobs: - bump: - runs-on: ubuntu-latest - permissions: - contents: write # push content/bump - pull-requests: write # open the PR, enable auto-merge - actions: write # run ci.yml on the bump commit - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - submodules: true - - - name: Point src/content at content main - id: bump - run: | - git -C src/content fetch --quiet origin main - old=$(git rev-parse HEAD:src/content) - new=$(git -C src/content rev-parse FETCH_HEAD) - echo "new=$new" >> "$GITHUB_OUTPUT" - if [ "$old" = "$new" ]; then - echo "Already published ($new)." - echo "changed=false" >> "$GITHUB_OUTPUT" - exit 0 - fi - files=$(git -C src/content diff --name-only "$old" "$new") - echo "$files" - if echo "$files" | grep -qvE '\.(md|json)$'; then auto=false; else auto=true; fi - git -C src/content checkout --quiet "$new" - { - echo "changed=true" - echo "auto=$auto" - echo "files<> "$GITHUB_OUTPUT" - - - name: Commit, open/update the PR, queue CI - if: steps.bump.outputs.changed == 'true' - env: - GH_TOKEN: ${{ github.token }} - NEW: ${{ steps.bump.outputs.new }} - AUTO: ${{ steps.bump.outputs.auto }} - FILES: ${{ steps.bump.outputs.files }} - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git switch --create content/bump - git add src/content - git commit --quiet -m "chore(content): publish ${NEW:0:7}" -m "$FILES" - git push --force --quiet origin content/bump - - if [ "$(gh pr view content/bump --json state --jq .state 2>/dev/null)" != "OPEN" ]; then - gh pr create --base main --head content/bump \ - --title "chore(content): publish from admin" \ - --body "Bumps \`src/content\` to poli0981/content@${NEW}. Opened by the admin's **Publish** button (.github/workflows/content-bump.yml)." - fi - - if [ "$AUTO" = "true" ]; then - gh pr merge content/bump --auto --squash - else - gh pr merge content/bump --disable-auto 2>/dev/null || true - gh pr comment content/bump --body "This publish touches files other than .md/.json (MDX runs code at build time), so it waits for a review instead of auto-merging." - fi - - # PRs opened with GITHUB_TOKEN don't trigger pull_request workflows; a dispatch is - # the exception, and its `build` check lands on the bump commit for the ruleset. - gh workflow run ci.yml --ref content/bump diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml deleted file mode 100644 index 6eb3921..0000000 --- a/.github/workflows/lighthouse.yml +++ /dev/null @@ -1,106 +0,0 @@ -name: Lighthouse - -# docs 14 §3: assert the perf budget on a preview build — WARN ONLY, never blocking. -# Lighthouse numbers move with runner load, so a hard gate here would block deploys on -# noise rather than on regressions. The job is advisory by construction: assertions are -# `warn`, and continue-on-error means a red run never fails the check suite. -# Per the doc, act when it goes red twice in a row rather than on a single bad run. -on: - pull_request: - paths-ignore: ["poli0981.dev-docs/**", "*.md", "LICENSE"] - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - lighthouse: - runs-on: ubuntu-latest - timeout-minutes: 30 - # The whole point: informative, never a blocker. - continue-on-error: true - permissions: - contents: read - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - submodules: recursive # src/content, or the build has no content to measure - - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version-file: .nvmrc - cache: npm - - # Same as ci.yml: no dependency lifecycle scripts in CI. - - name: Install - run: npm ci --ignore-scripts - - - name: Generate Cloudflare binding types - run: npm run types - - - name: Build - run: npm run build - - # `astro preview` boots the built worker in workerd with the real bindings and - # _headers, so the numbers reflect production rather than a bare static server. - - name: Start preview server - run: npm run preview & - - # Cloudflare's edge compresses every text response in production; the preview does not. - # Lighthouse measures through nginx (preinstalled on the runner, gzip — a little larger - # than the edge's brotli) so its simulated phone downloads about the bytes a real one - # would (home HTML 108 KB raw, 25–30 KB compressed), not three to four times as many. - - name: Start compressing proxy - run: | - cat > "$RUNNER_TEMP/nginx.conf" <<'EOF' - events {} - http { - access_log off; - gzip on; - gzip_proxied any; - gzip_comp_level 6; - gzip_vary on; - gzip_types text/css text/javascript application/javascript application/json - application/manifest+json application/xml image/svg+xml; - server { - listen 127.0.0.1:4322; - location / { - proxy_pass http://localhost:4321; - proxy_http_version 1.1; - proxy_set_header Accept-Encoding ""; - } - } - } - EOF - sudo nginx -t -c "$RUNNER_TEMP/nginx.conf" - sudo nginx -c "$RUNNER_TEMP/nginx.conf" - - - name: Wait for the server - run: | - for i in $(seq 1 60); do - if curl -sf -o /dev/null http://127.0.0.1:4322/; then - echo "preview up after ${i}s"; exit 0 - fi - sleep 1 - done - echo "preview server never came up"; exit 1 - - # Four representative pages (docs 14 §3): home, a blog post, a story chapter, a - # gallery album — the heaviest template of each kind. The action bundles @lhci/cli, - # so nothing is downloaded with npx at run time; it collects, asserts against - # lighthouserc.json (warn-only) and uploads the reports even when an assertion warns. - - name: Lighthouse - uses: treosh/lighthouse-ci-action@3e7e23fb74242897f95c0ba9cabad3d0227b9b18 # 12.6.2 - with: - configPath: ./lighthouserc.json - urls: | - http://127.0.0.1:4322/ - http://127.0.0.1:4322/blog/lan-dau-viet-truyen/ - http://127.0.0.1:4322/truyen/dem-khong-tieng/chuong-01/ - http://127.0.0.1:4322/gallery/game/ - uploadArtifacts: true - artifactName: lighthouse-reports diff --git a/.github/workflows/osv-scanner.yml b/.github/workflows/osv-scanner.yml deleted file mode 100644 index aeac172..0000000 --- a/.github/workflows/osv-scanner.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: OSV scan - -# docs 06 §6 and 08 §2 both call for a weekly dependency scan; this is it. -# It complements the per-PR `npm audit --omit=dev --audit-level=high` gate in ci.yml: -# audit only sees the production tree and only fails on high+, while OSV covers the -# whole lockfile (devDependencies included) against the full OSV database. -on: - schedule: - # Mondays 03:17 UTC — off the hour, where scheduled-runner contention is lowest. - - cron: "17 3 * * 1" - workflow_dispatch: - # Re-run when the dependency graph itself changes, so a bad bump is caught on the PR - # rather than up to a week later… - pull_request: - paths: ["package-lock.json"] - # …and once it lands, so the Security tab reflects main straight away. - push: - branches: [main] - paths: ["package-lock.json"] - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - scan: - # The repo is public, so code scanning is free: findings are uploaded as SARIF and - # show up under Security → Code scanning, and a finding still fails the run. - # PR runs skip the upload — Dependabot PRs get a read-only token, so the upload - # step would fail there for a reason unrelated to the scan itself. - uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@32d3cd482bdadfb38b186c0ad1b031902d55d932 # v2.7.1 - permissions: - actions: read - contents: read - security-events: write - with: - upload-sarif: ${{ github.event_name != 'pull_request' }} - scan-args: |- - --lockfile=package-lock.json diff --git a/.github/workflows/qodana.yml b/.github/workflows/qodana.yml deleted file mode 100644 index 6935ef0..0000000 --- a/.github/workflows/qodana.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: Qodana - -# JetBrains Qodana (Qodana for JS, WebStorm's inspections) over the whole repository: on every -# PR, on main and by hand. Settings live in qodana.yaml. Results go to Qodana Cloud (the -# project token is the QODANA_TOKEN secret) and, for main, to GitHub code scanning as SARIF. -# -# Advisory, not required: the main ruleset requires only `build`, and Dependabot and fork PRs -# get no secrets, so they skip this job like the SonarCloud one in ci.yml. -on: - pull_request: - push: - branches: [main] - paths-ignore: ["poli0981.dev-docs/**", "*.md", "LICENSE"] - workflow_dispatch: - -# Explicit — a missing block makes GitHub default every scope to `none`. -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - # Cancel superseded PR runs; let main runs finish. - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - -jobs: - qodana: - if: >- - github.event_name != 'pull_request' || - (github.event.pull_request.head.repo.full_name == github.repository && - github.actor != 'dependabot[bot]') - runs-on: ubuntu-latest - timeout-minutes: 30 - permissions: - contents: read - checks: write # problem annotations on the commit - pull-requests: write # the summary comment on PRs - security-events: write # SARIF upload (main and manual runs) - steps: - # Pinned to commit SHAs like every other workflow here; Dependabot keeps them current. - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - # The PR's own head commit, not the merge preview, so Qodana Cloud links to it. - ref: ${{ github.event.pull_request.head.sha || github.sha }} - fetch-depth: 0 - submodules: recursive - persist-credentials: false - - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version-file: .nvmrc - cache: npm - - # Same rules as ci.yml: no dependency lifecycle script runs in CI, and any lockfile - # package with an install script must be on package.json#allowScripts. - - name: Install - run: npm ci --ignore-scripts - - - name: Install scripts allow-listed - run: npm run check-install-scripts - - # Gitignored, generated types the TypeScript service needs to resolve imports of - # cloudflare:workers, astro:content and friends. - - name: Generate types - run: | - npm run types - npm run types:widgets - npm run astro -- sync - - - name: Qodana scan - uses: JetBrains/qodana-action@13e3acbbaeb2cbfc37893b98e74594985edf42eb # v2026.2.4 - env: - QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} - QODANA_ENDPOINT: https://qodana.cloud - with: - # Whole repository every time (it is small), so the quality gate in qodana.yaml - # always judges the full picture rather than the files a PR happens to touch. - pr-mode: false - upload-result: true - - # Like the OSV scan: main and manual runs only, so PR runs don't open code-scanning - # alerts for code that may never merge. - - name: Upload SARIF to code scanning - if: ${{ !cancelled() && github.event_name != 'pull_request' }} - uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 - with: - sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json - category: qodana diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml deleted file mode 100644 index 455e39e..0000000 --- a/.github/workflows/triage.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Triage - -# Maintenance mode (CONTRIBUTING.md): an issue or pull request asking for a new feature is -# labelled `enhancement` + `out-of-scope`, answered in both languages and closed. The rules -# live in scripts/triage.mjs (unit-tested); this only wires them to GitHub. The owner's own -# items, bots, and anything labelled `maintenance-exception` are left alone. -# -# pull_request_target runs with this repository's token, so it must never run a pull -# request's code. Nothing is checked out at all: the script reads scripts/triage.mjs from the -# default branch through the API and imports it from memory. -on: - issues: - types: [opened, reopened, edited, labeled] - pull_request_target: - types: [opened, reopened, edited, labeled] - # Dry run on main: classify a title and print the decision, writing nothing. - workflow_dispatch: - inputs: - title: - description: "Title to classify" - required: true - kind: - description: "issue or pull_request" - default: issue - -permissions: {} - -concurrency: - group: triage-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }} - cancel-in-progress: false - -jobs: - triage: - runs-on: ubuntu-latest - timeout-minutes: 5 - permissions: - contents: read - issues: write - pull-requests: write - steps: - - name: Label and close feature requests - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { data: file } = await github.rest.repos.getContent({ - ...context.repo, - path: "scripts/triage.mjs", - ref: context.payload.repository.default_branch, - }); - const source = file.content.replaceAll("\n", ""); - const { decide, closingComment, LABELS } = await import( - `data:text/javascript;base64,${source}` - ); - - if (context.eventName === "workflow_dispatch") { - const { title, kind } = context.payload.inputs; - const verdict = decide({ title, labels: [], author: "someone", association: "NONE" }); - core.notice(`${kind} "${title}": ${verdict.action} (${verdict.reason})`); - return; - } - - const item = context.payload.issue ?? context.payload.pull_request; - const kind = context.payload.pull_request ? "pull_request" : "issue"; - const verdict = decide({ - title: item.title, - labels: (item.labels ?? []).map((label) => label.name), - author: item.user.login, - association: item.author_association, - sender: context.payload.sender?.login, - owner: context.repo.owner, - state: item.state, - }); - core.info(`#${item.number}: ${verdict.action} (${verdict.reason})`); - if (verdict.action !== "close") return; - - const target = { ...context.repo, issue_number: item.number }; - await github.rest.issues.addLabels({ ...target, labels: [LABELS.feature, LABELS.closed] }); - await github.rest.issues.createComment({ ...target, body: closingComment(kind) }); - if (kind === "pull_request") { - await github.rest.pulls.update({ ...context.repo, pull_number: item.number, state: "closed" }); - } else { - await github.rest.issues.update({ ...target, state: "closed", state_reason: "not_planned" }); - } diff --git a/.gitlab/issue_templates/Accessibility.md b/.gitlab/issue_templates/Accessibility.md new file mode 100644 index 0000000..8ef1ab0 --- /dev/null +++ b/.gitlab/issue_templates/Accessibility.md @@ -0,0 +1,36 @@ + + +Cảm ơn bạn đã báo. Bạn không cần tự tìm nguyên nhân, và không cần nói gì về tình trạng khuyết tật +của mình. / Thanks for reporting. You do not have to diagnose anything, and you never need to tell +me about a disability. + +Không muốn đăng công khai? Gửi email tới accessibility@poli0981.dev hoặc dùng nút "Báo lỗi" ở cuối +mọi trang (không cần tài khoản). / Prefer not to post in public? Email accessibility@poli0981.dev, +or use "Report a bug" at the bottom of every page (no account needed). + +Tiêu đề / Title: `[a11y] …` + +### Bạn đang định làm gì? / What were you trying to do? + + + +### Điều gì đã xảy ra? / What happened instead? + + + +### Trang / Page + + + +### Môi trường / Environment + + + +### Mức độ / Severity + +- [ ] Chặn hẳn — không làm được việc chính / Critical — blocks a core task +- [ ] Nghiêm trọng — rất khó, nhưng có cách khác / Serious — major difficulty, a workaround exists +- [ ] Vừa — gây khó chịu hoặc không nhất quán / Moderate — annoying or inconsistent +- [ ] Nhẹ — ảnh hưởng ít / Minor — little impact + +/label ~accessibility diff --git a/.gitlab/issue_templates/Bug.md b/.gitlab/issue_templates/Bug.md new file mode 100644 index 0000000..f7926a4 --- /dev/null +++ b/.gitlab/issue_templates/Bug.md @@ -0,0 +1,34 @@ + + +Cảm ơn bạn đã báo lỗi. / Thanks for reporting. + +Nhanh hơn: nút "Báo lỗi" ngay trên trang gửi kèm trang và môi trường đang dùng (báo cáo đó thành +issue bảo mật, chỉ chủ repo xem được). / Quicker: the "Report a problem" button on the page itself +sends the page and environment along (those reports become confidential issues only the maintainer +can see). + +Dự án đang ở chế độ bảo trì: mẫu này dành cho lỗi, không dành cho đề xuất tính năng — xem +CONTRIBUTING.md. / The project is in maintenance mode: this template is for bugs, not feature +requests — see CONTRIBUTING.md. + +Tiêu đề / Title: `[web-report] …` + +### Mô tả / Description + + + +### Trang / Route + + + +### Môi trường / Environment + + + +### Console log (tùy chọn / optional) + +```text + +``` + +/label ~bug diff --git a/.gitlab/issue_templates/Language.md b/.gitlab/issue_templates/Language.md new file mode 100644 index 0000000..135976e --- /dev/null +++ b/.gitlab/issue_templates/Language.md @@ -0,0 +1,25 @@ + + +Cảm ơn bạn! Mỗi báo cáo một chỗ (hoặc một nhóm chỗ cùng một lỗi). / Thanks! One report per place, +or per group of places with the same problem. + +Tiêu đề / Title: `[language] …` + +### Trang / Page + + + +### Ngôn ngữ / Language + +- [ ] Tiếng Việt / Vietnamese +- [ ] Tiếng Anh / English + +### Câu hiện tại / Current text + + + +### Đề xuất sửa và lý do / Suggested wording and why + + + +/label ~language diff --git a/.gitlab/merge_request_templates/Default.md b/.gitlab/merge_request_templates/Default.md new file mode 100644 index 0000000..83a9f3e --- /dev/null +++ b/.gitlab/merge_request_templates/Default.md @@ -0,0 +1,36 @@ + + +## What and why + + + +## Kind of change + +The project is in maintenance mode ([CONTRIBUTING.md](https://git.poli0981.dev/poli0981/poli0981-dev/src/branch/main/CONTRIBUTING.md)): +new features are not accepted, and a `feat:` merge request is closed. GitLab CI does not run here: +the maintainer runs CI on Gitea before applying the change. + +- [ ] Dependency update +- [ ] Security fix (High/Critical advisory, or a runtime vulnerability) +- [ ] Major language, runtime or framework upgrade +- [ ] Bug fix — including UI/UX and accessibility +- [ ] Language fix — a misleading typo, or wording that does not fit + +## Checks + +- [ ] `npm run format:check`, `npm run lint`, `npm run check`, `npm run typecheck`, `npm test` +- [ ] `CHANGELOG.md` updated under `[Unreleased]` when visitors or operators would notice the change + +## Accessibility (only if the interface changed) + +See [`ACCESSIBILITY.md`](https://git.poli0981.dev/poli0981/poli0981-dev/src/branch/main/ACCESSIBILITY.md). +`npm run test:a11y` covers what a machine can check; the rest is by hand. + +- [ ] Works with the keyboard alone, start to finish; focus is visible and never lands under a fixed bar +- [ ] Anything that opens (menu, dialog, panel) closes with Esc and hands focus back to what opened it +- [ ] Icon-only controls have a name that starts with their visible text, taken from `src/i18n` +- [ ] State and "you are here" are not shown by colour alone; new colours go through `tests/palette.test.ts` +- [ ] Headings do not skip a level; images have an `alt` (empty only when decorative) +- [ ] New animation has a still branch under `prefers-reduced-motion` +- [ ] Looked at 320 px wide, at 200% zoom, in dark and light, in Vietnamese and English +- [ ] Listened to once with a screen reader diff --git a/.gitleaksignore b/.gitleaksignore new file mode 100644 index 0000000..3f1773f --- /dev/null +++ b/.gitleaksignore @@ -0,0 +1,19 @@ +# gitleaks, run by the ops repo's security.yml, scans every commit with its default rules. +# Each line below is one finding that is NOT a secret, as commit:file:rule:line. Anything +# else is still reported, and so is a later commit that touches these lines. A real secret +# never goes here: it is rotated, and the history is dealt with. + +# A deliberately forged Cloudflare Access JWT: the smoke test sends it to prove the admin +# API refuses a token that does not verify (it now lives in a variable, `forgedJwt`). +7ec559d216e593f53938bf1db8c85584f9115190:scripts/smoke-worker.mjs:generic-api-key:177 + +# The Cloudflare Access application's AUD tag. Public by design: it only says which app a +# token must be minted for (the comment above it in wrangler.jsonc says so). +7ec559d216e593f53938bf1db8c85584f9115190:wrangler.jsonc:generic-api-key:85 + +# The Cloudflare Web Analytics site tag: every production page sends it in its HTML. +48d4e7bbdccd00b34ac28819ce42309488bb63cd:src/components/CfBeacon.astro:generic-api-key:11 + +# SonarQube Cloud's project key, a public identifier, in the sonar-project.properties that +# left with Sonar (migration decision D1). +8a1316280f298a2814ba941ad33baad1d0596b3b:sonar-project.properties:generic-api-key:4 diff --git a/.gitmodules b/.gitmodules index bfc7731..f6ef049 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "src/content"] path = src/content - url = https://github.com/poli0981/content.git + url = https://git.poli0981.dev/poli0981/content.git diff --git a/ACCESSIBILITY.md b/ACCESSIBILITY.md index 366b500..fdecc7e 100644 --- a/ACCESSIBILITY.md +++ b/ACCESSIBILITY.md @@ -16,8 +16,9 @@ what a visitor can expect, the site wins. ## Reporting a barrier Email **accessibility@poli0981.dev**, or use **Report a bug** at the bottom of every page — it needs -no account and lands in a private tracker. If you use GitHub, you can open an issue with the -[Accessibility template](https://github.com/poli0981/poli0981-dev/issues/new?template=accessibility.yml). +no account and lands in a private tracker. If you have a GitLab account, you can open an issue with +the [Accessibility template](https://gitlab.com/poli0981/poli0981-dev/-/issues/new?issuable_template=Accessibility) +on the mirror. It helps to say which page, what you were trying to do, what happened instead, and which browser and assistive technology you use. You do not have to diagnose anything, and you never need to tell me @@ -152,12 +153,14 @@ npm run preview npm run test:a11y ``` -It drives the Chrome that is already installed; set `A11Y_CHANNEL=msedge` to use Edge instead. If a +It drives the Chrome that is already installed; set `A11Y_CHANNEL=msedge` to use Edge instead, or +`A11Y_CHANNEL=bundled` for Playwright's own Chromium (what CI uses: the Gitea runner's image has no +Chrome). If a rule cannot be met, say why in the pull request rather than switching the rule off. ## Ownership and review -Maintained by Kokone ([poli0981](https://github.com/poli0981)), the site's only maintainer, who +Maintained by Kokone ([poli0981](https://git.poli0981.dev/poli0981)), the site's only maintainer, who triages reports and keeps this file and the site's statement in step. Both are reviewed with every release that changes the interface and at least once a year ([`17_MAINTENANCE.md`](poli0981.dev-docs/17_MAINTENANCE.md)). diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d0858..509d036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,55 @@ Notable changes to poli0981.dev. The site deploys continuously from `main`; tags mark milestones. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). -Content changes (posts, stories, albums) live in [`poli0981/content`](https://github.com/poli0981/content) -and are not listed here. +Content changes (posts, stories, albums) live in [`poli0981/content`](https://git.poli0981.dev/poli0981/content) +and are not listed here. Links to pull requests before 2.4.0 point at the GitHub repository, which +no longer exists; the commits themselves are all on Gitea. ## [Unreleased] +## [2.4.0] — 2026-11-24 + +The move from GitHub to the owner's Gitea. The GitHub account is gone, and with it the +repository, Actions, Workers Builds' source, the admin's tokens and the bug-report tracker. This +release puts every one of them somewhere that works again; nothing new is added (maintenance +mode, [`CONTRIBUTING.md`](CONTRIBUTING.md)). + +### Changed + +- **Where the code lives.** The canonical repository is + [`git.poli0981.dev/poli0981/poli0981-dev`](https://git.poli0981.dev/poli0981/poli0981-dev), the + content submodule [`git.poli0981.dev/poli0981/content`](https://git.poli0981.dev/poli0981/content). + Issues and merge requests go to the mirror on + [GitLab](https://gitlab.com/poli0981/poli0981-dev) (Bug, Accessibility and Language templates); + patches and questions to `code@poli0981.dev`; security reports by e-mail only. +- **CI runs on Gitea Actions** (`.gitea/workflows`), on the owner's own runner: the build job is + unchanged in what it checks, and installs Playwright's Chromium where the runner image has no + Chrome. **`main` deploys from CI**: a `deploy` job runs `wrangler deploy` after `build` passes + and waits until `/api/health` reports the commit. Cloudflare Workers Builds is gone, and pull + requests get no preview versions. +- **The admin works through Gitea** (`src/lib/admin/gitea.ts`): one bot token + (`GITEA_BOT_TOKEN`) for saves and publishing, several files per commit with Gitea checking + each file's version, and the publish bar reading the content PR, its build status and the + publish workflow from Gitea. Publishing still merges itself for Markdown/JSON and waits for a + review when MDX changes: CI merges the content PR and starts the deploy. +- **Bug reports from the site** become **confidential issues on the GitLab mirror** + (`GITLAB_ISSUES_TOKEN`, var `REPORT_PROJECT`), seen only by the maintainer; reporter text cannot + ping anyone or run a GitLab quick action. Privacy §4 says so (content repo, effective + 2026-11-24). The Discord fallback is unchanged. +- **The activity widget** reads Gitea's public activity feed (no token) and links to Gitea. +- The dev profile link, the About page, the console banner, the legal pages' source and issue + links, and the project pages point at Gitea. +- **Dependency updates** come from Renovate (the shared `poli0981/renovate-config` preset, 3-day + wait kept) instead of Dependabot. **Security checks** come from the ops repository's + `security.yml`: gitleaks over the whole history, Opengrep and osv-scanner, weekly and on every + change. **Qodana** runs through its CLI; reports are artifacts. + +### Removed + +- SonarQube Cloud (job, configuration and badge), GitHub code scanning uploads, the OSV workflow + (replaced by `security.yml`) and the maintenance-mode triage bot, which needed GitHub's events: + out-of-scope requests on the mirror are closed by hand. + ## [2.3.0] — 2026-11-21 The last feature release: from here on the project is in **maintenance mode** @@ -292,11 +336,12 @@ The public launch is tagged `v1-launch`; the 1.x changes after it were not tagge - **2026-10** — Custom Worker entry in front of every page; Workers Rate Limiting; Web Analytics; topic email aliases; R2 media; the Turnstile gate; the admin at `admin.poli0981.dev`. -[Unreleased]: https://github.com/poli0981/poli0981-dev/compare/v2.3.0...HEAD -[2.3.0]: https://github.com/poli0981/poli0981-dev/compare/v2.2.0...v2.3.0 -[2.2.0]: https://github.com/poli0981/poli0981-dev/compare/v2.1.2...v2.2.0 -[2.1.2]: https://github.com/poli0981/poli0981-dev/compare/v2.1.1...v2.1.2 -[2.1.1]: https://github.com/poli0981/poli0981-dev/compare/v2.1.0...v2.1.1 -[2.1.0]: https://github.com/poli0981/poli0981-dev/compare/v2.0.0...v2.1.0 -[2.0.0]: https://github.com/poli0981/poli0981-dev/releases/tag/v2.0.0 -[1.x]: https://github.com/poli0981/poli0981-dev/releases/tag/v1-launch +[Unreleased]: https://git.poli0981.dev/poli0981/poli0981-dev/compare/v2.4.0...main +[2.4.0]: https://git.poli0981.dev/poli0981/poli0981-dev/compare/v2.3.0...v2.4.0 +[2.3.0]: https://git.poli0981.dev/poli0981/poli0981-dev/compare/v2.2.0...v2.3.0 +[2.2.0]: https://git.poli0981.dev/poli0981/poli0981-dev/compare/v2.1.2...v2.2.0 +[2.1.2]: https://git.poli0981.dev/poli0981/poli0981-dev/compare/v2.1.1...v2.1.2 +[2.1.1]: https://git.poli0981.dev/poli0981/poli0981-dev/compare/v2.1.0...v2.1.1 +[2.1.0]: https://git.poli0981.dev/poli0981/poli0981-dev/compare/v2.0.0...v2.1.0 +[2.0.0]: https://git.poli0981.dev/poli0981/poli0981-dev/releases/tag/v2.0.0 +[1.x]: https://git.poli0981.dev/poli0981/poli0981-dev/releases/tag/v1-launch diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 45fde2e..6b6b6c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,13 +2,30 @@ > **Tiếng Việt ở bên dưới.** / Vietnamese below. +## Where things live + +The canonical repository is on the owner's Gitea, +[`git.poli0981.dev/poli0981/poli0981-dev`](https://git.poli0981.dev/poli0981/poli0981-dev). It is +public to read, but registration is closed, so nobody else can open issues or pull requests there. +Since November 2026 (the GitHub repository is gone) outside contributions go through: + +- **Issues and merge requests**: the mirror at + [`gitlab.com/poli0981/poli0981-dev`](https://gitlab.com/poli0981/poli0981-dev). Gitea pushes to + it after every change, so it always has the current code. GitLab CI does not run there: the + owner runs CI on Gitea before applying a merge request. +- **Patches by e-mail**: `git format-patch` / `git send-email` to `code@poli0981.dev`, also for + questions. + +The owner applies accepted changes on Gitea; the mirror then shows the merge request as merged, +or the owner closes it with a link to the commit. + ## Maintenance mode Since **v2.3.0 (November 2026)** this project is in **maintenance mode**. The site is complete; it is kept healthy, but **no new features are being added**. Only these changes are accepted: -1. **Dependency updates** on the regular schedule (Dependabot weekly, a combined update about - once a month, always after a 3-day cooldown). +1. **Dependency updates** on the regular schedule (Renovate, with a combined update about once a + month, always after a 3-day wait). 2. **Security**: a dependency advisory of **High or Critical** severity, or a serious vulnerability in the runtime itself (Node.js, the Workers runtime), fixed as soon as possible — together with a feature only when the owner judges it truly necessary. @@ -19,38 +36,58 @@ is kept healthy, but **no new features are being added**. Only these changes are 5. **Language**: spelling mistakes that could mislead, and wording that does not fit the culture or the local voice, in Vietnamese or English. -**Not accepted: new features.** An issue or pull request asking for one is labelled -`enhancement` + `out-of-scope` and closed automatically -([`.github/workflows/triage.yml`](.github/workflows/triage.yml)). If it was closed by mistake, -reply on it and the owner will take another look; an exception the owner accepts carries the -`maintenance-exception` label. Ideas are still welcome in -[Discussions](https://github.com/poli0981/poli0981-dev/discussions), without any promise. +**Not accepted: new features.** An issue or merge request asking for one is labelled +`enhancement` + `out-of-scope` and closed. If it was closed by mistake, reply on it and the owner +will take another look; an exception the owner accepts carries the `maintenance-exception` label. +Ideas are still welcome by e-mail to `code@poli0981.dev`, without any promise. ### How to report -- **A problem on the website**: the "Báo lỗi / Report a problem" button on the page itself, or the - bug report form under [Issues](https://github.com/poli0981/poli0981-dev/issues/new/choose). -- **An accessibility barrier**: the accessibility form under Issues. -- **A spelling or wording problem**: the language form under Issues. -- **A security vulnerability**: privately — see [SECURITY.md](SECURITY.md). Never in a public - issue. +- **A problem on the website**: the "Báo lỗi / Report a problem" button on the page itself (no + account needed), or the + [Bug template](https://gitlab.com/poli0981/poli0981-dev/-/issues/new?issuable_template=Bug) on + the GitLab mirror. +- **An accessibility barrier**: the + [Accessibility template](https://gitlab.com/poli0981/poli0981-dev/-/issues/new?issuable_template=Accessibility), + or `accessibility@poli0981.dev`. +- **A spelling or wording problem**: the + [Language template](https://gitlab.com/poli0981/poli0981-dev/-/issues/new?issuable_template=Language). +- **A security vulnerability**: by e-mail only — see [SECURITY.md](SECURITY.md). Never in a public + issue on the mirror. -### Pull requests +### Merge requests and patches -Welcome for the five kinds of change above. Keep one change per pull request, follow the checks -in the [pull request template](.github/pull_request_template.md), and run the commands listed in -[README.md](README.md#commands) before opening it. CI must be green — `build` is required, and -the SonarCloud and Qodana gates have to pass too. Commits on `main` are signed. +Welcome for the five kinds of change above. Keep one change per merge request (or patch series), +follow the checks in the merge request template, and run the commands listed in +[README.md](README.md#commands) before sending it. CI on Gitea must be green before the owner +merges — `build` is the required check, and the Qodana and security checks have to pass too. +Commits on `main` are signed. --- +## Mã nguồn ở đâu + +Repo chính nằm trên Gitea của chủ repo, +[`git.poli0981.dev/poli0981/poli0981-dev`](https://git.poli0981.dev/poli0981/poli0981-dev). Ai cũng +đọc được, nhưng đăng ký tài khoản đã đóng nên người khác không mở được issue hay pull request ở đó. +Từ tháng 11/2026 (repo GitHub không còn), đóng góp từ bên ngoài đi qua: + +- **Issue và merge request**: bản sao tại + [`gitlab.com/poli0981/poli0981-dev`](https://gitlab.com/poli0981/poli0981-dev). Gitea đẩy sang + sau mỗi thay đổi, nên luôn có mã mới nhất. GitLab CI không chạy ở đó: chủ repo chạy CI trên Gitea + trước khi áp dụng merge request. +- **Patch qua e-mail**: `git format-patch` / `git send-email` tới `code@poli0981.dev`, câu hỏi cũng + gửi về đây. + +Chủ repo áp dụng thay đổi được chấp nhận trên Gitea; bản sao sau đó hiện merge request là đã merge, +hoặc chủ repo đóng nó kèm link tới commit. + ## Chế độ bảo trì Từ **v2.3.0 (tháng 11/2026)**, dự án ở **chế độ bảo trì**. Trang web đã hoàn chỉnh; repo vẫn được giữ cho khoẻ mạnh nhưng **không thêm tính năng mới**. Chỉ nhận những thay đổi sau: -1. **Cập nhật dependency** định kỳ (Dependabot hằng tuần, gộp một lần khoảng mỗi tháng, luôn sau - 3 ngày "nguội"). +1. **Cập nhật dependency** định kỳ (Renovate, gộp một lần khoảng mỗi tháng, luôn sau 3 ngày chờ). 2. **Bảo mật**: lỗ hổng trong dependency ở mức **High hoặc Critical**, hoặc lỗ hổng nghiêm trọng của chính runtime (Node.js, Workers runtime) — sửa sớm nhất có thể; kèm tính năng chỉ khi chủ repo đánh giá là thật sự cần thiết. @@ -61,24 +98,27 @@ cho khoẻ mạnh nhưng **không thêm tính năng mới**. Chỉ nhận nhữn 5. **Ngôn ngữ**: lỗi chính tả có thể gây hiểu nhầm, câu chữ không hợp văn hoá hay giọng địa phương, ở cả tiếng Việt lẫn tiếng Anh. -**Không nhận: tính năng mới.** Issue hoặc pull request đề xuất tính năng sẽ được gắn nhãn -`enhancement` + `out-of-scope` và tự động đóng -([`.github/workflows/triage.yml`](.github/workflows/triage.yml)). Nếu bị đóng nhầm, hãy trả lời ngay -trong đó — chủ repo sẽ xem lại; ngoại lệ được chấp nhận mang nhãn `maintenance-exception`. Ý tưởng -vẫn có thể trao đổi trong [Discussions](https://github.com/poli0981/poli0981-dev/discussions), không -cam kết sẽ làm. +**Không nhận: tính năng mới.** Issue hoặc merge request đề xuất tính năng sẽ được gắn nhãn +`enhancement` + `out-of-scope` và đóng lại. Nếu bị đóng nhầm, hãy trả lời ngay trong đó — chủ repo +sẽ xem lại; ngoại lệ được chấp nhận mang nhãn `maintenance-exception`. Ý tưởng vẫn có thể gửi qua +e-mail `code@poli0981.dev`, không cam kết sẽ làm. ### Báo lỗi ở đâu -- **Lỗi trên trang web**: nút "Báo lỗi" ngay trên trang, hoặc form báo lỗi trong - [Issues](https://github.com/poli0981/poli0981-dev/issues/new/choose). -- **Rào cản accessibility**: form accessibility trong Issues. -- **Lỗi chính tả, câu chữ**: form ngôn ngữ trong Issues. -- **Lỗ hổng bảo mật**: báo riêng — xem [SECURITY.md](SECURITY.md). Không mở issue công khai. +- **Lỗi trên trang web**: nút "Báo lỗi" ngay trên trang (không cần tài khoản), hoặc + [mẫu Bug](https://gitlab.com/poli0981/poli0981-dev/-/issues/new?issuable_template=Bug) trên bản + sao GitLab. +- **Rào cản accessibility**: + [mẫu Accessibility](https://gitlab.com/poli0981/poli0981-dev/-/issues/new?issuable_template=Accessibility), + hoặc `accessibility@poli0981.dev`. +- **Lỗi chính tả, câu chữ**: + [mẫu Language](https://gitlab.com/poli0981/poli0981-dev/-/issues/new?issuable_template=Language). +- **Lỗ hổng bảo mật**: chỉ qua e-mail — xem [SECURITY.md](SECURITY.md). Không mở issue công khai + trên bản sao. -### Pull request +### Merge request và patch -Hoan nghênh cho năm loại thay đổi ở trên. Mỗi pull request một thay đổi, làm theo các mục kiểm tra -trong [mẫu pull request](.github/pull_request_template.md), chạy các lệnh trong -[README.md](README.md#commands) trước khi mở. CI phải xanh — `build` là bắt buộc, cổng SonarCloud -và Qodana cũng phải qua. Commit trên `main` có chữ ký. +Hoan nghênh cho năm loại thay đổi ở trên. Mỗi merge request (hoặc chuỗi patch) một thay đổi, làm +theo các mục kiểm tra trong mẫu merge request, chạy các lệnh trong [README.md](README.md#commands) +trước khi gửi. CI trên Gitea phải xanh trước khi chủ repo merge — `build` là bắt buộc, Qodana và các +kiểm tra bảo mật cũng phải qua. Commit trên `main` có chữ ký. diff --git a/README.md b/README.md index fd105b4..233f1eb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # poli0981.dev -[![CI](https://github.com/poli0981/poli0981-dev/actions/workflows/ci.yml/badge.svg)](https://github.com/poli0981/poli0981-dev/actions/workflows/ci.yml) -[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=poli0981_poli0981-dev&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=poli0981_poli0981-dev) -[![Qodana](https://github.com/poli0981/poli0981-dev/actions/workflows/qodana.yml/badge.svg)](https://github.com/poli0981/poli0981-dev/actions/workflows/qodana.yml) +[![CI](https://git.poli0981.dev/poli0981/poli0981-dev/actions/workflows/ci.yml/badge.svg?branch=main)](https://git.poli0981.dev/poli0981/poli0981-dev/actions?workflow=ci.yml) +[![Qodana](https://git.poli0981.dev/poli0981/poli0981-dev/actions/workflows/qodana.yml/badge.svg?branch=main)](https://git.poli0981.dev/poli0981/poli0981-dev/actions?workflow=qodana.yml) +[![Security](https://git.poli0981.dev/poli0981/poli0981-dev/actions/workflows/security.yml/badge.svg?branch=main)](https://git.poli0981.dev/poli0981/poli0981-dev/actions?workflow=security.yml) [![License: GPL-3.0](https://img.shields.io/badge/code-GPL--3.0-blue)](LICENSE) [![Status: maintenance mode](https://img.shields.io/badge/status-maintenance%20mode-orange)](CONTRIBUTING.md#maintenance-mode) @@ -17,8 +17,15 @@ the SkullMute channel, in Vietnamese and English. Live at **[poli0981.dev](https **Maintenance mode since v2.3.0 (November 2026).** The site is complete. It still gets dependency updates, security fixes (High/Critical advisories, runtime vulnerabilities), major runtime and framework upgrades, bug fixes (UI/UX and accessibility included) and language fixes, -but no new features. Issues and pull requests asking for one are closed automatically. Details: -[`CONTRIBUTING.md`](CONTRIBUTING.md). +but no new features; requests for one are closed. Details: [`CONTRIBUTING.md`](CONTRIBUTING.md). + +## Where things live + +Source: [`git.poli0981.dev/poli0981/poli0981-dev`](https://git.poli0981.dev/poli0981/poli0981-dev) +(canonical, on the owner's Gitea since November 2026; the GitHub repository is gone). Mirror for +issues and merge requests: [`gitlab.com/poli0981/poli0981-dev`](https://gitlab.com/poli0981/poli0981-dev). +Patches and questions: `code@poli0981.dev`. Security: `security@poli0981.dev` (see +[`SECURITY.md`](SECURITY.md)). > **Trạng thái:** chế độ bảo trì từ v2.3.0 — chỉ cập nhật dependency, vá bảo mật, nâng cấp > runtime/framework, sửa lỗi (cả UI/UX, accessibility) và sửa lỗi ngôn ngữ; không thêm tính năng mới. @@ -30,10 +37,11 @@ but no new features. Issues and pull requests asking for one are closed automati | Framework | [Astro 7](https://astro.build) (static-first) with Svelte 5 islands | | Styling | Tailwind CSS 4, design tokens in `src/styles/global.css` ("Glacier Teal" palette) | | Hosting | Cloudflare Workers + Static Assets; KV, R2, Images, Rate Limiting, Access, Turnstile | -| Content | Markdown/MDX in [`poli0981/content`](https://github.com/poli0981/content) (git submodule `src/content`) | +| Content | Markdown/MDX in [`poli0981/content`](https://git.poli0981.dev/poli0981/content) (git submodule `src/content`) | | Search | Pagefind (built after `astro build`) | | Tooling | Node 26 · TypeScript 7 (`tsc`) next to TypeScript 6 (astro check, typescript-eslint) · `node:test` · ESLint · Prettier · knip | -| Quality | SonarCloud quality gate · Qodana · CodeQL · OSV-Scanner · Snyk · Dependabot (3-day cooldown) · axe-core gate · licence check | +| Quality | Qodana · gitleaks · Opengrep · OSV-Scanner · Renovate (3-day wait) · axe-core gate · licence check | +| CI | Gitea Actions (`.gitea/workflows`); `main` deploys with Wrangler from CI | ## How it fits together @@ -43,7 +51,7 @@ visitor ─▶ Cloudflare edge ─▶ src/worker.ts (every request, pages includ Turnstile gate (48-hour pass) · static pages from ASSETS · the rest → Astro app ├─ /api/report, /api/gate, /api/widgets, /api/health └─ admin.poli0981.dev (Cloudflare Access + JWT check) -workers/widgets (cron, every 45 min) ─▶ YouTube / Steam / GitHub ─▶ KV (data + mirrored images) +workers/widgets (cron, every 45 min) ─▶ YouTube / Steam / Gitea ─▶ KV (data + mirrored images) ``` Almost every page is prerendered. The Worker entry runs first for every route so the bot gate, @@ -55,7 +63,7 @@ the denylist and the security headers also cover static pages. Details: Requirements: Node 26 (`.nvmrc`) and npm 11. The content submodule is public, so a plain clone works. ```bash -git clone --recurse-submodules https://github.com/poli0981/poli0981-dev.git +git clone --recurse-submodules https://git.poli0981.dev/poli0981/poli0981-dev.git cd poli0981-dev npm ci --ignore-scripts && npm run check-install-scripts npx lefthook install @@ -64,7 +72,7 @@ npm run dev ``` `npm run dev` runs Astro on workerd with local bindings. The admin works locally with a stand-in -identity (`dev@localhost`); saving content needs a `GITHUB_CONTENT_TOKEN` in `.dev.vars`. +identity (`dev@localhost`); saving content needs a Gitea token as `GITEA_BOT_TOKEN` in `.dev.vars`. ## Commands @@ -86,10 +94,13 @@ identity (`dev@localhost`); saving content needs a `GITHUB_CONTENT_TOKEN` in `.d ## Deploying -Cloudflare **Workers Builds** builds every push: `main` runs `npx wrangler deploy`, any other -branch only `npx wrangler versions upload` (a preview version that takes no traffic). After a -merge, `https://poli0981.dev/api/health` reports the running version and commit. The widgets -worker deploys by hand: `npx wrangler deploy --config workers/widgets/wrangler.jsonc`. +CI deploys `main`: after `build` passes on a push to `main`, the `deploy` job in +[`.gitea/workflows/ci.yml`](.gitea/workflows/ci.yml) rebuilds with the production settings, runs +`npx wrangler deploy` and waits until `https://poli0981.dev/api/health` reports that commit. Pull +requests get no preview versions. The runner lives on the owner's PC, so a merge made while it is +off deploys when it comes back. (Cloudflare Workers Builds did this until it went with the GitHub +repository in November 2026.) The widgets worker deploys by hand: +`npx wrangler deploy --config workers/widgets/wrangler.jsonc`. Setup from scratch: [`07_CLOUDFLARE_SETUP.md`](poli0981.dev-docs/07_CLOUDFLARE_SETUP.md); pipeline: [`08_CI_CD.md`](poli0981.dev-docs/08_CI_CD.md); changes per release: [`CHANGELOG.md`](CHANGELOG.md). @@ -105,8 +116,9 @@ JWT (≤ 24 hours old) and an email allowlist on every request. ## Security -Please report vulnerabilities privately — see [`SECURITY.md`](SECURITY.md). Bug reports from the -site's "Report a bug" button land in a private repository, not in this one's issues. +Please report vulnerabilities privately, by e-mail — see [`SECURITY.md`](SECURITY.md). Bug +reports from the site's "Report a bug" button become confidential issues on the GitLab mirror, +visible only to the maintainer. ## Accessibility diff --git a/SECURITY.md b/SECURITY.md index abc9033..5120235 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -3,7 +3,10 @@ ## Reporting a vulnerability Email **security@poli0981.dev**. Please include steps to reproduce and the affected URL. -Do not open a public issue for a security problem. +E-mail is the only channel: the repository lives on a self-hosted Gitea with no private +reporting (GitHub's went with the old repository), and issues on the GitLab mirror are public. +**Do not open a public issue on the mirror for a security problem.** One opened there by +mistake is made confidential and continued by e-mail. Expect an acknowledgement within 7 days. This is a personal site maintained by one person, in their spare time — there is no bug bounty and no payout. @@ -23,7 +26,7 @@ Machine-readable contact: (RFC 9 **Out of scope** -- Findings that require an already-compromised Cloudflare, GitHub or Access identity +- Findings that require an already-compromised Cloudflare, Gitea, GitLab or Access identity - Attacks on Cloudflare Access's own login flow (report those to Cloudflare) - Volumetric denial of service - Missing hardening headers with no demonstrated impact @@ -51,7 +54,8 @@ Useful context when judging impact — the site is static and stores almost noth check on age-rated pages (an age threshold, never a birth date), stay in the browser's `localStorage` and are never sent to the site. - User-submitted input: the bug-report form (Turnstile-gated, schema-validated, size-capped, - forwarded to an issue in a **private** repository and a Discord webhook) and the bot-check + forwarded as a **confidential** issue on the GitLab mirror, visible only to the maintainer, + and to a Discord webhook) and the bot-check token exchange at `/api/gate`. Both are rate-limited per client. - IP addresses are used transiently for rate limiting and the IP denylist; they are not stored with reports. Workers Logs keep request logs for 7 days. diff --git a/THIRD-PARTY-NOTICES.md b/THIRD-PARTY-NOTICES.md index bdca042..49108ab 100644 --- a/THIRD-PARTY-NOTICES.md +++ b/THIRD-PARTY-NOTICES.md @@ -105,13 +105,14 @@ Not packages — listed for transparency: Images (one-time AVIF/WebP transforms), Rate Limiting, Turnstile (bot gate and bug-report form), Access (the admin), Web Analytics (cookieless page views, production builds only) and Workers Logs. -- **GitHub** — source code, the content repository, Actions CI, and issues in a private - repository for site bug reports. +- **Gitea** (self-hosted at git.poli0981.dev) — source code, the content repository and CI + (Gitea Actions, on the maintainer's own runner). +- **GitLab** — the public mirror of the repository, and confidential issues for site bug reports. - **Discord** — a webhook receiving bug-report notifications. -- **YouTube, Steam and GitHub public APIs** — read by the widgets cron worker; visitors' browsers +- **YouTube, Steam and Gitea public APIs** — read by the widgets cron worker; visitors' browsers never call them (images are mirrored and served from the site). -- **SonarCloud, Qodana (JetBrains), CodeQL, OSV-Scanner, Snyk** — code and dependency analysis in - CI; nothing they do reaches the running site. +- **Qodana (JetBrains), gitleaks, Opengrep, OSV-Scanner, Renovate** — code and dependency + analysis and updates in CI; nothing they do reaches the running site. ## Fonts diff --git a/astro.config.mjs b/astro.config.mjs index 0956632..c55be1c 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -61,15 +61,16 @@ const localizedNotFound = { }, }; -// Cloudflare Web Analytics beacon: only in builds made by Workers Builds for main -// (WORKERS_CI / WORKERS_CI_BRANCH are injected there), so CI, Lighthouse and branch -// previews never report page views. Overridable with PUBLIC_CF_BEACON=true|false. +// Cloudflare Web Analytics beacon: only in production builds, so CI, Lighthouse and local +// builds never report page views. The deploy job in .gitea/workflows/ci.yml sets +// PUBLIC_CF_BEACON=true; a Workers Builds build of main (WORKERS_CI / WORKERS_CI_BRANCH, +// before the move to Gitea) turns it on by itself. const CF_BEACON_DEFAULT = process.env.WORKERS_CI === "1" && process.env.WORKERS_CI_BRANCH === "main"; -// The commit a build was made from (Workers Builds sets WORKERS_CI_COMMIT_SHA, GitHub Actions -// GITHUB_SHA). /api/health reports it next to the Worker version id (src/lib/version.ts), so -// "what is live?" maps straight to a commit. +// The commit a build was made from (Gitea Actions sets GITHUB_SHA, as GitHub Actions did; +// Workers Builds set WORKERS_CI_COMMIT_SHA). /api/health reports it next to the Worker version +// id (src/lib/version.ts), so "what is live?" maps straight to a commit. const BUILD_COMMIT = process.env.WORKERS_CI_COMMIT_SHA ?? process.env.GITHUB_SHA ?? null; // The poli0981/content commit this build's src/content points at: the gitlink recorded in @@ -123,8 +124,9 @@ export default defineConfig({ }, // Bug-report pipeline env (docs 10). All optional so the site builds + degrades - // gracefully until the owner provisions them (Turnstile keys, a fine-grained GitHub - // Issues token, and a Discord webhook). The client site key is public + inlined. + // gracefully until the owner provisions them (Turnstile keys, a GitLab token that may + // open issues on the mirror, and a Discord webhook). The client site key is public + + // inlined. env: { schema: { PUBLIC_TURNSTILE_SITE_KEY: envField.string({ @@ -133,17 +135,12 @@ export default defineConfig({ optional: true, }), TURNSTILE_SECRET: envField.string({ context: "server", access: "secret", optional: true }), - GITHUB_ISSUES_TOKEN: envField.string({ context: "server", access: "secret", optional: true }), + GITLAB_ISSUES_TOKEN: envField.string({ context: "server", access: "secret", optional: true }), DISCORD_WEBHOOK_BUG: envField.string({ context: "server", access: "secret", optional: true }), - // Admin (admin.poli0981.dev), two fine-grained tokens (src/lib/admin/github.ts): - // content repo Contents RW, and site repo Actions RW for the publish workflow; - // plus the email allowlist on top of Access (unset = the admin refuses everyone). - GITHUB_CONTENT_TOKEN: envField.string({ - context: "server", - access: "secret", - optional: true, - }), - GITHUB_PUBLISH_TOKEN: envField.string({ + // Admin (admin.poli0981.dev): the Gitea token of the bot user poli0981-bot, a Write + // collaborator on the content and site repos (src/lib/admin/gitea.ts); plus the email + // allowlist on top of Access (unset = the admin refuses everyone). + GITEA_BOT_TOKEN: envField.string({ context: "server", access: "secret", optional: true, diff --git a/lighthouserc.json b/lighthouserc.json index 5de07d6..8ea1938 100644 --- a/lighthouserc.json +++ b/lighthouserc.json @@ -3,7 +3,8 @@ "collect": { "numberOfRuns": 3, "settings": { - "throttlingMethod": "simulate" + "throttlingMethod": "simulate", + "chromeFlags": "--no-sandbox" } }, "assert": { diff --git a/poli0981.dev-docs/00_INDEX.md b/poli0981.dev-docs/00_INDEX.md index cfd10a1..2b5f1b3 100644 --- a/poli0981.dev-docs/00_INDEX.md +++ b/poli0981.dev-docs/00_INDEX.md @@ -1,7 +1,7 @@ # poli0981.dev — Documentation Suite - Phiên bản suite: **v2.0** · Ngày: 2026-10-24 (v1.0: 2026-07-17) -- Repo: `poli0981/poli0981-dev` (**public** từ 10/2026) · nội dung: `poli0981/content` (submodule `src/content`) · Domain: `poli0981.dev` +- Repo: `poli0981/poli0981-dev` (**public** từ 10/2026; từ 2026-11-24 trên Gitea tự host `https://git.poli0981.dev/poli0981/poli0981-dev`, mirror công khai nhận issue/MR `https://gitlab.com/poli0981/poli0981-dev` — `08` §0) · nội dung: `poli0981/content` (submodule `src/content`, cũng trên Gitea) · Domain: `poli0981.dev` - Lịch sử thay đổi theo phiên bản: `CHANGELOG.md` ở gốc repo. - Ngôn ngữ tài liệu: tiếng Việt (thuật ngữ kỹ thuật giữ tiếng Anh). Riêng `12_LEGAL/` soạn song ngữ EN/VI vì là văn bản sẽ render trên site. - Tài liệu gốc: `poli0981.dev_proposal.md` (bản đề xuất v0.1, đã được duyệt). @@ -18,10 +18,10 @@ | 05 | 05_SITEMAP_UX.md | Route map, wireframe từng trang, legal gate, mobile nav | | 06 | 06_SECURITY.md | Headers/CSP, form, rate limit, secrets, supply chain | | 07 | 07_CLOUDFLARE_SETUP.md | **Hướng dẫn set Cloudflare từng bước** | -| 08 | 08_CI_CD.md | Workflows, permissions, deploy, Dependabot, hooks | +| 08 | 08_CI_CD.md | Forge & CI (Gitea), workflows, deploy, Renovate, hooks | | 09 | 09_ERROR_PAGES_OFFLINE.md | 404/403/429/5xx/offline + cách test | -| 10 | 10_BUG_REPORT_PIPELINE.md | Console capture → GitHub Issue + Discord | -| 11 | 11_WIDGETS_INTEGRATIONS.md | YouTube/Steam/GitHub widgets, cron worker, KV | +| 10 | 10_BUG_REPORT_PIPELINE.md | Console capture → issue confidential trên GitLab + Discord | +| 11 | 11_WIDGETS_INTEGRATIONS.md | YouTube/Steam/Gitea widgets, cron worker, KV | | 12 | 12_LEGAL/ | 5 văn bản song ngữ (xem dưới) | | 13 | 13_SEO_RSS_OG.md | Meta, hreflang, sitemap, RSS, OG image, AI crawlers | | 14 | 14_PERF_BUDGET.md | Ngân sách hiệu năng + kỷ luật islands | @@ -31,34 +31,35 @@ `12_LEGAL/`: `TERMS_OF_USE.md` · `PRIVACY_POLICY.md` · `DISCLAIMER.md` · `THIRD_PARTY_NOTICES.md` · `CONTENT_LICENSE.md` — **bản nháp gốc** (07/2026). Văn bản đang hiệu lực là `legal/*.md` trong repo `poli0981/content` (render ở `/legal/*`); sửa ở đó, không sửa ở đây. Hai trang thêm sau (`ai-usage`, `accessibility`) chỉ có ở repo content, không có bản nháp tại đây. -## Nhật ký quyết định (chốt 2026-07-17, cập nhật 2026-11-10) +## Nhật ký quyết định (chốt 2026-07-17, cập nhật 2026-11-24) | # | Quyết định | Chọn | |---|---|---| | D1 | Framework/hosting | Astro 7 + Svelte 5 islands, Cloudflare Workers + Static Assets | -| D2 | Quy trình viết | Markdown + Git (repo `poli0981/content`). Từ 10/2026 thêm **admin tự viết** ở `admin.poli0981.dev` (soạn/sửa → commit repo content; **Xuất bản** → workflow `content-bump.yml` mở PR bump submodule + auto-merge). Không Keystatic/CMS bên thứ ba | +| D2 | Quy trình viết | Markdown + Git (repo `poli0981/content`). Từ 10/2026 thêm **admin tự viết** ở `admin.poli0981.dev` (soạn/sửa → commit repo content; **Xuất bản** → workflow `content-bump.yml` mở PR bump submodule + auto-merge; từ 2026-11-24 việc merge do job `publish` của CI làm, `08` §0b). Không Keystatic/CMS bên thứ ba | | D3 | Q&A | FAQ tĩnh + liên hệ qua social/`contact@` — **không form, không D1** | | D4 | Ngôn ngữ | VI (mặc định, không prefix) + EN (`/en/`) | | D5 | Bình luận blog | Tắt (không Giscus) | | D6 | Legal canonical | Trên site tại `/legal/*`; repo public mirror `poli0981/legal` = tuỳ chọn sau | | D7 | Giấy phép | Code GPL-3.0 · Nội dung All Rights Reserved | | D8 | Error pages | Tự phục vụ từ app (không mua zone Pro) | -| D9 | API ngoài | Không weather/map; widget YouTube + Steam + GitHub qua cron worker | +| D9 | API ngoài | Không weather/map; widget YouTube + Steam + GitHub qua cron worker (GitHub đến 2026-11-23; nay feed công khai của Gitea — D25) | | D11 | Email | Google Workspace (MX Google), một hộp thư + alias theo chủ đề (`07` §11). Không Cloudflare Email Routing | | D12 | Chống bot | **Cổng Turnstile** trước mọi trang, vé 48 giờ (`06` §3b); bot đã xác thực đi thẳng nhờ Transform Rule `x-verified-bot` | | D13 | Rate limit | WAF rule (edge) → Workers Rate Limiting: RL_SITE toàn site 100/10s → bindings theo nhóm `/api` (`06` §2, `07` §6) thay bộ đếm KV | | D14 | Analytics | Cloudflare Web Analytics, **snippet thủ công** chỉ ở bản build production (`07` §12) | -| D15 | Admin | `admin.poli0981.dev` sau Cloudflare Access + Worker tự kiểm JWT (≤ 24 giờ, email phải có trong `ADMIN_EMAILS` — thiếu là từ chối); token GitHub chỉ ghi repo content; ảnh → Images binding → R2; mọi thao tác ghi audit log (`06` §9) | +| D15 | Admin | `admin.poli0981.dev` sau Cloudflare Access + Worker tự kiểm JWT (≤ 24 giờ, email phải có trong `ADMIN_EMAILS` — thiếu là từ chối); token GitHub chỉ ghi repo content (đến 2026-11-23; nay một token bot Gitea `GITEA_BOT_TOKEN`, `06` §9); ảnh → Images binding → R2; mọi thao tác ghi audit log (`06` §9) | | D10 | Data services | **KV** (cache widget + ảnh widget mirror cho `/ext-img`, denylist một khoá, audit log admin) + **R2** `poli0981-media` cho ảnh upload qua admin (từ 10/2026; AVIF/WebP sinh một lần lúc upload, phục vụ qua `/media`, cache 1 năm). Không D1. Ảnh build-time cũ vẫn ở `src/assets/` | | D16 | Palette & theme (10/2026) | **Glacier Teal** (xanh đêm + teal) thay palette ấm; theme mặc định **theo hệ điều hành**, nút 3 trạng thái hệ thống/sáng/tối (`03` §2, §6) | -| D17 | Toolchain (10/2026) | Node 26 · TypeScript 7 (`tsc` kiểm kiểu) chạy song song TypeScript 6 (astro check, typescript-eslint, svelte2tsx cần JS API) · test bằng `node:test` (không thêm deps) · SonarCloud phân tích qua CI (`08` §0) | -| D18 | Báo lỗi (10/2026) | Issue tạo ở repo **private** `poli0981/site-reports` (repo site đã public) — `10` §4 | -| D19 | Phát hành | Tag `vX.Y.Z` có ký GPG + GitHub Release + `CHANGELOG.md`; deploy vẫn là "merge `main`" (`08` §8) | -| D20 | Trợ năng (11/2026, v2.2.0) | Mục tiêu **WCAG 2.2 AA** — kim chỉ nam, không tự nhận đã được kiểm định. Tuyên bố cho khách ở `/legal/accessibility` (song ngữ, repo content); `ACCESSIBILITY.md` ở root là bản của repo kèm ghi chú cho người sửa code (trang site thắng nếu lệch). Rào cản báo về `accessibility@` hoặc nút "Báo lỗi". Cổng tự động: `npm run test:a11y` (axe-core + bàn phím + reflow + forced-colors, Playwright lái Chrome có sẵn) chạy trong check bắt buộc `build` (`08` §0, checklist ở `03` §8) — ngoại lệ có chủ đích của D17 "không thêm deps cho test" | -| D21 | Chế độ bảo trì (11/2026, v2.3.0) | Không thêm tính năng mới. Chỉ nhận: deps định kỳ · vá bảo mật (High/Critical, lỗ hổng runtime) · nâng cấp lớn ngôn ngữ/runtime/framework · sửa lỗi (UI/UX, a11y) · sửa lỗi ngôn ngữ. Bot `triage.yml` gắn `enhancement` + `out-of-scope` và đóng đề xuất tính năng; ngoại lệ = nhãn `maintenance-exception` (`CONTRIBUTING.md`, `17` §0) | +| D17 | Toolchain (10/2026) | Node 26 · TypeScript 7 (`tsc` kiểm kiểu) chạy song song TypeScript 6 (astro check, typescript-eslint, svelte2tsx cần JS API) · test bằng `node:test` (không thêm deps) · SonarCloud phân tích qua CI (`08` §0b; bỏ 2026-11-24 — Qodana + Opengrep thay, D25) | +| D18 | Báo lỗi (10/2026) | Issue tạo ở repo **private** `poli0981/site-reports` (repo site đã public) — đến 2026-11-23; nay issue **confidential** trên mirror GitLab `poli0981/poli0981-dev` (D25) — `10` §4 | +| D19 | Phát hành | Tag `vX.Y.Z` có ký GPG + GitHub Release (từ v2.4.0: Gitea Release) + `CHANGELOG.md`; deploy vẫn là "merge `main`" (`08` §8) | +| D20 | Trợ năng (11/2026, v2.2.0) | Mục tiêu **WCAG 2.2 AA** — kim chỉ nam, không tự nhận đã được kiểm định. Tuyên bố cho khách ở `/legal/accessibility` (song ngữ, repo content); `ACCESSIBILITY.md` ở root là bản của repo kèm ghi chú cho người sửa code (trang site thắng nếu lệch). Rào cản báo về `accessibility@` hoặc nút "Báo lỗi". Cổng tự động: `npm run test:a11y` (axe-core + bàn phím + reflow + forced-colors, Playwright lái Chrome có sẵn — trên runner Gitea là Chromium của Playwright, `08` §0b) chạy trong check bắt buộc `build` (`08` §0, checklist ở `03` §8) — ngoại lệ có chủ đích của D17 "không thêm deps cho test" | +| D21 | Chế độ bảo trì (11/2026, v2.3.0) | Không thêm tính năng mới. Chỉ nhận: deps định kỳ · vá bảo mật (High/Critical, lỗ hổng runtime) · nâng cấp lớn ngôn ngữ/runtime/framework · sửa lỗi (UI/UX, a11y) · sửa lỗi ngôn ngữ. Bot `triage.yml` gắn `enhancement` + `out-of-scope` và đóng đề xuất tính năng (đến 2026-11-23; nay chủ repo đóng tay trên mirror GitLab — D25); ngoại lệ = nhãn `maintenance-exception` (`CONTRIBUTING.md`, `17` §0) | | D22 | Nhãn nội dung & tuổi (11/2026) | `contentWarning` từ danh sách cố định 11 nhãn (`src/lib/content-labels.ts`) cho blog/truyện/album/từng ảnh + `ageRating` 13+/16+/18+. Banner; ảnh mờ bằng CSS (`:has()`, chạy khi tắt JS); hỏi tuổi bằng `` gốc, không tự bật, câu trả lời chỉ ở localStorage `ageGate` (mốc tuổi, không ngày sinh) — Privacy §6 (`04` §2) | -| D23 | Xuất bản tự động (11/2026) | Mỗi lần lưu/xoá trong admin tự dispatch `content-bump.yml`; build ghi `__CONTENT_COMMIT__` ⇒ `/api/health` có `version.content`, admin phân biệt "đã merge" với "đã lên web". Điều kiện: Workers Builds deploy `main` (`07` §9) | -| D24 | Chất lượng (11/2026) | Thêm **Qodana** (Ultimate, Qodana for JS, ngưỡng 0) cạnh SonarCloud. License: kiểm toàn bộ `package-lock.json`, ngoại lệ theo **gói** có lý do (`scripts/license-policy.mjs`) — license audit của Qodana cần Ultimate Plus nên không dùng (`08` §0) | +| D23 | Xuất bản tự động (11/2026) | Mỗi lần lưu/xoá trong admin tự dispatch `content-bump.yml`; build ghi `__CONTENT_COMMIT__` ⇒ `/api/health` có `version.content`, admin phân biệt "đã merge" với "đã lên web". Điều kiện: Workers Builds deploy `main` (`07` §9) — đến 2026-11-23; nay job `deploy` của Gitea CI (D25) | +| D24 | Chất lượng (11/2026) | Thêm **Qodana** (Ultimate, Qodana for JS, ngưỡng 0) cạnh SonarCloud (SonarCloud bỏ 2026-11-24, D25). License: kiểm toàn bộ `package-lock.json`, ngoại lệ theo **gói** có lý do (`scripts/license-policy.mjs`) — license audit của Qodana cần Ultimate Plus nên không dùng (`08` §0) | +| D25 | Chuyển sang Gitea (11/2026, chốt 2026-11-24, v2.4.0) | Tài khoản GitHub `poli0981` không còn ⇒ repo site + `content` sống trên Gitea tự host `git.poli0981.dev` (bản gốc); mirror công khai `gitlab.com/poli0981/poli0981-dev` nhận issue/MR (người ngoài không đăng ký được Gitea; patch/câu hỏi `code@`, bảo mật chỉ `security@`). CI = Gitea Actions (`.gitea/workflows/`, runner trên PC chủ repo, job lịch chỉ 13:00–16:00 UTC); deploy = job `deploy` của `ci.yml` (`wrangler deploy`) thay Workers Builds, không còn preview cho PR; check bắt buộc `CI / build (*)`. Bỏ SonarCloud, CodeQL/Snyk, `triage.yml`, Dependabot ⇒ Qodana + `security.yml` (gitleaks/Opengrep/osv-scanner) + Renovate tự host. Admin: một token bot `GITEA_BOT_TOKEN`; báo lỗi: issue confidential trên GitLab; widget hoạt động: feed Gitea không token. Runbook: repo `poli0981/.github`, `docs/GITEA-MIGRATION.md` (`08` §0) | ## Cách dùng suite diff --git a/poli0981.dev-docs/01_PRD.md b/poli0981.dev-docs/01_PRD.md index c366ae2..e9c4a12 100644 --- a/poli0981.dev-docs/01_PRD.md +++ b/poli0981.dev-docs/01_PRD.md @@ -6,7 +6,7 @@ Website cá nhân `poli0981.dev` cho Kokone: **portfolio dev + blog kiêm nhật ## 2. Mục tiêu -1. Một địa chỉ duy nhất đại diện cả hai "mặt": developer (GitHub poli0981) và creator (SkullMute). +1. Một địa chỉ duy nhất đại diện cả hai "mặt": developer (poli0981 — GitHub đến 11/2026, nay Gitea `git.poli0981.dev/poli0981`) và creator (SkullMute). 2. Viết được **thoải mái và bền**: blog/nhật ký/truyện bằng Markdown, xuất bản bằng `git push` hoặc nút **Xuất bản** của admin tự viết — không phụ thuộc CMS bên thứ ba. 3. Đẹp có chủ đích ("Phòng đọc lúc nửa đêm"), không giống template, mobile hoàn chỉnh. 4. Vận hành ~US$12–13/năm phát sinh mới; không thêm dịch vụ trả phí nào khác. @@ -25,7 +25,7 @@ Website cá nhân `poli0981.dev` cho Kokone: **portfolio dev + blog kiêm nhật | Persona | Đến từ | Cần gì | |---|---|---| | Viewer của kênh | YouTube/Discord | Xem "người đứng sau kênh", video mới, đang chơi gì, FAQ, link social | -| Dev/recruiter/collab | GitHub, mail sponsor | Portfolio project, /uses, cách liên hệ đáng tin (`contact@poli0981.dev`) | +| Dev/recruiter/collab | Gitea/GitLab (trước 11/2026: GitHub), mail sponsor | Portfolio project, /uses, cách liên hệ đáng tin (`contact@poli0981.dev`) | | Độc giả truyện | Social/share link | Trải nghiệm đọc dài thoải mái trên điện thoại, theo dõi qua RSS | | Chính Kokone | — | Viết nhanh, đăng nhanh, không phải bảo trì nhiều | @@ -37,18 +37,18 @@ Website cá nhân `poli0981.dev` cho Kokone: **portfolio dev + blog kiêm nhật |---|---|---| | Trang chủ | Hero + signature Waveline, bài blog/truyện mới nhất, widget video mới + đang chơi gì | P1 (widget P2) | | /about | Song ngữ, 2 mặt dev/creator, ảnh đại diện, timeline ngắn | P1 | -| /projects | Card từ collection `projects`, filter theo tag, link GitHub/release | P1 | +| /projects | Card từ collection `projects`, filter theo tag, link repo (Gitea; trước 11/2026: GitHub)/release | P1 | | /blog | Index + trang bài, tag, reading time, RSS riêng | P1 | | /stories | Index theo series/status, **reader mode** riêng (font serif, chỉnh cỡ chữ, theme giấy, progress, prev/next chương, content-warning) | P1 | | /gallery | Album theo năm/sự kiện, lightbox, EXIF đã strip | P2 | | /gaming | Giới thiệu kênh, embed video (click-to-load, nocookie), thể loại yêu thích, widget Steam | P2 | | /dev (/uses) | PC specs, tool stack, setup OBS/Resolve | P2 | | /qa | FAQ tĩnh từ collection `faq` + khối "Liên hệ" trỏ /links và `contact@` | P1 | -| /links | Toàn bộ social (YouTube, Discord ×2, GitHub, Telegram, Bluesky, Mastodon, X, Facebook), icon + mô tả | P1 | +| /links | Toàn bộ social (YouTube, Discord ×2, Gitea (trước 11/2026: GitHub), Telegram, Bluesky, Mastodon, X, Facebook), icon + mô tả | P1 | | /legal/* | 7 trang song ngữ: 5 trang gốc từ `12_LEGAL/` + `ai-usage` + `accessibility` (tuyên bố trợ năng, 11/2026) | P1 | | Search | Pagefind, modal, lọc theo locale | P2 | | Error/offline | 404/403/429/500/offline custom | P1 (mini-game P3) | -| Bug report | Nút footer → GitHub Issue + Discord | P2 | +| Bug report | Nút footer → issue (GitHub đến 2026-11-23; nay issue confidential trên mirror GitLab) + Discord | P2 | | Legal gate | Bottom-sheet lần đầu truy cập | P1 | ## 6. Yêu cầu phi chức năng diff --git a/poli0981.dev-docs/02_ARCHITECTURE.md b/poli0981.dev-docs/02_ARCHITECTURE.md index 2c6fdca..bb857fd 100644 --- a/poli0981.dev-docs/02_ARCHITECTURE.md +++ b/poli0981.dev-docs/02_ARCHITECTURE.md @@ -2,7 +2,7 @@ ## 1. Tổng quan -Site **prerender tĩnh gần như toàn bộ** bằng Astro, deploy lên **Cloudflare Workers + Static Assets**. Một Worker chính (`poli0981-dev`) phục vụ site, admin và vài API route; một Worker phụ (`poli0981-widgets`) chạy cron lấy dữ liệu YouTube/Steam/GitHub vào KV. +Site **prerender tĩnh gần như toàn bộ** bằng Astro, deploy lên **Cloudflare Workers + Static Assets**. Một Worker chính (`poli0981-dev`) phục vụ site, admin và vài API route; một Worker phụ (`poli0981-widgets`) chạy cron lấy dữ liệu YouTube/Steam/Gitea vào KV. ``` Khách ──HTTPS──> Cloudflare edge (WAF free, Bot Fight, DDoS auto, Transform Rule x-verified-bot) @@ -20,11 +20,11 @@ Khách ──HTTPS──> Cloudflare edge (WAF free, Bot Fight, DDoS auto, Trans └── /api/*, /admin* → app Astro (@astrojs/cloudflare/handler) ├── middleware: admin (Access JWT + CSRF), rate limit /api, trang lỗi ├── /api/report · /api/gate · /api/widgets · /api/health - └── /admin/* + /api/admin/* (GitHub API → repo content, R2, Images, KV) + └── /admin/* + /api/admin/* (Gitea API → repo content, R2, Images, KV) ▲ đọc │ ghi KV (widgets:*, denylist, audit:*) ◄───┘ ▲ ghi - Worker "widgets" (cron 45') ──> YouTube RSS / Steam API / GitHub API (+ mirror ảnh) + Worker "widgets" (cron 45') ──> YouTube RSS / Steam API / feed Gitea (+ mirror ảnh) ``` Mọi response đi ra đều qua `withSecurityHeaders` (`src/lib/security-headers.ts`) và mang log JSON có cấu trúc (`src/lib/log.ts`: `event`, `ray`, `path`… — xem `06` §10). @@ -33,16 +33,16 @@ Mọi response đi ra đều qua `withSecurityHeaders` (`src/lib/security-header | Thành phần | Bản | Ghi chú | |---|---|---| -| Node.js | 26 (`.nvmrc` = `26`, Workers Builds `NODE_VERSION=26`) | engines: `>=26` | +| Node.js | 26 (`.nvmrc` = `26`, CI đọc `.nvmrc`; Workers Builds `NODE_VERSION=26` đến 2026-11) | engines: `>=26` | | Astro | ^7.4 | CSP API + Fonts API built-in | | @astrojs/cloudflare | ^14.4 | target Workers; entry riêng `src/worker.ts` | | @astrojs/mdx, sitemap, rss | ^8 · ^3 · ^4 | item RSS dựng ở `src/lib/rss.ts` (truyện chỉ mô tả + link) | | Svelte + @astrojs/svelte | 5 + ^9.1 | islands | | Tailwind CSS | ^4 | CSS-first, `@theme` | | Pagefind | ^1 | chạy post-build | -| Wrangler | ^4.152 | dev, types, smoke test, deploy tay | +| Wrangler | ^4.152 | dev, types, smoke test, deploy (job `deploy` của CI từ 2026-11-24; widgets deploy tay) | | TypeScript | **7.0** (`@typescript/native` → `tsc`) + **6.0** (`typescript`) | TS7 kiểm kiểu nhanh (`npm run typecheck`), TS6 cho astro check / typescript-eslint / svelte2tsx (TS 7.0 chưa có JS API). `target`/`lib` = ES2025, `erasableSyntaxOnly` | -| Test | `node:test` của Node 26 | không thêm deps; `module.registerHooks` giả lập `astro:*`/`cloudflare:workers`; coverage lcov cho SonarCloud | +| Test | `node:test` của Node 26 | không thêm deps; `module.registerHooks` giả lập `astro:*`/`cloudflare:workers`; coverage ≥ 80% dòng (lcov từng gửi SonarCloud, bỏ 2026-11-24) | | jose · marked · yaml · zod | ^6 · ^18 · ^2 · ^4 | Access JWT · preview admin · frontmatter · schema | ## 3. Cấu trúc repo @@ -53,7 +53,7 @@ poli0981-dev/ ├── docs/templates/ # khung bài mới (npm run new:post) ├── public/ # favicon, robots.txt, security.txt, sw.js, gate.js, skullhop.js ├── scripts/ # gen-og, gen-notices, check-exif/strip-exif, check-csp-hashes, -│ # check-install-scripts, smoke-worker, new-post +│ # check-install-scripts, smoke-worker, new-post, content-publish ├── src/ │ ├── worker.ts # entry: denylist, rate limit site, host, /media, /ext-img, cổng, assets │ ├── middleware.ts # admin JWT + CSRF, rate limit /api, trang lỗi @@ -67,10 +67,12 @@ poli0981-dev/ │ ├── lib/ # gate/, admin/, media/, denylist, ext-img, log, version, palette, theme… │ ├── pages/ # routes + /en/* + api/* + admin/* + 403/404/429/500 │ └── styles/ # global.css (token), prose.css, admin.css -├── tests/ # node:test + support/ (stub astro:*, fake KV/R2/GitHub…) · a11y/ (*.spec.ts: axe-core + bàn phím qua Playwright) +├── tests/ # node:test + support/ (stub astro:*, fake KV/R2/Gitea…) · a11y/ (*.spec.ts: axe-core + bàn phím qua Playwright) ├── workers/widgets/ # worker cron riêng (wrangler.jsonc riêng) -├── .github/ # ci.yml, content-bump.yml, lighthouse.yml, osv-scanner.yml, qodana.yml, triage.yml, dependabot.yml, ISSUE_TEMPLATE/ (config, bug_report, accessibility, language), pull_request_template.md -├── astro.config.mjs · wrangler.jsonc · sonar-project.properties · qodana.yaml · lefthook.yml · knip.json +├── .gitea/workflows/ # ci.yml (build · deploy · publish), content-bump.yml, security.yml, qodana.yml, lighthouse.yml (08 §0) +├── .github/ # ISSUE_TEMPLATE/ (config, bug_report, accessibility, language — Gitea đọc) + pull_request_template.md +├── .gitlab/ # issue_templates/ (Bug, Accessibility, Language) + merge_request_templates/Default.md — cho mirror GitLab +├── astro.config.mjs · wrangler.jsonc · renovate.json · qodana.yaml · lefthook.yml · knip.json └── LICENSE (GPL-3.0) · CONTENT-LICENSE.md · DISCLAIMER.md · THIRD-PARTY-NOTICES.md · SECURITY.md · ACCESSIBILITY.md · CONTRIBUTING.md · CHANGELOG.md ``` @@ -96,7 +98,7 @@ poli0981-dev/ "html_handling": "auto-trailing-slash", "run_worker_first": ["/*", "!/_astro/*", "…"] }, "kv_namespaces": [{ "binding": "KV", "id": "…" }], "ratelimits": [ RL_SITE 100/10s · RL_REPORT 5/60s · RL_GATE 30/60s · RL_ADMIN 120/60s · RL_API 120/60s ], - "vars": { "GATE_MODE": "on", "ACCESS_TEAM_DOMAIN": "…", "ACCESS_AUD": "…", "REPORT_REPO": "poli0981/site-reports" }, + "vars": { "GATE_MODE": "on", "ACCESS_TEAM_DOMAIN": "…", "ACCESS_AUD": "…", "REPORT_PROJECT": "poli0981/poli0981-dev" }, // project GitLab (10 §4) "r2_buckets": [{ "binding": "MEDIA", "bucket_name": "poli0981-media" }], "images": { "binding": "IMAGES" }, "version_metadata": { "binding": "CF_VERSION_METADATA" }, @@ -105,7 +107,7 @@ poli0981-dev/ } ``` -Secrets (đặt bằng `wrangler secret put`, không bao giờ commit — bảng đầy đủ ở `06` §4): `TURNSTILE_SECRET`, `GATE_SECRET`, `GITHUB_ISSUES_TOKEN`, `DISCORD_WEBHOOK_BUG`, `GITHUB_CONTENT_TOKEN`, `GITHUB_PUBLISH_TOKEN`, `ADMIN_EMAILS`. +Secrets (đặt bằng `wrangler secret put`, không bao giờ commit — bảng đầy đủ ở `06` §4): `TURNSTILE_SECRET`, `GATE_SECRET`, `GITLAB_ISSUES_TOKEN`, `DISCORD_WEBHOOK_BUG`, `GITEA_BOT_TOKEN`, `ADMIN_EMAILS` (từ 2026-11-24; trước đó `GITHUB_ISSUES_TOKEN`, `GITHUB_CONTENT_TOKEN`, `GITHUB_PUBLISH_TOKEN`). `/api/health` trả `version` (id bản Worker đang chạy + commit đã build, từ `version_metadata` và `__BUILD_COMMIT__`) — dùng để xác minh deploy từ bên ngoài. @@ -119,7 +121,7 @@ Secrets (đặt bằng `wrangler secret put`, không bao giờ commit — bảng ## 7. Setup máy dev (một lần) ```bash -git clone --recurse-submodules https://github.com/poli0981/poli0981-dev.git +git clone --recurse-submodules https://git.poli0981.dev/poli0981/poli0981-dev.git cd poli0981-dev nvm use # đọc .nvmrc = 26 npm ci --ignore-scripts && npm run check-install-scripts @@ -128,14 +130,14 @@ npm run types && npm run types:widgets npm run dev # astro dev trên workerd (bindings local); admin dùng danh tính giả dev@localhost ``` -Quy tắc gói bên thứ ba: chỉ thêm khi có lý do trong ADR/PR description; mỗi gói mới phải qua `npm audit` + Dependabot theo dõi; `THIRD-PARTY-NOTICES.md` sinh bằng `scripts/gen-notices.mjs` và CI kiểm lệch. +Quy tắc gói bên thứ ba: chỉ thêm khi có lý do trong ADR/PR description; mỗi gói mới phải qua `npm audit` + Renovate theo dõi; `THIRD-PARTY-NOTICES.md` sinh bằng `scripts/gen-notices.mjs` và CI kiểm lệch. ## 8. Chính sách phiên bản & CVE -- Pin `^` trong cùng major; Dependabot mở PR patch/minor hằng tuần (cooldown 3 ngày — `08` §6). -- Trước mỗi lần nâng **major**: đọc upgrade guide chính thức + chạy toàn bộ CI + preview (`17` §2). -- **TypeScript 7**: `@typescript/native` là alias `npm:typescript@7` — Dependabot bỏ qua alias `npm:`, nên nâng tay; `typescript` (bản 6) giữ đến khi TS 7.1 có JS API cho astro check / typescript-eslint / svelte2tsx, lúc đó gộp về một bản. -- Theo dõi CVE liên tục: Dependabot alerts, `npm audit` (CI), OSV-Scanner, Snyk, CodeQL, SonarCloud (`06` §6). +- Pin `^` trong cùng major; Renovate (tự host, chạy hằng ngày) gộp patch/minor vào một PR, chỉ đề xuất bản đã phát hành ≥ 3 ngày (`08` §6). Đến 2026-11-23: Dependabot hằng tuần, cooldown 3 ngày. +- Trước mỗi lần nâng **major**: đọc upgrade guide chính thức + chạy toàn bộ CI + thử local (`17` §2; từ 2026-11-24 không còn version preview cho PR). +- **TypeScript 7**: `@typescript/native` là alias `npm:typescript@7` — thời Dependabot (bỏ qua alias `npm:`) phải nâng tay; Renovate theo dõi nó như một dependency riêng, luật giữ `typescript` major không chặn nó. `typescript` (bản 6) giữ đến khi TS 7.1 có JS API cho astro check / typescript-eslint / svelte2tsx, lúc đó gộp về một bản. +- Theo dõi CVE liên tục: Renovate (cảnh báo OSV ⇒ PR nhãn `security`), `npm audit` (CI), `security.yml` (osv-scanner, Opengrep, gitleaks), Qodana (`06` §6). Đến 2026-11-23 còn Dependabot alerts, Snyk, CodeQL, SonarCloud. ## 9. ADR (Architecture Decision Records — rút gọn) @@ -144,11 +146,11 @@ Quy tắc gói bên thứ ba: chỉ thêm khi có lý do trong ADR/PR descriptio | 01 | Astro thay vì SvelteKit/Next | Content-first, ~0 JS mặc định, Content Collections type-safe, RSS/sitemap first-class | Site biến thành web-app nhiều tương tác | | 02 | Workers thay vì Pages | Hướng Cloudflare khuyến nghị cho dự án mới; assets request free; 1 nền tảng cho cả site + cron | — | | 03 | Svelte islands thay vì React | Nhẹ hơn, đã quen từ WXT/BookmarkMagic; tránh kéo React runtime vào site tĩnh | Cần lib chỉ có React | -| 04 | Admin tự viết thay vì Keystatic (10/2026) | Host riêng sau Access + kiểm JWT; token chỉ ghi repo content, xuất bản qua workflow có CI; ảnh qua Images binding → R2; ít deps (`jose`, `yaml`, `marked`) | Cần nhiều người biên tập / phân quyền | -| 05 | Không D1/Sentry | Q&A form bị bỏ; bug report đi thẳng GitHub+Discord; lỗi runtime xem ở Workers Logs (log JSON) | Xuất hiện nhu cầu dữ liệu động thật | +| 04 | Admin tự viết thay vì Keystatic (10/2026) | Host riêng sau Access + kiểm JWT; token chỉ ghi repo content, xuất bản qua workflow có CI (từ 2026-11-24 một token bot Gitea, `06` §9); ảnh qua Images binding → R2; ít deps (`jose`, `yaml`, `marked`) | Cần nhiều người biên tập / phân quyền | +| 05 | Không D1/Sentry | Q&A form bị bỏ; bug report đi thẳng issue + Discord (issue trên GitHub đến 2026-11-23; nay issue confidential trên GitLab, `10` §4); lỗi runtime xem ở Workers Logs (log JSON) | Xuất hiện nhu cầu dữ liệu động thật | | 06 | GPL-3.0 code / ARR content | Nhất quán hệ sinh thái repo; truyện & ảnh cần bảo hộ chặt | — | | 07 | Error pages tự phục vụ | Custom Errors của Cloudflare cần zone plan trả phí; site chạy trên Worker nên tự làm được | Nếu một ngày mua Pro vì lý do khác | | 08 | Logic edge ở worker entry (`src/worker.ts`) | Trang tĩnh được adapter phục vụ trước middleware ⇒ cổng Turnstile, denylist, `/media`, chuyển host, security headers phải nằm ở entry + `assets.run_worker_first` | Adapter có hook chính thức cho trang tĩnh | | 09 | TypeScript 7 song song TypeScript 6 (10/2026) | `tsc` 7 nhanh hơn nhiều cho kiểm kiểu; công cụ hệ sinh thái chưa chạy được trên TS 7.0 (không có JS API) | TS 7.1 có API mới | -| 10 | `node:test` + SonarCloud thay Vitest (10/2026) | Không thêm deps; Node 26 chạy thẳng TypeScript, `registerHooks` giả lập module ảo; lcov cho quality gate | Cần test component trong DOM thật | +| 10 | `node:test` + SonarCloud thay Vitest (10/2026) | Không thêm deps; Node 26 chạy thẳng TypeScript, `registerHooks` giả lập module ảo; lcov cho quality gate (SonarCloud bỏ 2026-11-24 khi chuyển Gitea; ngưỡng 80% dòng vẫn nằm trong `test:coverage`) | Cần test component trong DOM thật | | 11 | Palette Glacier Teal + theme theo hệ điều hành (10/2026) | Tông lạnh theo yêu cầu chủ site; mọi cặp màu kiểm WCAG AA bằng test; một nguồn màu `src/lib/palette.ts` | Đổi nhận diện | diff --git a/poli0981.dev-docs/03_DESIGN_SYSTEM.md b/poli0981.dev-docs/03_DESIGN_SYSTEM.md index af8e835..7e50604 100644 --- a/poli0981.dev-docs/03_DESIGN_SYSTEM.md +++ b/poli0981.dev-docs/03_DESIGN_SYSTEM.md @@ -122,7 +122,7 @@ Token `--scrollbar-thumb` / `--scrollbar-thumb-hover` / `--scrollbar-track` khai | MenuSheet | island | dialog modal, bẫy focus, trả focus về nút mở | | LegalGateSheet | island | spec ở `05` §6 | | Waveline | island | §5 | -| WidgetLatestVideo / WidgetNowPlaying / WidgetGitHub | .astro | đọc KV lúc request?—không: đọc lúc **build** + island refresh nhẹ (xem 11 §5) | +| WidgetLatestVideo / WidgetNowPlaying / WidgetGitea (trước 2026-11-24: WidgetGitHub) | .astro | đọc KV lúc request?—không: đọc lúc **build** + island refresh nhẹ (xem 11 §5) | | Callout, TagPill, Pagination | .astro | | ## 8. A11y & mobile checklist (áp cho mọi PR UI) diff --git a/poli0981.dev-docs/04_CONTENT_MODEL.md b/poli0981.dev-docs/04_CONTENT_MODEL.md index 716058b..266b895 100644 --- a/poli0981.dev-docs/04_CONTENT_MODEL.md +++ b/poli0981.dev-docs/04_CONTENT_MODEL.md @@ -102,16 +102,16 @@ tags: [horror, short-story] ## 5a. Viết qua admin (`admin.poli0981.dev`) -- **Nội dung**: danh sách theo collection → *Tạo mới* (loại, slug, ngôn ngữ; truyện cần slug bộ) hoặc sửa bài có sẵn. Form theo đúng schema (`src/lib/admin/collections.ts`), thân bài Markdown + *Xem trước*, *Chèn ảnh* (chèn `` từ thư viện), *Ảnh bìa* (`coverMedia`). **Lưu** = commit thẳng vào `poli0981/content` (`main`), giữ nguyên định dạng frontmatter phần không sửa; sửa song song trên GitHub ⇒ báo xung đột (409) thay vì ghi đè. +- **Nội dung**: danh sách theo collection → *Tạo mới* (loại, slug, ngôn ngữ; truyện cần slug bộ) hoặc sửa bài có sẵn. Form theo đúng schema (`src/lib/admin/collections.ts`), thân bài Markdown + *Xem trước*, *Chèn ảnh* (chèn `` từ thư viện), *Ảnh bìa* (`coverMedia`). **Lưu** = commit thẳng vào `poli0981/content` (`main`), giữ nguyên định dạng frontmatter phần không sửa; sửa song song (trên Gitea hay chỗ khác) ⇒ báo xung đột (409) thay vì ghi đè. Từ 2026-11-24 repo content nằm trên Gitea (`https://git.poli0981.dev/poli0981/content`), admin ghi qua token bot `GITEA_BOT_TOKEN` (`06` §9). - **Ảnh**: kéo-thả nhiều ảnh → nén một lần (AVIF/WebP, bỏ EXIF) → R2; sửa alt, copy snippet, xoá khi không còn bài nào dùng. - **Gallery**: tạo album (vi/en + `gallery-photos/.json` trong một commit), thêm/bớt/sắp xếp ảnh R2, chú thích vi/en bắt buộc. -- **Xuất bản**: nút trên thanh admin ⇒ workflow `content-bump.yml` (xem `08` §0); site cập nhật sau khi CI xanh và Workers Builds deploy (~5–8 phút). Bài mới tạo mặc định `draft: true` — bỏ tick để hiện trên site. -- Lưu ý: repo content **public** ⇒ bản nháp vẫn đọc được trên GitHub. +- **Xuất bản**: nút trên thanh admin ⇒ workflow `content-bump.yml` (xem `08` §0); site cập nhật sau khi CI xanh, job `publish` merge PR và job `deploy` deploy `main` (đến 2026-11-23: Workers Builds deploy; ~5–8 phút). Runner chạy trên PC của chủ repo ⇒ PC tắt thì xuất bản chờ tới khi runner lên lại. Bài mới tạo mặc định `draft: true` — bỏ tick để hiện trên site. +- Lưu ý: repo content **public** ⇒ bản nháp vẫn đọc được trên Gitea và mirror GitLab (đến 2026-11-23: GitHub). ## 5. Quy trình viết (quyết định D2 — Markdown + Git thuần) 1. **Ở PC**: tạo file trong VS Code/Obsidian (vault trỏ thẳng `src/content/`), viết với `draft: true`, xem bằng `npm run dev`. -2. **Capture từ điện thoại**: github.com → repo → thư mục collection → Add file → viết vài dòng + frontmatter tối thiểu + `draft: true` → commit thẳng `main` (draft không build ra site nên an toàn). +2. **Capture từ điện thoại**: `git.poli0981.dev` → repo `content` → thư mục collection → Add File → New File (đến 2026-11-23: github.com) → viết vài dòng + frontmatter tối thiểu + `draft: true` → commit thẳng `main` (draft không build ra site nên an toàn). 3. **Xuất bản**: bỏ `draft`, điền đủ frontmatter, chạy checklist §7, push → CI deploy. 4. Template sẵn: `docs/templates/{blog,story-chapter,project,faq}.md` — copy là viết. diff --git a/poli0981.dev-docs/05_SITEMAP_UX.md b/poli0981.dev-docs/05_SITEMAP_UX.md index 7b6e868..e3605da 100644 --- a/poli0981.dev-docs/05_SITEMAP_UX.md +++ b/poli0981.dev-docs/05_SITEMAP_UX.md @@ -51,11 +51,11 @@ ReadingControls: cỡ chữ S/M/L · nền Giấy/Sepia/Tối (độc lập them **Gaming**: hero kênh (banner + subscribe button link) → 3 video mới (YouTube RSS, thumbnail click-to-load nocookie) → "Đang chơi" (Steam) → khối "Mình cover gì": VN · JRPG · indie/psychological horror (kèm dòng: không FPS/competitive) → link Discord gaming server. Được phép scanline nhẹ (03 §4). -**Dev**: intro → grid project featured → /uses (bảng: PC specs i7-14700KF · RTX 5080 16GB · 32GB DDR5 · 2K 240Hz · Win 11 Pro; software: OBS, Resolve Studio, VS Code…) → hoạt động GitHub (widget). +**Dev**: intro → grid project featured → /uses (bảng: PC specs i7-14700KF · RTX 5080 16GB · 32GB DDR5 · 2K 240Hz · Win 11 Pro; software: OBS, Resolve Studio, VS Code…) → hoạt động Gitea (widget; trước 2026-11-24 là GitHub). **Q&A**: accordion theo group (Kênh/Dev/Cá nhân) → khối Liên hệ: "Nhanh nhất: Discord · Business: contact@poli0981.dev · Toàn bộ: /links". -**Links**: danh sách dọc lớn (icon + tên + mô tả 1 dòng + nút): YouTube, Discord gaming, Discord repo, GitHub, Telegram, Bluesky, Mastodon, X, Facebook page. `rel="me"` cho Mastodon verify. +**Links**: danh sách dọc lớn (icon + tên + mô tả 1 dòng + nút): YouTube, Discord gaming, Discord repo, Gitea (trước 2026-11-24: GitHub), Telegram, Bluesky, Mastodon, X, Facebook page. `rel="me"` cho Mastodon verify. ## 3. Điều hướng diff --git a/poli0981.dev-docs/06_SECURITY.md b/poli0981.dev-docs/06_SECURITY.md index f14dec5..4c1c916 100644 --- a/poli0981.dev-docs/06_SECURITY.md +++ b/poli0981.dev-docs/06_SECURITY.md @@ -42,7 +42,7 @@ request → src/worker.ts (mọi route, cả trang tĩnh) ## 3. Form duy nhất: /api/report (bug) -Rate limit §2 → body đọc có trần **32 KB** (khai `Content-Length` lớn hơn hoặc stream vượt ⇒ 413, không đọc hết) → validate Zod (`10` §3) → Turnstile `siteverify` (`success` + `action: "report"` + `hostname`) → issue ở repo **private** `poli0981/site-reports` + Discord (`allowed_mentions` rỗng, `@mention` trong nội dung bị vô hiệu) — mỗi lời gọi ra ngoài có timeout 10 s. Sai bất kỳ bước nào: 400/413/429, message chung chung, không lộ chi tiết. +Rate limit §2 → body đọc có trần **32 KB** (khai `Content-Length` lớn hơn hoặc stream vượt ⇒ 413, không đọc hết) → validate Zod (`10` §3) → Turnstile `siteverify` (`success` + `action: "report"` + `hostname`) → issue **confidential** trên mirror GitLab `poli0981/poli0981-dev` (đến 2026-11-23: repo private `poli0981/site-reports` trên GitHub) + Discord (`allowed_mentions` rỗng, `@mention` và quick action GitLab trong nội dung bị vô hiệu) — mỗi lời gọi ra ngoài có timeout 10 s. Sai bất kỳ bước nào: 400/413/429, message chung chung, không lộ chi tiết. Các API khác cũng có trần body: `/api/gate` 8 KB; JSON của admin 512 KB và bắt buộc `Content-Type: application/json`; upload ảnh 20 MB (từ chối theo `Content-Length` trước khi parse form). @@ -79,29 +79,30 @@ gate.js → Turnstile (action "gate") → POST /api/gate (RL_GATE, Sec-Fetch-Sit |---|---|---| | TURNSTILE_SECRET | worker site | form báo lỗi + cổng | | GATE_SECRET | worker site | ký vé cổng (≥ 32 byte ngẫu nhiên) | -| GITHUB_ISSUES_TOKEN | worker site | Fine-grained PAT: **chỉ repo `poli0981/site-reports`, chỉ Issues R/W**, hạn ≤ 1 năm | +| GITLAB_ISSUES_TOKEN | worker site | token GitLab, role **Reporter** trên project mirror `poli0981/poli0981-dev`, scope `api` — chỉ để tạo issue confidential (`10` §4) | | DISCORD_WEBHOOK_BUG | worker site | webhook 1 kênh riêng | -| GITHUB_CONTENT_TOKEN | worker site | Fine-grained PAT: **chỉ `poli0981/content`, Contents R/W** (admin lưu bài) | -| GITHUB_PUBLISH_TOKEN | worker site | Fine-grained PAT: **chỉ `poli0981/poli0981-dev`, Actions R/W** (nút Xuất bản). Thiếu ⇒ admin dùng tạm token nội dung và cảnh báo "một token" | +| GITEA_BOT_TOKEN | worker site | token `write:repository` của user bot `poli0981-bot`, collaborator Write **chỉ** trên `poli0981/content` (admin lưu bài) và `poli0981/poli0981-dev` (nút Xuất bản dispatch `content-bump.yml`) — §9 | | ADMIN_EMAILS | worker site | email được vào admin, phân cách dấu phẩy — **bắt buộc**, thiếu là không ai vào được | | STEAM_API_KEY, STEAM_ID64, DISCORD_WEBHOOK_CI | worker widgets | key Steam mặc định; webhook cảnh báo cron | -| GITHUB_TOKEN (tuỳ chọn) | worker widgets | fine-grained PAT **không quyền nào** (chỉ đọc dữ liệu public) — nâng hạn mức API events từ 60/giờ/IP (IP egress của Workers dùng chung, hay bị 403) | -| SONAR_TOKEN | GitHub Actions secret | phân tích SonarCloud (`08` §0) | +| QODANA_TOKEN | secret Actions (Gitea) | token project trên Qodana Cloud (`08` §0b) | +| CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID | secret Actions cấp user (Gitea) | job `deploy` của `ci.yml` — quyền ở `07` §10 | + +Bỏ ngày 2026-11-24 (chuyển sang Gitea): `GITHUB_ISSUES_TOKEN` (PAT chỉ repo private `poli0981/site-reports`, Issues R/W), `GITHUB_CONTENT_TOKEN` + `GITHUB_PUBLISH_TOKEN` (hai PAT của admin, thay bằng `GITEA_BOT_TOKEN`), `GITHUB_TOKEN` tuỳ chọn của worker widgets (feed Gitea không cần token), `SONAR_TOKEN` (secret GitHub Actions của SonarCloud). Không secret nào trong repo/`wrangler.jsonc`; `.dev.vars` nằm trong `.gitignore`. Admin chỉ hiện **tên** secret đã/chưa đặt (`/admin/security/`), không bao giờ hiện giá trị. -`wrangler secret put` tạo một version mới dựa trên version **mới nhất** đã upload và deploy nó ngay: chỉ đặt secret khi version mới nhất là bản của `main` (không phải bản preview của một PR) — kiểm bằng `wrangler versions list` trước. +`wrangler secret put` tạo một version mới dựa trên version **mới nhất** đã upload và deploy nó ngay: chỉ đặt secret khi version mới nhất là bản của `main` (không phải bản preview của một PR) — kiểm bằng `wrangler versions list` trước. (Từ 2026-11-24 CI không còn upload version preview cho PR, nhưng một `versions upload` chạy tay vẫn có thể là bản mới nhất.) ## 5. Nội dung nhúng bên thứ ba - YouTube: **click-to-load facade** — thumbnail do worker widgets mirror vào KV và site phục vụ qua `/ext-img/yt/` (icon Steam qua `/ext-img/steam/…`), nên trình duyệt khách **không gọi** `i.ytimg.com`/Steam trước khi bấm; bấm mới tạo iframe `youtube-nocookie.com`. `/ext-img` chỉ nhận đúng 2 mẫu đường dẫn, chỉ đọc KV (không bao giờ fetch theo yêu cầu của khách), trả kèm `CSP: sandbox`. -- Ngoại lệ duy nhất cho script bên ngoài: beacon Cloudflare Web Analytics (`static.cloudflareinsights.com`, báo về `cloudflareinsights.com`) — `type=module`, không cookie, chỉ có trong bản build production của Workers Builds (`src/components/CfBeacon.astro`). Turnstile chỉ tải khi trang xác minh/form báo lỗi cần. Còn lại: không font/CDN/script ngoài — mọi asset self-host. +- Ngoại lệ duy nhất cho script bên ngoài: beacon Cloudflare Web Analytics (`static.cloudflareinsights.com`, báo về `cloudflareinsights.com`) — `type=module`, không cookie, chỉ có trong bản build production — job `deploy` của CI đặt `PUBLIC_CF_BEACON=true` (đến 2026-11-23: bản build `main` của Workers Builds) (`src/components/CfBeacon.astro`). Turnstile chỉ tải khi trang xác minh/form báo lỗi cần. Còn lại: không font/CDN/script ngoài — mọi asset self-host. ## 6. Supply chain (repo public từ 10/2026) - **Cài đặt**: `npm ci --ignore-scripts` từ lockfile ở CI; `scripts/check-install-scripts.mjs` liệt kê gói có install script và fail khi xuất hiện gói mới ngoài allowlist (esbuild/workerd/sharp chạy được nhờ optionalDependencies, không cần script). -- **Quét**: Dependabot (alerts + security updates, **cooldown 3 ngày** — không đề xuất bản vừa phát hành, chặn kiểu Shai-Hulud) · `npm audit --omit=dev --audit-level=high` trong CI (fail = chặn merge) · OSV-Scanner (SARIF, hằng tuần + khi đổi lockfile) · **CodeQL** (free vì repo public) · **SonarCloud** (quality gate trên PR) · Snyk (GitHub app). -- Mỗi PR Dependabot: đọc changelog trước khi merge major; patch/minor merge khi CI xanh (08 §6). Khi `main` dính advisory mới, mọi PR đỏ ở bước audit ⇒ vá gộp một PR rồi đóng các PR bị thay thế. +- **Quét** (từ 2026-11-24): Renovate tự host (chỉ đề xuất bản đã phát hành **≥ 3 ngày** — chặn kiểu Shai-Hulud; cảnh báo OSV mở PR nhãn `security` ngay, không chờ) · `npm audit --omit=dev --audit-level=high` trong CI (fail = chặn merge) · **`security.yml`** (reusable của repo ops: gitleaks trên toàn bộ lịch sử, Opengrep luật JS/TS, osv-scanner trên `package-lock.json`; PR, push `main`, thứ Tư hằng tuần; SARIF là artifact vì Gitea không có code scanning) · **Qodana** (ngưỡng 0, tư vấn). Đến 2026-11-23: Dependabot (alerts + security updates, cooldown 3 ngày), OSV-Scanner (SARIF), CodeQL, SonarCloud (quality gate trên PR), Snyk (GitHub app). +- Mỗi PR Renovate: đọc changelog trước khi merge major; patch/minor merge khi CI xanh (08 §6). Khi `main` dính advisory mới, mọi PR đỏ ở bước audit ⇒ vá gộp một PR rồi đóng các PR bị thay thế. ## 7. security.txt (`public/.well-known/security.txt`) @@ -111,7 +112,7 @@ Contact: mailto:contact@poli0981.dev Expires: 2027-07-01T00:00:00Z Preferred-Languages: vi, en Canonical: https://poli0981.dev/.well-known/security.txt -Policy: https://github.com/poli0981/poli0981-dev/blob/main/SECURITY.md +Policy: https://git.poli0981.dev/poli0981/poli0981-dev/src/branch/main/SECURITY.md ``` ## 8. Checklist hardening @@ -142,7 +143,7 @@ admin.poli0981.dev ─▶ Cloudflare Access (policy email) ─▶ Worker - **Vì sao host riêng**: cùng origin thì một lỗi XSS ở trang công khai có thể gọi API admin bằng cookie Access. Khác origin + kiểm `Sec-Fetch-Site` ⇒ không. - **Ba lớp**: Access chặn ở edge; Worker tự kiểm JWT (preview URL/workers.dev đều tắt, header giả ⇒ 403 — smoke test kiểm cả JWT giả); `ADMIN_EMAILS` quyết định ai được thao tác — policy Access lỡ mở rộng cũng không mở admin. - **Khuyến nghị cấu hình Access** (dashboard, `07` §13b): bắt buộc MFA ở IdP/Access, session duration ≤ 24 giờ (khớp `maxTokenAge`), bật *binding cookie*, cookie `SameSite=Lax` trở lên. -- **Hai token GitHub** (fine-grained — quyền của một token áp cho *mọi* repo nó được chọn, nên không thể "ghi repo này, chỉ dispatch repo kia" bằng một token): `GITHUB_CONTENT_TOKEN` (chỉ `poli0981/content`, Contents R/W) và `GITHUB_PUBLISH_TOKEN` (chỉ `poli0981/poli0981-dev`, Actions R/W — không có Contents ⇒ lộ cũng không đẩy được code). Đọc trạng thái (PR, check, gitlink) không cần quyền vì hai repo đều public. Thiếu quyền ⇒ admin báo rõ token nào cần quyền gì (header `X-Accepted-GitHub-Permissions`). Xuất bản đi qua `content-bump.yml` (GITHUB_TOKEN) + CI `build` bắt buộc; diff có file ngoài `.md/.json` (vd. `.mdx` — chạy code lúc build) ⇒ không auto-merge. +- **Một token Gitea** (`GITEA_BOT_TOKEN`, từ 2026-11-24; `src/lib/admin/gitea.ts`): token `write:repository` của user bot `poli0981-bot`, collaborator Write chỉ trên `poli0981/content` và `poli0981/poli0981-dev`. Scope của token Gitea áp cho mọi repo mà user đó với tới, nên giới hạn nằm ở danh sách collaborator của bot, không ở token. Bot không đẩy code vào repo site — ở đó nó chỉ dispatch `content-bump.yml`, và `main` chỉ chủ repo push được (branch protection, `08` §0). Lưu bài = API change-files của Gitea (`POST /repos/{o}/{r}/contents`, sha của từng file là khoá lạc quan ⇒ sửa song song thì admin báo xung đột 409); danh sách = head nhánh + cây đệ quy + `POST …/file-contents` theo lô 50 file. Trạng thái xuất bản = PR `content/bump` đang mở, commit status `CI / build (…)` của nó, marker `` / `` trong thân PR, run `content-bump.yml` gần nhất. Xuất bản đi qua `content-bump.yml` (job token) + CI `build` bắt buộc; diff có file ngoài `.md/.json` (vd. `.mdx` — chạy code lúc build) ⇒ marker review, không tự merge. (Đến 2026-11-23: **hai token GitHub** fine-grained — quyền của một PAT áp cho *mọi* repo nó được chọn — `GITHUB_CONTENT_TOKEN` chỉ `poli0981/content` Contents R/W và `GITHUB_PUBLISH_TOKEN` chỉ `poli0981/poli0981-dev` Actions R/W; thiếu token thứ hai thì admin cảnh báo "một token". Cảnh báo đó đã bỏ.) - **Audit log**: mỗi thao tác (lưu/xoá nội dung, upload/sửa alt/xoá ảnh, lưu/xoá album, xuất bản, chặn/bỏ chặn IP) ghi một khoá KV `audit:*` (90 ngày) kèm email, đích và commit — xem ở `/admin/activity/` cạnh lịch sử commit của repo content. - **Upload ảnh**: kiểm magic bytes (không SVG), ≤ 20 MB, id = SHA-256 ⇒ trùng thì không biến đổi lại; biến thể + master tái mã hoá (mất EXIF/GPS), không giữ file gốc; `/media` chỉ phục vụ key biến thể, `CSP: sandbox`. Không xoá được ảnh còn được nội dung dùng. - **Preview Markdown** render trong `