Skip to content

A full-featured download manager.

ci(release): publish validated flatpak application bundles (#2172)

Dr_rOot5bf2e9fa9212
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 86394b5e..dcbecdc5 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -207,6 +207,7 @@ jobs:
tests/scripts/verify-server-package.test.ts
tests/scripts/verify-update-artifacts.test.ts
tests/scripts/workflow-release-matrix.test.ts
+ tests/scripts/workflow-flatpak-release.test.ts
tests/scripts/workflow-snap.test.ts
- name: Type-check (root)
diff --git a/.github/workflows/flatpak.yml b/.github/workflows/flatpak.yml
index 65b80833..eb3f3152 100644
--- a/.github/workflows/flatpak.yml
+++ b/.github/workflows/flatpak.yml
@@ -1,9 +1,8 @@
-# Motrix Turbo — reproducible Flatpak validation and native builds.
+# Motrix — reproducible Flatpak validation and release builds.
#
-# The canonical manifest keeps the application source pointed at a future
-# public release. CI replaces only that source with a git archive of the
-# checked-out commit; every third-party source remains pinned and is fetched by
-# flatpak-builder before the offline build starts.
+# PR CI and the release caller replace the application's template source with
+# a checksum-pinned archive of the event commit. The release caller also checks
+# its preflight version. Third-party sources remain pinned for offline builds.
name: Flatpak
@@ -56,13 +55,19 @@ on:
- 'tsconfig*.json'
- 'vite*.config.ts'
workflow_dispatch:
+ workflow_call:
+ inputs:
+ release-version:
+ description: Expected package version from the release preflight
+ required: true
+ type: string
permissions:
contents: read
concurrency:
- group: flatpak-${{ github.ref }}
- cancel-in-progress: true
+ group: flatpak-${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: ${{ inputs.release-version == '' }}
jobs:
lint:
@@ -88,8 +93,7 @@ jobs:
run: desktop-file-validate flatpak/app.motrix.native.desktop
- name: Validate AppStream metainfo
- # Public repository and screenshot URLs are still maintainer-owned
- # submission blockers, so URL reachability is intentionally excluded.
+ # Keep metadata validation independent of website availability.
run: appstreamcli validate --no-net flatpak/app.motrix.native.metainfo.xml
- name: Lint Flatpak manifest
@@ -101,6 +105,9 @@ jobs:
name: Verify locked offline sources
runs-on: ubuntu-24.04
timeout-minutes: 30
+ outputs:
+ version: ${{ steps.source.outputs.version }}
+ branch: ${{ steps.source.outputs.branch }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
@@ -207,7 +214,15 @@ jobs:
tests/scripts/prepare-flatpak-node-lock.test.ts
- name: Prepare checked-out source for Flatpak
- run: node scripts/prepare-flatpak-project.mjs
+ id: source
+ env:
+ RELEASE_VERSION: ${{ inputs.release-version }}
+ run: |
+ args=(--ref "$GITHUB_SHA" --github-output "$GITHUB_OUTPUT")
+ if [[ -n "$RELEASE_VERSION" ]]; then
+ args+=(--version "$RELEASE_VERSION")
+ fi
+ node scripts/prepare-flatpak-project.mjs "${args[@]}"
- name: Upload prepared Flatpak source
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
@@ -261,14 +276,18 @@ jobs:
uses: flatpak/flatpak-github-actions/flatpak-builder@401fe28a8384095fc1531b9d320b292f0ee45adb # v6.7
with:
arch: ${{ matrix.flatpak_arch }}
+ branch: ${{ needs.sources.outputs.branch }}
bundle: app.motrix.native-${{ matrix.flatpak_arch }}.flatpak
manifest-path: flatpak/app.motrix.native.ci.yml
cache-key: flatpak-${{ matrix.flatpak_arch }}-${{ hashFiles('flatpak/app.motrix.native.yml', 'flatpak/generated-sources.json', 'flatpak/cargo-sources.json', 'pnpm-lock.yaml', 'packages/native-host/Cargo.lock', 'packages/finalize-fs/Cargo.lock') }}
- upload-artifact: true
+ upload-artifact: false
- name: Smoke-test installed payload
env:
MOTRIX_FLATPAK_ARCH: ${{ matrix.electron_arch }}
+ MOTRIX_FLATPAK_REF_ARCH: ${{ matrix.flatpak_arch }}
+ MOTRIX_FLATPAK_BRANCH: ${{ needs.sources.outputs.branch }}
+ MOTRIX_RELEASE_VERSION: ${{ needs.sources.outputs.version }}
# Container-local /tmp, not runner.temp: the workspace mount (/__w)
# is owned by neither the container user nor root, and the host
# companion refuses install trees under such ancestors by design.
@@ -283,6 +302,19 @@ jobs:
mkdir -p "$HOME" "$XDG_DATA_HOME" "$XDG_CONFIG_HOME"
flatpak --user install -y --noninteractive \
"./app.motrix.native-${{ matrix.flatpak_arch }}.flatpak"
+ test "$(flatpak --user info --show-ref app.motrix.native)" = \
+ "app/app.motrix.native/$MOTRIX_FLATPAK_REF_ARCH/$MOTRIX_FLATPAK_BRANCH"
+ installed_location="$(flatpak --user info --show-location app.motrix.native)"
+ python3 - "$installed_location" "$MOTRIX_RELEASE_VERSION" <<'PY'
+ import sys
+ import xml.etree.ElementTree as ET
+ from pathlib import Path
+
+ metainfo = Path(sys.argv[1]) / 'files/share/metainfo/app.motrix.native.metainfo.xml'
+ root = ET.parse(metainfo).getroot()
+ assert root.findtext('id') == 'app.motrix.native'
+ assert root.find('releases/release').get('version') == sys.argv[2]
+ PY
# The single-quoted payload is expanded by sh inside the Flatpak.
# shellcheck disable=SC2016
flatpak run \
@@ -441,3 +473,22 @@ jobs:
nonce_server_pid=''
cleanup
trap - EXIT
+
+ # Only successful builds and installed-payload checks may feed a release.
+ # Use this same staging path in PR CI and reusable release invocations.
+ - name: Stage verified Flatpak release bundle
+ env:
+ RELEASE_VERSION: ${{ needs.sources.outputs.version }}
+ FLATPAK_ARCH: ${{ matrix.flatpak_arch }}
+ run: |
+ mkdir -p flatpak-release
+ cp "app.motrix.native-${FLATPAK_ARCH}.flatpak" \
+ "flatpak-release/Motrix-${RELEASE_VERSION}-${FLATPAK_ARCH}.flatpak"
+
+ - name: Upload verified Flatpak release bundle
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: flatpak-release-${{ matrix.electron_arch }}
+ path: flatpak-release/*.flatpak
+ if-no-files-found: error
+ retention-days: 14
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f7a2ea5c..8e568e84 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -15,7 +15,9 @@
# runtime and per-architecture native zsync metadata. It self-integrates its
# desktop entry and URL-scheme handlers at runtime under the user's XDG data
# tree (src/main/platform/appimage-integration.ts). Snap has its own
-# strict-confinement build and Store promotion workflows. 32-bit targets remain
+# strict-confinement build and Store promotion workflows. Flatpak reuses its
+# native build and installed-payload checks and joins both Linux release sets.
+# 32-bit targets remain
# unsupported. Windows arm64 remains reserved until the aria2 lock supplies that
# architecture.
@@ -1529,13 +1531,21 @@ jobs:
if-no-files-found: error
retention-days: 7
+ flatpak:
+ name: Build and validate Flatpak
+ needs: preflight
+ uses: ./.github/workflows/flatpak.yml
+ with:
+ release-version: ${{ needs.preflight.outputs.version }}
+
assemble:
name: Assemble and validate release
- needs: [preflight, build, sign]
+ needs: [preflight, build, sign, flatpak]
if: >-
always() &&
needs.preflight.result == 'success' &&
needs.build.result == 'success' &&
+ needs.flatpak.result == 'success' &&
(
(github.event_name == 'push' && needs.sign.result == 'success') ||
(github.event_name == 'workflow_dispatch' && needs.sign.result == 'skipped')
@@ -1570,6 +1580,18 @@ jobs:
pattern: release-input-*
path: release-input
+ - name: Download verified x86_64 Flatpak
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
+ with:
+ name: flatpak-release-x64
+ path: release-input/release-input-linux-x64/flatpak
+
+ - name: Download verified aarch64 Flatpak
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
+ with:
+ name: flatpak-release-arm64
+ path: release-input/release-input-linux-arm64/flatpak
+
- name: Assemble release artifacts
run: >-
node scripts/assemble-release-artifacts.mjs
diff --git a/README.md b/README.md
index bdd852d4..395a1061 100644
--- a/README.md
+++ b/README.md
@@ -144,6 +144,7 @@ package that matches your operating system and architecture:
| Windows | `x64` | `.exe` (NSIS installer) / `.zip` | Use the `.exe` installer for a normal installation or `.zip` for a manually extracted copy |
| Linux | `x64`, `arm64` | `.AppImage` / `.deb` / `.rpm` | Use the portable `.AppImage` on any distribution, `.deb` on Debian or Ubuntu, or `.rpm` on Fedora or openSUSE |
| Linux (Snap Store) | `amd64`, `arm64` | `latest/edge` | Install the strictly confined beta with `sudo snap install motrix --edge` |
+| Linux (Flatpak) | `x86_64`, `aarch64` | `.flatpak` | Install a versioned bundle from a release that includes it; see the [Flatpak guide](docs/flatpak.md) |
| Arch Linux / Omarchy | `x64`, `arm64` | `.pacman` | Install the native Arch package with `sudo pacman -U ./Motrix-<version>-<arch>.pacman`; see the [Arch installation guide](docs/arch-linux.md) |
The `.AppImage` asks on first launch whether to register its desktop entry and
@@ -153,8 +154,11 @@ Settings → Integration.
The Snap Store package is strictly confined. Its approved `personal-files`
interface permits Motrix to register Native Messaging hosts for supported
browsers; it does not grant general access to files outside the normal Snap
-interfaces. Flatpak is validated separately and is not published by the
-release tag. Windows `arm64` and all 32-bit packages are not available.
+interfaces. Release tags build and validate Flatpak application bundles for
+both architectures before publication. Older releases, including beta.39,
+contain only the Flatpak Native Host companion. These single-file bundles
+require manual upgrades; they do not configure a Motrix update repository.
+Windows `arm64` and all 32-bit packages are not available.
Windows `x64` packages are unsigned and may trigger a Windows SmartScreen
warning.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 8fda1c5d..81ed6551 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -141,12 +141,15 @@ Motrix Extension 已上架官方浏览器扩展商店,配合 Motrix 2 使用
| Windows | `x64` | `.exe`(NSIS 安装包)/ `.zip` | 常规安装使用 `.exe`;`.zip` 可解压后手动运行 |
| Linux | `x64`、`arm64` | `.AppImage` / `.deb` / `.rpm` | 任意发行版可使用便携的 `.AppImage`,Debian 或 Ubuntu 使用 `.deb`,Fedora 或 openSUSE 使用 `.rpm` |
| Linux(Snap Store) | `amd64`、`arm64` | `latest/edge` | 使用 `sudo snap install motrix --edge` 安装严格限制的 beta |
+| Linux(Flatpak) | `x86_64`、`aarch64` | `.flatpak` | 从包含该格式的 Release 下载对应版本的安装包,详见 [Flatpak 安装指南](docs/flatpak.zh-CN.md) |
| Arch Linux / Omarchy | `x64`、`arm64` | `.pacman` | 使用 `sudo pacman -U ./Motrix-<version>-<arch>.pacman` 安装原生 Arch 包,详见 [Arch 安装指南](docs/arch-linux.zh-CN.md) |
`.AppImage` 首次启动时会询问是否把桌面入口和 URL scheme 处理程序注册到你的用户数据目录;拒绝则不改动系统。之后随时可以在「设置 → 集成」中启用或移除该桌面集成。
Snap Store 安装包使用严格限制。已批准的 `personal-files` interface 允许 Motrix
为支持的浏览器注册 Native Messaging host,不会授予常规 Snap interface
-之外的通用文件访问权限。Flatpak 会单独验证,不会随该版本 tag 发布。
+之外的通用文件访问权限。Release tag 会构建并验证两种架构的 Flatpak 主程序包,
+通过后再发布。beta.39 等旧版本仅包含 Flatpak Native Host 配套程序。
+这些单文件安装包需要手动升级,不会配置 Motrix 更新仓库。
同时不提供 Windows `arm64` 和任何 32 位安装包。Windows `x64` 安装包未签名,
可能触发 Windows SmartScreen 警告。
diff --git a/docs/flatpak.md b/docs/flatpak.md
new file mode 100644
index 00000000..9c2ac4d1
--- /dev/null
+++ b/docs/flatpak.md
@@ -0,0 +1,79 @@
+# Flatpak installation
+
+[简体中文](flatpak.zh-CN.md)
+
+Download the application bundle from a [Motrix GitHub release](https://github.com/agalwood/Motrix/releases)
+that includes `.flatpak` assets. The 2.0 beta releases up to beta.39 contain only the
+Native Host companion, which cannot install the application.
+
+| `uname -m` | Application bundle | Optional browser companion |
+|------------|--------------------|----------------------------|
+| `x86_64` | `Motrix-<version>-x86_64.flatpak` | `Motrix-Native-Host-<version>-linux-x64.tar.gz` |
+| `aarch64` | `Motrix-<version>-aarch64.flatpak` | `Motrix-Native-Host-<version>-linux-arm64.tar.gz` |
+
+## Install and run
+
+Install Flatpak using your distribution's package manager. Add Flathub for the
+shared runtime, then install the downloaded application as your normal user.
+Replace the placeholders with the actual filename:
+
+```bash
+flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
+flatpak install --user --or-update ./Motrix-<version>-<arch>.flatpak
+flatpak run app.motrix.native
+```
+
+The application ID is `app.motrix.native`. Beta bundles use the `beta` Flatpak
+branch; stable versions use `stable`. Use one branch at a time when integrating
+with the browser companion. Adding Flathub here provides dependencies; it does
+not install the older `net.agalwood.Motrix` application or publish Motrix 2.x to
+Flathub. The old ID is a separate application, not an automatic upgrade path.
+
+The sandbox permits access to Downloads by default. Select other directories
+through the file chooser portal. Application data is stored beneath
+`~/.var/app/app.motrix.native/`; switching packaging formats does not migrate
+existing Motrix data automatically.
+
+## Browser extension
+
+Ordinary downloads do not need the companion. To enable the supported host
+browsers' Native Messaging integration, first install the application, then
+download the matching version and architecture of the Native Host companion.
+Follow the [companion installation guide](../packages/native-host/README.md).
+
+The application bundle contains the in-sandbox broker. The companion runs
+outside the sandbox and is installed separately by the user. Neither component
+replaces the other; installing just the `.tar.gz` does not install Motrix.
+
+## Upgrade and remove
+
+Quit Motrix, download a newer `.flatpak` for the same architecture and branch,
+and install it with the same `flatpak install --user --or-update ./…flatpak` command.
+Flatpak will offer to update the existing installation. Update an installed
+browser companion separately using its documented `install --force` command.
+
+These bundles do not configure a Motrix remote. `flatpak update` can update
+shared runtimes, but does not discover newer Motrix bundles on GitHub.
+Download each application update from Releases.
+
+```bash
+flatpak uninstall --user app.motrix.native
+```
+
+Uninstall the companion separately if you installed it. Do not add
+`--delete-data` unless you intend to remove the application's saved data.
+
+## Build and release checks
+
+The release workflow calls the same native x86_64/aarch64 Flatpak workflow used
+by PR CI. It archives the release event's commit, verifies its package version
+against release preflight and AppStream metadata, and pins the source archive
+checksum. Each bundle is installed and checked for application ID, architecture,
+branch, version, aria2 features, and the private broker protocol. x86_64 also
+checks the host-side companion's framed Native Messaging exchange.
+
+Both bundles must succeed before release assembly and publication. They are
+required release assets, separate from Electron's updater manifests. Manual
+release workflow runs validate the build without publishing. These checks do
+not replace interactive desktop testing of portals, tray behavior, or browser
+pairing.
diff --git a/docs/flatpak.zh-CN.md b/docs/flatpak.zh-CN.md
new file mode 100644
index 00000000..78a91bee
--- /dev/null
+++ b/docs/flatpak.zh-CN.md
@@ -0,0 +1,66 @@
+# Flatpak 安装
+
+[English](flatpak.md)
+
+从包含 `.flatpak` 产物的 [Motrix GitHub Release](https://github.com/agalwood/Motrix/releases)
+下载主程序包。2.0 的 beta.39 及更早 beta 版本仅包含 Native Host 配套程序,不能用它安装主程序。
+
+| `uname -m` | 主程序包 | 可选的浏览器配套程序 |
+|------------|----------|--------------------|
+| `x86_64` | `Motrix-<version>-x86_64.flatpak` | `Motrix-Native-Host-<version>-linux-x64.tar.gz` |
+| `aarch64` | `Motrix-<version>-aarch64.flatpak` | `Motrix-Native-Host-<version>-linux-arm64.tar.gz` |
+
+## 安装和运行
+
+先通过发行版的包管理器安装 Flatpak。添加 Flathub 以获取共享运行时,再以普通用户
+安装下载的主程序包。将占位符替换为实际文件名:
+
+```bash
+flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
+flatpak install --user --or-update ./Motrix-<version>-<arch>.flatpak
+flatpak run app.motrix.native
+```
+
+应用 ID 为 `app.motrix.native`。Beta 包使用 Flatpak 的 `beta` 分支,正式版本使用
+`stable` 分支。使用浏览器配套程序时,请只保留其中一个分支。这里添加 Flathub 是
+为了获取依赖,不会安装旧的 `net.agalwood.Motrix`,也不代表 Motrix 2.x 已上架
+Flathub。旧 ID 对应另一个应用,不会自动升级为新 ID。
+
+沙箱默认允许访问下载目录;其他目录通过文件选择器 portal 授权。应用数据保存在
+`~/.var/app/app.motrix.native/` 下。切换安装包格式不会自动迁移原有 Motrix 数据。
+
+## 浏览器扩展
+
+普通下载不需要 companion。若要启用受支持的宿主机浏览器的 Native Messaging
+集成,请先安装主程序,再下载同版本、对应架构的 Native Host 配套程序,并按照
+[companion 安装指南](../packages/native-host/README.zh-CN.md)操作。
+
+主程序包包含沙箱内的 broker;companion 在沙箱外运行,由用户单独安装。两者不能
+相互替代,仅安装 `.tar.gz` 不会安装 Motrix 主程序。
+
+## 升级和卸载
+
+退出 Motrix,下载相同架构、相同分支的新版本 `.flatpak`,再次执行
+`flatpak install --user --or-update ./…flatpak`。Flatpak 会提示更新现有安装。如果安装了浏览器
+companion,还需要按照其文档使用 `install --force` 单独升级。
+
+这些包不会配置 Motrix remote。`flatpak update` 可以更新共享运行时,但不会从
+GitHub 发现新的 Motrix 单文件包。主程序每次更新都需要从 Release 下载。
+
+```bash
+flatpak uninstall --user app.motrix.native
+```
+
+如果安装了 companion,请单独卸载它。只有确定要删除应用保存的数据时,才添加
+`--delete-data`。
+
+## 构建和发布检查
+
+Release 工作流复用 PR CI 使用的 x86_64/aarch64 原生 Flatpak 构建流程。它归档
+发布事件对应的提交,核对源码版本、发布预检版本及 AppStream 版本,并固定源码
+归档的校验和。每个包都会实际安装,检查应用 ID、架构、分支、版本、aria2 功能和
+私有 broker 协议。x86_64 还会检查宿主机 companion 的 Native Messaging 帧通信。
+
+两种架构都成功后才能组装和发布 Release。主程序包属于必需发布产物,不进入
+Electron 的自动更新 manifest。手动运行 Release 工作流只验证构建,不会发布。
+这些检查不能替代对 portal、托盘和浏览器配对的交互式桌面测试。
diff --git a/flatpak/app.motrix.native.metainfo.xml b/flatpak/app.motrix.native.metainfo.xml
index 0614d69c..7e292ebf 100644
--- a/flatpak/app.motrix.native.metainfo.xml
+++ b/flatpak/app.motrix.native.metainfo.xml
@@ -44,13 +44,10 @@
<launchable type="desktop-id">app.motrix.native.desktop</launchable>
- <!-- TODO(maintainer): replace placeholder URLs once the public repo and
- site for motrix-turbo are finalized. The bugtracker URL must be
- reachable for Flathub review. -->
<url type="homepage">https://motrix.app/</url>
- <url type="bugtracker">https://github.com/TODO-ORG/motrix-turbo/issues</url>
+ <url type="bugtracker">https://github.com/agalwood/Motrix/issues</url>
<url type="help">https://motrix.app/manual/</url>
- <url type="vcs-browser">https://github.com/TODO-ORG/motrix-turbo</url>
+ <url type="vcs-browser">https://github.com/agalwood/Motrix</url>
<content_rating type="oars-1.1"/>
@@ -59,17 +56,14 @@
<color type="primary" scheme_preference="dark">#1f6f3a</color>
</branding>
- <!-- TODO(maintainer): replace screenshot URLs once motrix-turbo ships its
- own screenshots. Flathub requires at least one screenshot at 1248x720
- or larger; PNG is preferred over JPEG. -->
<screenshots>
<screenshot type="default">
<caption>Active downloads view</caption>
- <image>https://raw.githubusercontent.com/TODO-ORG/motrix-turbo/main/docs/screenshots/downloads-light.png</image>
+ <image>https://raw.githubusercontent.com/agalwood/Motrix/main/screenshots/motrix-downloads-en-light.webp</image>
</screenshot>
<screenshot>
<caption>Active downloads view (dark theme)</caption>
- <image>https://raw.githubusercontent.com/TODO-ORG/motrix-turbo/main/docs/screenshots/downloads-dark.png</image>
+ <image>https://raw.githubusercontent.com/agalwood/Motrix/main/screenshots/motrix-downloads-en-dark.webp</image>
</screenshot>
</screenshots>
diff --git a/flatpak/app.motrix.native.yml b/flatpak/app.motrix.native.yml
index 90aca1a2..a6b9c207 100644
--- a/flatpak/app.motrix.native.yml
+++ b/flatpak/app.motrix.native.yml
@@ -1,10 +1,10 @@
# Flathub manifest for Motrix Turbo.
#
-# The canonical application source remains a placeholder until motrix-turbo
-# has a public, tagged release. PR CI derives a temporary manifest from this
-# file and replaces only that source with a git archive of the checked-out
-# commit. Every dependency used after flatpak-builder enters its offline build
-# phase is declared below or in the two committed generated source manifests.
+# PR CI and release builds derive a manifest from this template, replacing the
+# application source with a checksum-pinned archive of the checked-out commit.
+# Direct Flathub submission still requires a public source tag and commit here.
+# Every dependency used during the offline build is declared below or in the
+# two committed generated source manifests.
app-id: app.motrix.native
runtime: org.freedesktop.Platform
diff --git a/scripts/assemble-release-artifacts.mjs b/scripts/assemble-release-artifacts.mjs
index 2d1d0ddc..b15d88ec 100644
--- a/scripts/assemble-release-artifacts.mjs
+++ b/scripts/assemble-release-artifacts.mjs
@@ -56,6 +56,7 @@ export const RELEASE_TARGETS = [
`Motrix-${version}-x64.pacman`,
`Motrix-${version}-x86_64.AppImage`,
`Motrix-${version}-x86_64.AppImage.zsync`,
+ `Motrix-${version}-x86_64.flatpak`,
flatpakCompanionArchiveName(version, 'x64'),
],
manifestAssetNames: (version) => [
@@ -76,6 +77,7 @@ export const RELEASE_TARGETS = [
`Motrix-${version}-aarch64.pacman`,
`Motrix-${version}-arm64.AppImage`,
`Motrix-${version}-arm64.AppImage.zsync`,
+ `Motrix-${version}-aarch64.flatpak`,
flatpakCompanionArchiveName(version, 'arm64'),
],
manifestAssetNames: (version) => [
@@ -105,6 +107,7 @@ const RELEASE_ASSET_EXTENSIONS = [
'.deb',
'.dmg',
'.exe',
+ '.flatpak',
'.rpm',
'.pacman',
'.snap',
@@ -314,6 +317,9 @@ async function collectTargetFiles(directory, target, version, manifestNames) {
].join(', ')}`
)
}
+ if (name.endsWith('.flatpak') && (await stat(source)).size === 0) {
+ throw new Error(`${target.name}: Flatpak bundle ${name} is empty`)
+ }
const key = name.toLowerCase()
const previous = selected.get(key)
diff --git a/scripts/prepare-flatpak-project.mjs b/scripts/prepare-flatpak-project.mjs
index eaad0cc4..55d9d240 100644
--- a/scripts/prepare-flatpak-project.mjs
+++ b/scripts/prepare-flatpak-project.mjs
@@ -1,10 +1,12 @@
#!/usr/bin/env node
import { spawnSync } from 'node:child_process'
-import { mkdir, readFile, writeFile } from 'node:fs/promises'
+import { createHash } from 'node:crypto'
+import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
+import { resolveReleaseMetadata } from './release-metadata.mjs'
const SCRIPT_PATH = fileURLToPath(import.meta.url)
const require = createRequire(import.meta.url)
@@ -24,6 +26,8 @@ export function parseArgs(argv) {
output: 'flatpak/app.motrix.native.ci.yml',
archive: 'flatpak/motrix-source.tar.gz',
ref: 'HEAD',
+ version: '',
+ 'github-output': '',
}
for (let index = 0; index < argv.length; index += 1) {
@@ -45,7 +49,7 @@ function requireRecord(value, label) {
return value
}
-export function replaceApplicationSource(manifest, archivePath) {
+export function replaceApplicationSource(manifest, archivePath, sha256) {
const root = requireRecord(structuredClone(manifest), 'Flatpak manifest')
if (!Array.isArray(root.modules)) {
throw new Error('Flatpak manifest modules must be an array')
@@ -79,10 +83,20 @@ export function replaceApplicationSource(manifest, archivePath) {
type: 'archive',
path: archivePath,
'strip-components': 0,
+ ...(sha256 ? { sha256 } : {}),
}
return root
}
+function gitOutput(repoRoot, args) {
+ const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' })
+ if (result.error) throw result.error
+ if (result.status !== 0) {
+ throw new Error(`git ${args[0]} failed: ${result.stderr.trim()}`)
+ }
+ return result.stdout.trim()
+}
+
function createArchive(repoRoot, outputPath, ref) {
const result = spawnSync(
'git',
@@ -104,6 +118,34 @@ export async function prepareFlatpakProject(options, repoRoot = process.cwd()) {
const outputDir = path.dirname(outputPath)
const relativeArchive = path.relative(outputDir, archivePath)
+ // The manifest and dependency locks come from this checkout. Never pair
+ // those inputs with application source from another revision.
+ const revision = gitOutput(repoRoot, ['rev-parse', `${options.ref}^{commit}`])
+ if (revision !== gitOutput(repoRoot, ['rev-parse', 'HEAD'])) {
+ throw new Error('Flatpak source ref must match the checked-out commit')
+ }
+ const sourcePackage = JSON.parse(
+ gitOutput(repoRoot, ['show', `${revision}:package.json`])
+ )
+ const metadata = resolveReleaseMetadata({
+ eventName: 'workflow_dispatch',
+ packageVersion: sourcePackage.version,
+ })
+ if (options.version && options.version !== metadata.version) {
+ throw new Error(
+ `Flatpak source version ${metadata.version} does not match release version ${options.version}`
+ )
+ }
+ const metainfo = await readFile(
+ path.join(repoRoot, 'flatpak/app.motrix.native.metainfo.xml'),
+ 'utf8'
+ )
+ if (
+ metainfo.match(/<release\s+version="([^"]+)"/)?.[1] !== metadata.version
+ ) {
+ throw new Error('Flatpak AppStream version must match the source version')
+ }
+
if (
relativeArchive === '' ||
relativeArchive.startsWith(`..${path.sep}`) ||
@@ -113,13 +155,17 @@ export async function prepareFlatpakProject(options, repoRoot = process.cwd()) {
}
await mkdir(outputDir, { recursive: true })
- createArchive(repoRoot, archivePath, options.ref)
+ createArchive(repoRoot, archivePath, revision)
const manifest = yaml.load(await readFile(manifestPath, 'utf8'))
const prepared = replaceApplicationSource(
manifest,
- relativeArchive.split(path.sep).join('/')
+ relativeArchive.split(path.sep).join('/'),
+ createHash('sha256')
+ .update(await readFile(archivePath))
+ .digest('hex')
)
+ prepared.branch = metadata.channel
await writeFile(
outputPath,
yaml.dump(prepared, {
@@ -130,7 +176,13 @@ export async function prepareFlatpakProject(options, repoRoot = process.cwd()) {
}),
'utf8'
)
- return { manifestPath: outputPath, archivePath }
+ if (options['github-output']) {
+ await appendFile(
+ options['github-output'],
+ `version=${metadata.version}\nbranch=${metadata.channel}\nrevision=${revision}\n`
+ )
+ }
+ return { manifestPath: outputPath, archivePath, ...metadata, revision }
}
async function main() {
diff --git a/tests/scripts/assemble-release-artifacts.test.ts b/tests/scripts/assemble-release-artifacts.test.ts
index 071302bb..6a522666 100644
--- a/tests/scripts/assemble-release-artifacts.test.ts
+++ b/tests/scripts/assemble-release-artifacts.test.ts
@@ -50,6 +50,8 @@ describe('assembleReleaseArtifacts', () => {
'Motrix-2.0.0-arm64.AppImage.zsync',
'Motrix-2.0.0-x86_64.AppImage',
'Motrix-2.0.0-x86_64.AppImage.zsync',
+ 'Motrix-2.0.0-aarch64.flatpak',
+ 'Motrix-2.0.0-x86_64.flatpak',
'Motrix-2.0.0.aarch64.rpm',
'Motrix-2.0.0.x86_64.rpm',
'Motrix-2.0.0-x64.pacman',
@@ -101,6 +103,9 @@ describe('assembleReleaseArtifacts', () => {
expect(
linuxManifest.files.some((file) => file.url.endsWith('.AppImage'))
).toBe(true)
+ expect(
+ linuxManifest.files.some((file) => file.url.endsWith('.flatpak'))
+ ).toBe(false)
}
await expect(
@@ -294,6 +299,54 @@ describe('assembleReleaseArtifacts', () => {
)
})
+ it.each(['linuxX64Flatpak', 'linuxArm64Flatpak'] as const)(
+ 'requires the Flatpak application bundle %s before assembly',
+ async (key) => {
+ const fixture = await createFixture()
+ await unlink(fixture.paths[key])
+ await expect(
+ assembleReleaseArtifacts({
+ inputDirectory: fixture.input,
+ outputDirectory: fixture.output,
+ version: VERSION,
+ })
+ ).rejects.toThrow(
+ `required release asset ${fixture.names[key]} is missing`
+ )
+ await expect(access(fixture.output)).rejects.toThrow()
+ }
+ )
+
+ it.each(['Motrix-1.0.0-x86_64.flatpak', 'Motrix-2.0.0-aarch64.flatpak'])(
+ 'rejects a wrong version or architecture in the x64 bundle: %s',
+ async (name) => {
+ const fixture = await createFixture()
+ await rename(
+ fixture.paths.linuxX64Flatpak,
+ path.join(path.dirname(fixture.paths.linuxX64Flatpak), name)
+ )
+ await expect(
+ assembleReleaseArtifacts({
+ inputDirectory: fixture.input,
+ outputDirectory: fixture.output,
+ version: VERSION,
+ })
+ ).rejects.toThrow('unexpected release asset')
+ }
+ )
+
+ it('rejects an empty Flatpak bundle', async () => {
+ const fixture = await createFixture()
+ await writeFile(fixture.paths.linuxX64Flatpak, '')
+ await expect(
+ assembleReleaseArtifacts({
+ inputDirectory: fixture.input,
+ outputDirectory: fixture.output,
+ version: VERSION,
+ })
+ ).rejects.toThrow('is empty')
+ })
+
it('requires one architecture-specific Flatpak companion per Linux target', async () => {
const fixture = await createFixture()
await unlink(fixture.paths.linuxX64Companion)
@@ -622,12 +675,14 @@ async function createFixture(version = VERSION) {
await mkdir(input)
const names = {
+ linuxArm64Flatpak: `Motrix-${version}-aarch64.flatpak`,
linuxArm64Pacman: `Motrix-${version}-aarch64.pacman`,
linuxArm64Deb: `Motrix_${version}_arm64.deb`,
linuxArm64Companion: `Motrix-Native-Host-${version}-linux-arm64.tar.gz`,
linuxArm64Rpm: `Motrix-${version}.aarch64.rpm`,
linuxArm64AppImage: `Motrix-${version}-arm64.AppImage`,
linuxArm64Zsync: `Motrix-${version}-arm64.AppImage.zsync`,
+ linuxX64Flatpak: `Motrix-${version}-x86_64.flatpak`,
linuxX64Pacman: `Motrix-${version}-x64.pacman`,
linuxX64Deb: `Motrix_${version}_amd64.deb`,
linuxX64Companion: `Motrix-Native-Host-${version}-linux-x64.tar.gz`,
@@ -643,6 +698,7 @@ async function createFixture(version = VERSION) {
const linuxArm64AppImageContent = Buffer.from('Linux arm64 AppImage')
const linuxX64AppImageContent = Buffer.from('Linux x64 AppImage')
const contents = {
+ linuxArm64Flatpak: Buffer.from('Flatpak aarch64'),
linuxArm64Pacman: Buffer.from('Linux arm64 pacman'),
linuxArm64Deb: Buffer.from('Linux arm64 deb'),
linuxArm64Companion: Buffer.from('Linux arm64 Flatpak companion'),
@@ -652,6 +708,7 @@ async function createFixture(version = VERSION) {
names.linuxArm64AppImage,
linuxArm64AppImageContent
),
+ linuxX64Flatpak: Buffer.from('Flatpak x86_64'),
linuxX64Pacman: Buffer.from('Linux x64 pacman'),
linuxX64Deb: Buffer.from('Linux x64 deb'),
linuxX64Companion: Buffer.from('Linux x64 Flatpak companion'),
@@ -719,6 +776,11 @@ async function createFixture(version = VERSION) {
)
const linuxX64 = await makeTarget(input, 'linux-x64')
+ const linuxX64Flatpak = await writeAsset(
+ linuxX64,
+ names.linuxX64Flatpak,
+ contents.linuxX64Flatpak
+ )
const linuxX64Pacman = await writeAsset(
linuxX64,
names.linuxX64Pacman,
@@ -773,6 +835,11 @@ async function createFixture(version = VERSION) {
)
const linuxArm64 = await makeTarget(input, 'linux-arm64')
+ const linuxArm64Flatpak = await writeAsset(
+ linuxArm64,
+ names.linuxArm64Flatpak,
+ contents.linuxArm64Flatpak
+ )
const linuxArm64Pacman = await writeAsset(
linuxArm64,
names.linuxArm64Pacman,
@@ -852,6 +919,7 @@ async function createFixture(version = VERSION) {
names,
output,
paths: {
+ linuxArm64Flatpak: linuxArm64Flatpak.path,
linuxArm64Pacman: linuxArm64Pacman.path,
linuxArm64Deb: linuxArm64Deb.path,
linuxArm64Companion: linuxArm64Companion.path,
@@ -859,6 +927,7 @@ async function createFixture(version = VERSION) {
linuxArm64Rpm: linuxArm64Rpm.path,
linuxArm64AppImage: linuxArm64AppImage.path,
linuxArm64Zsync: linuxArm64Zsync.path,
+ linuxX64Flatpak: linuxX64Flatpak.path,
linuxX64Pacman: linuxX64Pacman.path,
linuxX64Deb: linuxX64Deb.path,
linuxX64Companion: linuxX64Companion.path,
diff --git a/tests/scripts/flatpak-project.test.ts b/tests/scripts/flatpak-project.test.ts
index 94a23c4a..445b81f8 100644
--- a/tests/scripts/flatpak-project.test.ts
+++ b/tests/scripts/flatpak-project.test.ts
@@ -1,14 +1,30 @@
-import { readFileSync } from 'node:fs'
+import { execFileSync } from 'node:child_process'
+import { createHash } from 'node:crypto'
+import {
+ mkdirSync,
+ mkdtempSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs'
import { createRequire } from 'node:module'
+import { tmpdir } from 'node:os'
import path from 'node:path'
-import { describe, expect, it } from 'vitest'
+import { afterEach, describe, expect, it } from 'vitest'
// @ts-expect-error -- JavaScript packaging script intentionally has no declarations
import {
parseArgs,
+ prepareFlatpakProject,
replaceApplicationSource,
} from '../../scripts/prepare-flatpak-project.mjs'
const require = createRequire(import.meta.url)
+const tempDirs: string[] = []
+afterEach(() => {
+ for (const directory of tempDirs.splice(0)) {
+ rmSync(directory, { recursive: true, force: true })
+ }
+})
const parseYaml = require('js-yaml').load as (source: string) => unknown
const manifest = parseYaml(
readFileSync(
@@ -24,6 +40,62 @@ const manifest = parseYaml(
}
describe('prepare-flatpak-project', () => {
+ it.each(['2.0.0', '2.0.0-beta.40'])(
+ 'pins the archived commit, version and branch for %s',
+ async (version) => {
+ const { root, git, options } = createSourceFixture(version)
+ const result = await prepareFlatpakProject(options, root)
+ const prepared = parseYaml(readFileSync(result.manifestPath, 'utf8')) as {
+ branch: string
+ modules: Array<{ sources: Array<{ sha256: string }> }>
+ }
+ expect(prepared.branch).toBe(version.includes('-') ? 'beta' : 'stable')
+ expect(prepared.modules[0]?.sources[0]?.sha256).toBe(
+ createHash('sha256')
+ .update(readFileSync(result.archivePath))
+ .digest('hex')
+ )
+ const archivedPackage = execFileSync(
+ 'tar',
+ ['-xOf', result.archivePath, 'package.json'],
+ {
+ encoding: 'utf8',
+ }
+ )
+ expect(JSON.parse(archivedPackage).version).toBe(version)
+ expect(readFileSync(options['github-output'], 'utf8')).toContain(
+ `revision=${git('rev-parse', 'HEAD')}`
+ )
+ expect(result.version).toBe(version)
+ }
+ )
+
+ it('rejects a release version that differs from the archived source', async () => {
+ const { root, options } = createSourceFixture('2.0.0-beta.40')
+ await expect(
+ prepareFlatpakProject({ ...options, version: '2.0.0-beta.39' }, root)
+ ).rejects.toThrow('does not match release version')
+ })
+
+ it('rejects archiving a different commit than the dependency checkout', async () => {
+ const { root, git, options } = createSourceFixture('2.0.0')
+ git('commit', '--allow-empty', '-m', 'next source')
+ await expect(
+ prepareFlatpakProject({ ...options, ref: 'HEAD~1' }, root)
+ ).rejects.toThrow('must match the checked-out commit')
+ })
+
+ it('rejects stale AppStream metadata before producing a release bundle', async () => {
+ const { root, options } = createSourceFixture('2.0.0')
+ writeFileSync(
+ path.join(root, 'flatpak/app.motrix.native.metainfo.xml'),
+ '<component><releases><release version="1.0.0"/></releases></component>'
+ )
+ await expect(prepareFlatpakProject(options, root)).rejects.toThrow(
+ 'AppStream version must match'
+ )
+ })
+
it('replaces only the application git source with the CI archive', () => {
const prepared = replaceApplicationSource(
manifest,
@@ -103,7 +175,39 @@ describe('prepare-flatpak-project', () => {
output: 'flatpak/ci.yml',
archive: 'flatpak/source.tar.gz',
ref: 'abc123',
+ version: '',
+ 'github-output': '',
})
expect(() => parseArgs(['--surprise', 'value'])).toThrow('unknown flag')
})
})
+
+function createSourceFixture(version: string) {
+ const root = mkdtempSync(path.join(tmpdir(), 'motrix-flatpak-source-'))
+ tempDirs.push(root)
+ mkdirSync(path.join(root, 'flatpak'))
+ writeFileSync(path.join(root, 'package.json'), JSON.stringify({ version }))
+ writeFileSync(
+ path.join(root, 'flatpak/app.motrix.native.yml'),
+ 'modules:\n - name: motrix\n sources:\n - type: git\n url: https://example.test/motrix.git\n'
+ )
+ writeFileSync(
+ path.join(root, 'flatpak/app.motrix.native.metainfo.xml'),
+ `<component><releases><release version="${version}"/></releases></component>`
+ )
+ const git = (...args: string[]) =>
+ execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim()
+ git('init', '--quiet')
+ git('config', 'user.email', '[email protected]')
+ git('config', 'user.name', 'Flatpak test')
+ git('config', 'commit.gpgsign', 'false')
+ git('add', '.')
+ git('commit', '--quiet', '-m', 'source')
+ const options = parseArgs([
+ '--version',
+ version,
+ '--github-output',
+ path.join(root, 'github-output'),
+ ])
+ return { root, git, options }
+}
diff --git a/tests/scripts/workflow-flatpak-release.test.ts b/tests/scripts/workflow-flatpak-release.test.ts
new file mode 100644
index 00000000..b51434f9
--- /dev/null
+++ b/tests/scripts/workflow-flatpak-release.test.ts
@@ -0,0 +1,120 @@
+import { readFileSync } from 'node:fs'
+import { load } from 'js-yaml'
+import { describe, expect, it } from 'vitest'
+
+interface Step {
+ name?: string
+ uses?: string
+ if?: string
+ run?: string
+ with?: Record<string, unknown>
+}
+
+interface Workflow {
+ on: Record<string, unknown>
+ concurrency: Record<string, unknown>
+ jobs: Record<
+ string,
+ {
+ needs?: string | string[]
+ uses?: string
+ if?: string
+ with?: Record<string, unknown>
+ steps?: Step[]
+ }
+ >
+}
+
+const flatpak = load(
+ readFileSync('.github/workflows/flatpak.yml', 'utf8')
+) as Workflow
+const release = load(
+ readFileSync('.github/workflows/release.yml', 'utf8')
+) as Workflow
+
+describe('Flatpak release gate', () => {
+ it('builds within the release run, after version preflight, and blocks assembly on failure', () => {
+ expect(flatpak.on.workflow_call).toEqual({
+ inputs: {
+ 'release-version': {
+ description: expect.any(String),
+ required: true,
+ type: 'string',
+ },
+ },
+ })
+ expect(release.jobs.flatpak).toMatchObject({
+ needs: 'preflight',
+ uses: './.github/workflows/flatpak.yml',
+ with: { 'release-version': `\${{ needs.preflight.outputs.version }}` },
+ })
+ expect(release.jobs.assemble?.needs).toContain('flatpak')
+ expect(release.jobs.assemble?.if).toContain(
+ "needs.flatpak.result == 'success'"
+ )
+ expect(flatpak.concurrency['cancel-in-progress']).toBe(
+ `\${{ inputs.release-version == '' }}`
+ )
+ expect(flatpak.concurrency.group).toContain('github.workflow')
+ })
+
+ it('pins the source to the event revision and checks the preflight version', () => {
+ const prepare = flatpak.jobs.sources?.steps?.find(
+ (step) => step.name === 'Prepare checked-out source for Flatpak'
+ )
+ expect(prepare?.run).toContain('--ref "$GITHUB_SHA"')
+ expect(prepare?.run).toContain('--version "$RELEASE_VERSION"')
+ const builder = flatpak.jobs.build?.steps?.find(
+ (step) => step.name === 'Build Flatpak bundle'
+ )
+ expect(builder?.with?.branch).toBe(`\${{ needs.sources.outputs.branch }}`)
+ })
+
+ it('uploads only after installed-bundle and native-messaging checks, including in PR CI', () => {
+ const steps = flatpak.jobs.build?.steps ?? []
+ const install = steps.findIndex(
+ (step) => step.name === 'Smoke-test installed payload'
+ )
+ const companion = steps.findIndex(
+ (step) =>
+ step.name ===
+ 'Smoke-test Browser Native Messaging through the host companion'
+ )
+ const upload = steps.findIndex(
+ (step) => step.name === 'Upload verified Flatpak release bundle'
+ )
+ expect(install).toBeGreaterThanOrEqual(0)
+ expect(companion).toBeGreaterThan(install)
+ expect(upload).toBeGreaterThan(companion)
+ expect(steps[upload]?.if).toBeUndefined()
+ expect(steps[upload]?.with).toMatchObject({
+ name: `flatpak-release-\${{ matrix.electron_arch }}`,
+ path: 'flatpak-release/*.flatpak',
+ 'if-no-files-found': 'error',
+ })
+ expect(
+ steps.find((step) => step.name === 'Build Flatpak bundle')?.with?.[
+ 'upload-artifact'
+ ]
+ ).toBe(false)
+ expect(steps[install]?.run).toContain('--show-ref')
+ expect(steps[install]?.run).toContain(
+ "root.find('releases/release').get('version') == sys.argv[2]"
+ )
+ })
+
+ it('downloads both verified bundles into their matching Linux release inputs', () => {
+ const steps = release.jobs.assemble?.steps ?? []
+ for (const arch of ['x64', 'arm64']) {
+ const download = steps.find(
+ (step) => step.with?.name === `flatpak-release-${arch}`
+ )
+ expect(download?.uses).toMatch(/^actions\/download-artifact@/)
+ expect(download?.with?.path).toBe(
+ `release-input/release-input-linux-${arch}/flatpak`
+ )
+ }
+ expect(release.jobs.publish?.needs).toContain('assemble')
+ expect(release.jobs.publish?.if).toContain("github.event_name == 'push'")
+ })
+})
diff --git a/tests/scripts/workflow-release-matrix.test.ts b/tests/scripts/workflow-release-matrix.test.ts
index f6369041..023d0b35 100644
--- a/tests/scripts/workflow-release-matrix.test.ts
+++ b/tests/scripts/workflow-release-matrix.test.ts
@@ -2755,20 +2755,16 @@ describe('release workflow publication contract', () => {
it('keeps inline Node workflow steps syntactically executable', () => {
let checked = 0
- for (const [jobName, value] of Object.entries(
- workflowJobs(releaseWorkflow)
- )) {
- for (const step of jobSteps(asRecord(value, `${jobName} job`))) {
- if (step.shell !== 'node {0}') continue
- const source = stringField(step, 'run').replace(
- /\$\{\{[\s\S]*?\}\}/gu,
- 'github_expression'
- )
- expect(
- () => new Script(source, { filename: `${jobName}.js` })
- ).not.toThrow()
- checked += 1
- }
+ for (const { jobName, step } of allSteps(releaseWorkflow)) {
+ if (step.shell !== 'node {0}') continue
+ const source = stringField(step, 'run').replace(
+ /\$\{\{[\s\S]*?\}\}/gu,
+ 'github_expression'
+ )
+ expect(
+ () => new Script(source, { filename: `${jobName}.js` })
+ ).not.toThrow()
+ checked += 1
}
expect(checked).toBeGreaterThan(0)
})