Skip to content

Build your personal knowledge base with Trilium Notes

ci(flatpak): open the packaging repo's pull request from the workflow

Elian Dorancd644e4d0d34
diff --git a/.github/workflows/release-flathub.yml b/.github/workflows/release-flathub.yml
index 7ae2409cf1..922807767c 100644
--- a/.github/workflows/release-flathub.yml
+++ b/.github/workflows/release-flathub.yml
@@ -20,6 +20,14 @@ jobs:
# update-repo.mts resolves the ref against the checkout, so tags must be present.
fetch-depth: 0
+ - name: Clone the Flathub repo
+ uses: actions/checkout@v7
+ with:
+ repository: flathub/org.triliumnotes.Trilium
+ # Under the workspace so the pull request step can reach it.
+ path: flathub
+ token: ${{ secrets.FLATHUB_PAT }}
+
- uses: actions/setup-node@v7
with:
node-version: 24
@@ -29,27 +37,55 @@ jobs:
# lag behind fixes such as skipping the linux-armv7l binaries Electron 44 dropped.
run: pipx install 'git+https://github.com/flatpak/flatpak-builder-tools.git@41c20aa10819cdb2a4f3ca171758a96d1955c018#subdirectory=node'
- - name: Clone the Flathub repo
- run: git clone --depth=1 https://github.com/flathub/org.triliumnotes.Trilium.git "$RUNNER_TEMP/flathub"
-
- name: Update the manifest and packaging files
- run: node --experimental-strip-types scripts/flatpak/update-repo.mts "$RUNNER_TEMP/flathub" ${INPUT_REF:+"$INPUT_REF"}
+ id: update
+ run: node --experimental-strip-types scripts/flatpak/update-repo.mts flathub ${INPUT_REF:+"$INPUT_REF"}
env:
INPUT_REF: ${{ inputs.ref }}
- name: Generate the offline install sources
- run: node --experimental-strip-types scripts/flatpak/generate-sources.mts "$RUNNER_TEMP/flathub"
+ run: node --experimental-strip-types scripts/flatpak/generate-sources.mts flathub
- name: Validate the metainfo
+ # The build installs it from the pinned checkout, so this repo's copy is the one to check.
run: |
sudo apt-get update
sudo apt-get install --yes appstream
- appstreamcli validate --explain "$RUNNER_TEMP/flathub/org.triliumnotes.Trilium.metainfo.xml"
+ appstreamcli validate --explain apps/desktop/flatpak/org.triliumnotes.Trilium.metainfo.xml
- name: Show the resulting change
- run: git -C "$RUNNER_TEMP/flathub" --no-pager diff --stat
+ run: git -C flathub --no-pager diff --stat
- uses: actions/upload-artifact@v7
with:
name: flathub-repo
- path: ${{ runner.temp }}/flathub
+ path: flathub
+
+ - name: Open a pull request
+ uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
+ with:
+ path: flathub
+ token: ${{ secrets.FLATHUB_PAT }}
+ # One branch per tag, one shared branch for betas, so a re-run supersedes
+ # its predecessor instead of leaving a stale pull request behind.
+ branch: update/${{ steps.update.outputs.tag || 'beta' }}
+ draft: ${{ steps.update.outputs.tag == '' }}
+ commit-message: |
+ Update to ${{ steps.update.outputs.tag || steps.update.outputs.short }}
+
+ Generated from TriliumNext/Trilium@${{ steps.update.outputs.commit }}
+ by .github/workflows/release-flathub.yml.
+ title: ${{ steps.update.outputs.tag != '' && format('Update to {0}', steps.update.outputs.tag) || format('Test build of {0}', steps.update.outputs.short) }}
+ body: |
+ Packaged from [`${{ steps.update.outputs.short }}`](https://github.com/TriliumNext/Trilium/commit/${{ steps.update.outputs.commit }}).
+
+ * The manifest comes from `apps/desktop/flatpak/` in that commit; the desktop
+ file and metainfo install from its checkout, so they need no copy here.
+ * `generated-sources.json` was regenerated from that commit's `pnpm-lock.yaml`
+ (pnpm ${{ steps.update.outputs.pnpm }}) with `flatpak-node-generator`.
+ * `appstreamcli validate` passed on the metainfo before this was opened.
+
+ The `builds/x86_64` check covers both architectures: open its run to read the
+ `build-aarch64` job, which nothing reports on its own.
+
+ ${{ steps.update.outputs.tag == '' && '**Draft:** this commit is not a release tag. Merging it would publish an unreleased build to the stable channel — it is here for the test build.' || '' }}
diff --git a/scripts/flatpak/update-repo.mts b/scripts/flatpak/update-repo.mts
index 2408454ed3..a0910ddd65 100644
--- a/scripts/flatpak/update-repo.mts
+++ b/scripts/flatpak/update-repo.mts
@@ -16,7 +16,7 @@
import { execFileSync } from "node:child_process";
import { createHash } from "node:crypto";
-import { copyFileSync, readFileSync, statSync, writeFileSync } from "node:fs";
+import { appendFileSync, copyFileSync, readFileSync, statSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
const FLATPAK_DIR = join(import.meta.dirname, "../../apps/desktop/flatpak");
@@ -24,6 +24,7 @@ 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" ];
+const MIN_PNPM_MAJOR = 12;
export async function main(argv: string[]) {
const [repoDirArg, ref = "HEAD"] = argv;
@@ -39,6 +40,7 @@ export async function main(argv: string[]) {
const pnpmVersion = parsePnpmVersion(git("show", `${commit}:package.json`));
if (getPnpmVersion(manifest) !== pnpmVersion) {
+ checkPnpmSupported(pnpmVersion);
manifest = updatePnpmPins(manifest, pnpmVersion, {
x64: await sha256OfUrl(pnpmExeUrl("x64", pnpmVersion)),
arm64: await sha256OfUrl(pnpmExeUrl("arm64", pnpmVersion))
@@ -49,9 +51,17 @@ export async function main(argv: string[]) {
for (const file of COPIED_FILES) {
copyFileSync(join(FLATPAK_DIR, file), join(repoDir, file));
}
+ if (process.env.GITHUB_OUTPUT) {
+ appendFileSync(process.env.GITHUB_OUTPUT, formatOutputs(commit, tag, pnpmVersion));
+ }
console.log(`Updated ${repoDir}: ${tag ?? "beta"} @ ${commit}, pnpm ${pnpmVersion}.`);
}
+/** 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`;
+}
+
/** Pins the manifest's git source; without a tag, the `tag:` line goes (a beta builds a bare commit). */
export function updateGitSource(manifest: string, commit: string, tag?: string): string {
const gitSource = /(url: https:\/\/github\.com\/TriliumNext\/Trilium\.git\n)(\s*tag: \S+\n)?(\s*)commit: [0-9a-f]{40}/;
@@ -62,6 +72,18 @@ export function updateGitSource(manifest: string, commit: string, tag?: string):
`${urlLine}${tag ? `${indent}tag: ${tag}\n` : ""}${indent}commit: ${commit}`);
}
+/**
+ * The manifest pins pnpm per architecture, from the `@pnpm/exe.*` packages pnpm
+ * publishes since 12. Older refs pinned one wrapper tarball, whose URL this
+ * would otherwise build and fetch to a bare 404.
+ */
+export function checkPnpmSupported(version: string) {
+ if (Number(version.split(".")[0]) < MIN_PNPM_MAJOR) {
+ throw new Error(`The ref pins pnpm ${version}; the manifest's per-architecture `
+ + `sources need pnpm ${MIN_PNPM_MAJOR} or newer.`);
+ }
+}
+
/** The version the manifest's per-arch pnpm sources currently pin. */
export function getPnpmVersion(manifest: string): string {
const url = /exe\.linux-x64-([\d.]+)\.tgz/.exec(manifest);
diff --git a/scripts/flatpak/update-repo.spec.ts b/scripts/flatpak/update-repo.spec.ts
index c1ee3982f0..caeac83173 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 { getPnpmVersion, parsePnpmVersion, updateGitSource, updatePnpmPins } from "./update-repo.mjs";
+import { checkPnpmSupported, formatOutputs, getPnpmVersion, parsePnpmVersion, updateGitSource, updatePnpmPins } from "./update-repo.mjs";
const MANIFEST = `\
modules:
@@ -49,6 +49,15 @@ describe("updateGitSource", () => {
});
});
+describe("formatOutputs", () => {
+ it("reports the tag for a release and an empty tag for a beta", () => {
+ expect(formatOutputs(NEW_COMMIT, "v0.106.0", "12.4.2")).toBe(
+ `commit=${NEW_COMMIT}\nshort=12345678\ntag=v0.106.0\npnpm=12.4.2\n`);
+ // The workflow drafts the pull request when the tag is empty.
+ expect(formatOutputs(NEW_COMMIT, undefined, "12.4.2")).toContain("tag=\n");
+ });
+});
+
describe("pnpm pins", () => {
it("reads the pinned version", () => {
expect(getPnpmVersion(MANIFEST)).toBe("12.4.2");
@@ -71,6 +80,13 @@ describe("pnpm pins", () => {
expect(updated).not.toContain("12.4.2");
});
+ it("rejects a ref older than the per-arch pnpm packages", () => {
+ expect(() => checkPnpmSupported("12.4.2")).not.toThrow();
+ // pnpm 11 shipped one wrapper tarball; @pnpm/exe.* starts at 12, so the
+ // fetch would 404 with nothing explaining why.
+ expect(() => checkPnpmSupported("11.22.0")).toThrow(/pnpm 12 or newer/);
+ });
+
it("rejects a manifest missing a per-arch source", () => {
const withoutArm = MANIFEST.replace("exe.linux-arm64", "exe.linux-mips");
expect(() => updatePnpmPins(withoutArm, "12.5.0", { x64: "a".repeat(64), arm64: "b".repeat(64) }))