From c24ed407efc9d34d32f4ad325994de8fb302bb02 Mon Sep 17 00:00:00 2001 From: Ewan Croft Date: Thu, 1 Oct 2026 21:08:07 +0100 Subject: [PATCH] Remove language snapshot workflow Drop the daily Actions job and script. The homepage uses the bundled snapshot, and fetches the commit total live when GITHUB_TOKEN is set. Co-Authored-By: Claude Code --- .github/workflows/github-languages.yml | 46 -------------------------- scripts/update-github-languages.mjs | 19 ----------- src/lib/services/home.ts | 43 +++++++++--------------- 3 files changed, 15 insertions(+), 93 deletions(-) delete mode 100644 .github/workflows/github-languages.yml delete mode 100644 scripts/update-github-languages.mjs diff --git a/.github/workflows/github-languages.yml b/.github/workflows/github-languages.yml deleted file mode 100644 index bca3f2ce..00000000 --- a/.github/workflows/github-languages.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Update GitHub languages - -on: - schedule: - - cron: "17 3 * * *" - workflow_dispatch: - -permissions: - contents: write - -jobs: - update: - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: 24 - - - name: Fetch language breakdown - run: node --experimental-strip-types scripts/update-github-languages.mjs - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_USERNAME: ${{ github.repository_owner }} - OUT_FILE: ${{ runner.temp }}/github-languages.json - - # main is protected, so the snapshot lives on an unprotected `data` branch - # that the site reads from raw.githubusercontent.com. - - name: Publish to data branch - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - if git ls-remote --exit-code --heads origin data >/dev/null; then - git fetch origin data:data - git worktree add "$RUNNER_TEMP/data" data - else - git worktree add --orphan -b data "$RUNNER_TEMP/data" - fi - cd "$RUNNER_TEMP/data" - cp "$RUNNER_TEMP/github-languages.json" github-languages.json - git add github-languages.json - if git diff --cached --quiet; then exit 0; fi - git commit -m "chore: refresh GitHub language breakdown" - git push origin data diff --git a/scripts/update-github-languages.mjs b/scripts/update-github-languages.mjs deleted file mode 100644 index 38331601..00000000 --- a/scripts/update-github-languages.mjs +++ /dev/null @@ -1,19 +0,0 @@ -// Writes the language snapshot (OUT_FILE, default src/lib/data/github-languages.json): exact language bytes across the -// user's non-fork repositories (GraphQL, paginated). Needs GITHUB_TOKEN, which -// Actions provides automatically. -import { writeFile } from "node:fs/promises"; -import { fetchGitHubCommitTotal, fetchGitHubLanguages } from "../src/lib/services/github.ts"; - -const username = process.env.GITHUB_USERNAME || "ewanc26"; -const token = process.env.GITHUB_TOKEN; -if (!token) throw new Error("GITHUB_TOKEN is required"); - -const [languages, commits] = await Promise.all([ - fetchGitHubLanguages(username, fetch, token), - fetchGitHubCommitTotal(username, fetch, token), -]); -if (languages.length === 0) throw new Error("No languages returned; leaving snapshot untouched"); - -const out = process.env.OUT_FILE || new URL("../src/lib/data/github-languages.json", import.meta.url); -await writeFile(out, JSON.stringify({ username, updatedAt: new Date().toISOString().slice(0, 10), commits, languages }, null, 2) + "\n"); -console.log(`Wrote ${languages.length} languages and ${commits} commits for ${username}`); diff --git a/src/lib/services/home.ts b/src/lib/services/home.ts index 2432ce1e..e28998c8 100644 --- a/src/lib/services/home.ts +++ b/src/lib/services/home.ts @@ -16,6 +16,7 @@ import { env } from "$env/dynamic/private"; import { fetchPinnedGitHubProjects, fetchGitHubContributions, + fetchGitHubCommitTotal, fetchGitHubLanguages, } from "$lib/services/github"; import languageSnapshot from "$lib/data/github-languages.json"; @@ -50,37 +51,23 @@ async function fetchVerifications() { } } -const LANGUAGE_SNAPSHOT_URL = - "https://raw.githubusercontent.com/ewanc26/website/data/github-languages.json"; - -type LanguageSnapshot = typeof languageSnapshot & { commits?: number | null }; - -const usable = (snap: LanguageSnapshot | null | undefined, username: string) => - !!snap && - snap.username?.toLowerCase() === username.toLowerCase() && - Array.isArray(snap.languages) && - snap.languages.length > 0; +type LanguageSnapshot = typeof languageSnapshot; async function loadSnapshot(username: string) { - try { - const res = await fetch(LANGUAGE_SNAPSHOT_URL); - if (res.ok) { - const remote = (await res.json()) as LanguageSnapshot; - if (usable(remote, username)) { - return { languages: remote.languages, commits: remote.commits ?? null }; - } - } - } catch {} + const token = env.GITHUB_TOKEN; const bundled = languageSnapshot as LanguageSnapshot; - if (usable(bundled, username)) { - return { languages: bundled.languages, commits: bundled.commits ?? null }; - } - const languages = await fetchGitHubLanguages( - username, - fetch, - env.GITHUB_TOKEN, - ).catch(() => []); - return { languages, commits: null }; + const hasBundled = + bundled.username?.toLowerCase() === username.toLowerCase() && + bundled.languages.length > 0; + const [languages, commits] = await Promise.all([ + hasBundled + ? Promise.resolve(bundled.languages) + : fetchGitHubLanguages(username, fetch, token).catch(() => []), + token + ? fetchGitHubCommitTotal(username, fetch, token).catch(() => null) + : Promise.resolve(null), + ]); + return { languages, commits }; } export async function getHomeData() {