Skip to content

Build your personal knowledge base with Trilium Notes

fix(flatpak): delete the packaging repo files the recipe no longer owns

Elian Dorandb6a4f25cad7
diff --git a/.claude/skills/packaging-for-flathub/SKILL.md b/.claude/skills/packaging-for-flathub/SKILL.md
index f635792ecf..615ce9e3dc 100644
--- a/.claude/skills/packaging-for-flathub/SKILL.md
+++ b/.claude/skills/packaging-for-flathub/SKILL.md
@@ -30,7 +30,10 @@ the words that go to Flathub reviewers.
a clone of the real Flathub repo (default branch `master`, Elian has `push`). It holds
only the manifest, `trilium.sh`, `flathub.json`, `generated-sources.json` and a README.
**Never hand-edit it** — `update-repo.mts` overwrites everything but the sources file,
- which `generate-sources.mts` overwrites.
+ which `generate-sources.mts` overwrites, and deletes every *other* tracked file. A file
+ the recipe should keep but not write belongs in `KEPT_FILES`; `master` carried
+ `flip-fuses.mts`, `stamp-build-info.mts` and `trim-locales.mts` long after the manifest
+ moved to running the checkout's own copies, which is what that prune clears.
Local flow, from this repo, in this order:
diff --git a/scripts/flatpak/update-repo.mts b/scripts/flatpak/update-repo.mts
index fe20dd28a4..cd9a9bf38f 100644
--- a/scripts/flatpak/update-repo.mts
+++ b/scripts/flatpak/update-repo.mts
@@ -5,6 +5,8 @@
* `packageManager`. The desktop file and metainfo install from the pinned
* checkout itself; `generated-sources.json` is a separate step:
* ./scripts/flatpak/generate-sources.mts, run against the same ref's checkout.
+ * Whatever else the packaging repo still tracks is removed, so the pull request
+ * carries away an older recipe's leftovers rather than leaving them behind.
*
* Usage:
*
@@ -18,7 +20,7 @@
import { execFileSync } from "node:child_process";
import { createHash } from "node:crypto";
-import { appendFileSync, copyFileSync, readFileSync, statSync, writeFileSync } from "node:fs";
+import { appendFileSync, copyFileSync, existsSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
const REPO_ROOT = join(import.meta.dirname, "../..");
@@ -27,6 +29,9 @@ const MANIFEST_NAME = "org.triliumnotes.Trilium.yml";
// The wrapper is a manifest source; flathub.json configures Flathub's bots and
// only takes effect on the packaging repo's default branch.
const COPIED_FILES = [ "trilium.sh", "flathub.json" ];
+// Everything else tracked in the packaging repo is a leftover of an older recipe.
+// generate-sources.mts writes the sources file; the other two are the repo's own.
+const KEPT_FILES = [ MANIFEST_NAME, ...COPIED_FILES, "generated-sources.json", "README.md", ".gitignore" ];
const MIN_PNPM_MAJOR = 12;
export async function main(argv: string[]) {
@@ -53,12 +58,31 @@ export async function main(argv: string[]) {
for (const file of COPIED_FILES) {
copyFileSync(join(FLATPAK_DIR, file), join(repoDir, file));
}
+ // `git ls-files` keeps listing a deletion that is staged but not committed, so a
+ // re-run against the same checkout finds the file already gone.
+ for (const file of selectStaleFiles(gitIn(repoDir, "ls-files"))) {
+ if (existsSync(join(repoDir, file))) {
+ rmSync(join(repoDir, file));
+ console.log(`Removed ${file}, which the recipe no longer owns.`);
+ }
+ }
if (process.env.GITHUB_OUTPUT) {
appendFileSync(process.env.GITHUB_OUTPUT, formatOutputs(commit, tag, pnpmVersion));
}
console.log(`Updated ${repoDir}: ${tag ?? "beta"} @ ${commit}, pnpm ${pnpmVersion}.`);
}
+/**
+ * The tracked files the recipe no longer writes, so a pull request removes them instead
+ * of leaving an older recipe's leftovers behind — `master` still carries the build-time
+ * scripts from before the manifest ran the checkout's own copies.
+ */
+export function selectStaleFiles(trackedFiles: string): string[] {
+ return trackedFiles.split("\n")
+ .map((file) => file.trim())
+ .filter((file) => file && !KEPT_FILES.includes(file));
+}
+
/** Step outputs for the workflow that opens the pull request; the tag is empty for a beta. */
export function formatOutputs(commit: string, tag: string | undefined, pnpmVersion: string): string {
return `commit=${commit}\nshort=${commit.slice(0, 8)}\ntag=${tag ?? ""}\npnpm=${pnpmVersion}\n`;
@@ -139,6 +163,10 @@ function git(...args: string[]): string {
return execFileSync("git", args, { cwd: REPO_ROOT }).toString().trim();
}
+function gitIn(cwd: string, ...args: string[]): string {
+ return execFileSync("git", args, { cwd }).toString().trim();
+}
+
function isTag(ref: string): boolean {
try {
git("show-ref", "--verify", "--quiet", `refs/tags/${ref}`);
diff --git a/scripts/flatpak/update-repo.spec.ts b/scripts/flatpak/update-repo.spec.ts
index 1272b6cf6a..67b100ded5 100644
--- a/scripts/flatpak/update-repo.spec.ts
+++ b/scripts/flatpak/update-repo.spec.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { checkPlaceholdersFilled, checkPnpmSupported, formatOutputs, parsePnpmVersion, updateGitSource, updatePnpmPins } from "./update-repo.mjs";
+import { checkPlaceholdersFilled, checkPnpmSupported, formatOutputs, parsePnpmVersion, selectStaleFiles, updateGitSource, updatePnpmPins } from "./update-repo.mjs";
const MANIFEST = `\
modules:
@@ -89,3 +89,27 @@ describe("checkPlaceholdersFilled", () => {
.toThrow(/__ELECTRON_SHA256__/);
});
});
+
+describe("selectStaleFiles", () => {
+ it("keeps what the recipe writes and the repo owns, removes the rest", () => {
+ const tracked = [
+ ".gitignore",
+ "README.md",
+ "flathub.json",
+ "flip-fuses.mts",
+ "generated-sources.json",
+ "org.triliumnotes.Trilium.yml",
+ "stamp-build-info.mts",
+ "trilium.sh",
+ "trim-locales.mts",
+ ""
+ ].join("\n");
+
+ expect(selectStaleFiles(tracked))
+ .toEqual([ "flip-fuses.mts", "stamp-build-info.mts", "trim-locales.mts" ]);
+ });
+
+ it("finds nothing to remove once a repo holds only the recipe", () => {
+ expect(selectStaleFiles("org.triliumnotes.Trilium.yml\ntrilium.sh\n")).toEqual([]);
+ });
+});