本站支持 ActivityPub: [email protected]

如何在 Flathub 发布自己的开源软件

封面图片来源:使用 Aseprite 制作(源文件, 遵循 CC BY-SA 4.0

注意:本文不是 flatpak 打包教程,并假定读者能够独立打包 flatpak 格式安装包

QRookie 为例子演示如何向 Flathub 提交软件,这也是我目前唯一发布在 Flathub 的软件

编写 Manifest

QRookie 项目本身已经包含图标、.desktop 文件、Appstream 文件,只需要编写 flatpak manifest 就可以了。(如果你要打包的软件不包含这些,或不符合规范,那就得自己重新写了)

app-id: io.github.glaumar.QRookie
runtime: org.kde.Platform
runtime-version: "6.6"
sdk: org.kde.Sdk
command: qrookie
finish-args:
  - --socket=wayland
  - --socket=fallback-x11
  - --share=ipc
  - --device=all
  - --share=network
  - --persist=.android
cleanup:
  - "*.a"
  - /include
modules:
  - name: p7zip
    buildsystem: simple
    build-commands:
      - cd CPP/7zip/Bundles/Alone
      - make
      - cd ../../../../
      - install -pDm 0755 bin/7za -t "$FLATPAK_DEST/bin/"
    sources:
      - type: archive
        url: https://github.com/p7zip-project/p7zip/archive/refs/tags/v17.05.tar.gz
        sha256: d2788f892571058c08d27095c22154579dfefb807ebe357d145ab2ddddefb1a6

  - name: android-tools
    buildsystem: simple
    build-commands:
      - install -pDm 0755 adb -t "$FLATPAK_DEST/bin/"
    sources:
      - type: archive
        url: https://dl.google.com/android/repository/platform-tools_r34.0.0-linux.zip
        sha256: 8137c2834dea05cb64c1a8bc041ea00fcd43e3a8a29429ad4f25b8ee51efebf6

  - name: qcoro
    buildsystem: cmake-ninja
    sources:
      - type: archive
        url: https://github.com/danvratil/qcoro/archive/refs/tags/v0.10.0.tar.gz
        sha256: b7c8f00273ad27d85814bf4ec93eb6922c75656800a61d11854d36355a4a1aec

  - name: qrookie
    buildsystem: cmake-ninja
    sources:
      - type: archive
        url: https://github.com/glaumar/QRookie/archive/refs/tags/v0.2.1.tar.gz
        sha256: e0f036d7dc3b9408a9bdcd438316e7d6edc98a9ef3fa9fca8dbf42000917b628
{
  "only-arches": ["x86_64"]
}

一些注意事项

  • 如果你不是软件作者,需要事先征得作者同意,即使是开源软件也一样;
  • 权限最小化,如果用了比较宽泛的权限,如:--device=all --filesystem=home 审核可能会要求解释使用原因;
  • 至少保证在 Gnome 和 KDE 下主题显示正常,如果程序确实只在 KDE 下才能正常显示,可以考虑添加环境变量 --env=XDG_CURRENT_DESKTOP=KDE 临时解决;
  • 包括依赖在内,所有 modules 尽可能从源码编译,因为 Flathub 是支持多架构的。上面 QRookie 需要 adb,所以只支持 x86,对于只支持特定架构的,需要添加一个 flathub.json 文件,参考 这里
  • 编译环境不能联网,即不能在 build-args 里使用 --share=network,对于 QRookie 来说这不是问题,但如果打包的软件使用的是 Golang、Rust、C# 等带包管理的语言,则无法联网下载依赖, 解决方法是提前生成每个依赖的 module 并包含到 manifest 里,这里 提供了针对各个语言依赖生成工具;
  • 官方提供了一些常用依赖 shared-modules ,可以的话尽量直接使用这里面的 module

本地编译和检查

编译和安装

flatpak run org.flatpak.Builder --force-clean --sandbox --user --install --install-deps-from=flathub --ccache --mirror-screenshots-url=https://dl.flathub.org/media/ --repo=repo builddir io.github.glaumar.QRookie.yml 

运行

flatpak run io.github.glaumar.QRookie

检查

每次上传前最好都使用工具检查一下,把低级错误处理掉

Manifest

flatpak run --command=flatpak-builder-lint org.flatpak.Builder manifest io.github.glaumar.QRookie.yml

Repo

flatpak run --command=flatpak-builder-lint org.flatpak.Builder repo repo

repo 检查出现 appstream-screenshots-not-mirrored-in-ostree 是正常的,可以忽略,其他错误参考 https://docs.flathub.org/docs/for-app-authors/linter/ 修改

Appstream

flatpak run --command=flatpak-builder-lint org.flatpak.Builder appstream io.github.glaumar.QRookie.metainfo.xml

# 或者
appstreamcli validate io.github.glaumar.QRookie.metainfo.xml

.desktop file

desktop-file-validate io.github.glaumar.QRookie.desktop

上传

1. Fork flathub/flathub

在 Github 上 fork flathub/flathub , 不要勾选 Copy the master branch only

2. Clone 到本地

git clone --branch=new-pr [email protected]:your_github_username/flathub.git

cd flathub

3. 创建新分支

git checkout -b  io.github.glaumar.QRookie

4. 提交文件

# 有其他文件当然也一并提交,这里只有这两个文件
git add io.github.glaumar.QRookie.yml flathub.json

git commit

git push --set-upstream origin io.github.glaumar.QRookie

5. 在 Github 上向 new-pr 分支 pull request

记住是向 flathub 仓库 new-pr 分支 pull request,然后按照提示编辑描述即可,完成后点击 “Create pull request”。之后社区会有志愿者审核,按审核意见修改即可

6. 接收仓库

审核通过后 pull request 会标记为 ready,等待每周的统一合并即可。请求合并之后在 flathub 下会创建一个新仓库(这里是 flathub/io.github.glaumar.QRookie)并转交给你,收到通知后记得接收。合并之后几天内你的应用就会出现在 flathub 首页

软件更新

  1. fork 收的新仓库 (flathub/io.github.glaumar.QRookie
  2. 修改并提交
  3. 创建 pull request
  4. 等待机器人检查通过(这里 可以看到等待队列)
  5. 你拥有 flathub/io.github.glaumar.QRookie 的写入权限,自己 merge 就好(我这里遇到过 github 抽风无法合并,等待 1~2 个小时之后再合并就好了)
  6. 合并之后一般第二天更新就会在 flathub.org 上展示

参考:

知识共享许可协议
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注