Colota - Android GPS Location tracker
docs: derive the releases page from git tags (#595)
Max Dietrich473f908c2c17
diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.ymlindex c6053a18..5dc4cdd3 100644--- a/.github/workflows/deploy-docs.yml+++ b/.github/workflows/deploy-docs.yml@@ -24,6 +24,8 @@ jobs:steps:- name: Checkoutuses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7+ with:+ fetch-depth: 0- name: Setup Node.jsuses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7diff --git a/.github/workflows/docs-check.yml b/.github/workflows/docs-check.ymlindex 1bfa3308..33ef2b39 100644--- a/.github/workflows/docs-check.yml+++ b/.github/workflows/docs-check.yml@@ -20,6 +20,8 @@ jobs:steps:- name: Checkout codeuses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7+ with:+ fetch-depth: 0- name: Setup Node.jsuses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7diff --git a/apps/docs/releases.json b/apps/docs/releases.jsondeleted file mode 100644index d4143cdf..00000000--- a/apps/docs/releases.json+++ /dev/null@@ -1,22 +0,0 @@-{- "//": "Maps Play Store versionCode (the changelog filename) to the released version and date. Add one entry per release; the releases page is generated from this plus fastlane/metadata/android/en-US/changelogs/<code>.txt. Codes with no entry here are skipped, which is how unreleased builds stay off the page.",- "44": { "version": "1.13.0", "date": "2026-08-11" },- "43": { "version": "1.12.2", "date": "2026-08-02" },- "42": { "version": "1.12.1", "date": "2026-07-13" },- "41": { "version": "1.12.0", "date": "2026-07-06" },- "40": { "version": "1.11.0", "date": "2026-06-13" },- "39": { "version": "1.10.0", "date": "2026-05-31" },- "38": { "version": "1.9.0", "date": "2026-05-25" },- "37": { "version": "1.8.0", "date": "2026-05-15" },- "35": { "version": "1.7.1", "date": "2026-05-02" },- "34": { "version": "1.7.0", "date": "2026-04-30" },- "33": { "version": "1.6.1", "date": "2026-04-17" },- "32": { "version": "1.6.0", "date": "2026-04-09" },- "31": { "version": "1.5.1", "date": "2026-03-31" },- "30": { "version": "1.5.0", "date": "2026-03-28" },- "28": { "version": "1.4.0", "date": "2026-03-16" },- "25": { "version": "1.3.2", "date": "2026-03-08" },- "24": { "version": "1.3.1", "date": "2026-03-03" },- "22": { "version": "1.2.1", "date": "2026-02-26" },- "20": { "version": "1.2.0", "date": "2026-02-25" }-}diff --git a/apps/docs/scripts/generate-releases.mjs b/apps/docs/scripts/generate-releases.mjsindex e9b2a035..d6dad765 100644--- a/apps/docs/scripts/generate-releases.mjs+++ b/apps/docs/scripts/generate-releases.mjs@@ -1,4 +1,5 @@import { readFileSync, writeFileSync, existsSync } from "node:fs"+import { execFileSync } from "node:child_process"import { dirname, join } from "node:path"import { fileURLToPath } from "node:url"@@ -9,23 +10,67 @@ const changelogDir = join(repoRoot, "fastlane", "metadata", "android", "en-US",// A standalone page, not a doc: this is a changelog, and it mirrors src/pages/privacy-policy.md.const out = join(docsRoot, "src", "pages", "releases.md")const REPO = "https://github.com/dietrichmax/colota"+const GRADLE = "apps/mobile/android/app/build.gradle"-const releases = JSON.parse(readFileSync(join(docsRoot, "releases.json"), "utf8"))+const git = (...args) => execFileSync("git", args, { cwd: repoRoot, encoding: "utf8" }).trim()++let tags+try {+ tags = git("tag", "--list").split("\n").map((t) => t.trim())+} catch {+ throw new Error(`Cannot read git tags, which the releases page is derived from. CI needs fetch-depth: 0.`)+}++// Release tags only: drops the rc tags and the floating "latest".+const parts = (tag) => tag.slice(1).split(".").map(Number)+const releases = tags+ .filter((t) => /^v\d+\.\d+\.\d+$/.test(t))+ .sort((a, b) => {+ const [x, y] = [parts(a), parts(b)]+ return y[0] - x[0] || y[1] - x[1] || y[2] - x[2]+ })++// A release is shown when its tagged versionCode has a changelog file, so an unreleased build+// stays off the page until it is tagged, and the page cannot drift from what actually shipped.+const byCode = new Map()+const skipped = []+const mistagged = []+for (const tag of releases) {+ const version = tag.slice(1)+ let gradle+ try {+ gradle = git("show", `${tag}:${GRADLE}`)+ } catch {+ skipped.push(`${tag}: no ${GRADLE}`)+ continue+ }+ // A tag placed before its own release commit still carries the previous version, and would+ // otherwise claim that release's versionCode and overwrite it. Trust neither half unless+ // versionName agrees with the tag.+ const name = gradle.match(/versionName\s+"([^"]+)"/)?.[1]+ if (name !== version) {+ mistagged.push(`${tag} points at a commit declaring ${name ?? "no versionName"}`)+ continue+ }+ const code = Number(gradle.match(/versionCode\s+(\d+)/)[1])+ if (!existsSync(join(changelogDir, `${code}.txt`))) {+ skipped.push(`${tag}: no changelog for versionCode ${code}`)+ continue+ }+ byCode.set(code, { code, version, date: git("log", "-1", "--format=%as", tag) })+}// Newest first. Sorting by versionCode rather than version string avoids 1.10.0 < 1.9.0.-const entries = Object.entries(releases)- .filter(([code]) => code !== "//")- .map(([code, meta]) => ({ code: Number(code), ...meta }))- .sort((a, b) => b.code - a.code)+const entries = [...byCode.values()].sort((a, b) => b.code - a.code)++if (entries.length === 0) {+ throw new Error("No release tag matched a changelog, refusing to write an empty releases page.")+}const sections = entries.map((entry, i) => {- const file = join(changelogDir, `${entry.code}.txt`)- if (!existsSync(file)) {- throw new Error(`releases.json lists ${entry.version} (code ${entry.code}) but ${file} is missing`)- }// Docusaurus parses .md as MDX, so braces in changelog text (placeholders such as// {date}) would be evaluated as JSX expressions. Backslash-escape them.- const notes = readFileSync(file, "utf8").trim().replace(/([{}])/g, "\\$1")+ const notes = readFileSync(join(changelogDir, `${entry.code}.txt`), "utf8").trim().replace(/([{}])/g, "\\$1")const previous = entries[i + 1]const compare = previous? `${REPO}/compare/v${previous.version}...v${entry.version}`@@ -58,4 +103,8 @@ const page = [].join("\n")writeFileSync(out, page)+if (skipped.length) console.log(`Skipped ${skipped.length} tag(s):\n ${skipped.join("\n ")}`)+if (mistagged.length) {+ console.warn(`WARNING: ${mistagged.length} tag(s) missing from the page, retag to include them:\n ${mistagged.join("\n ")}`)+}console.log(`Generated ${out} with ${entries.length} releases`)