Implementing Flathub CICD with Github Actions

Im trying to package my package my app for flatpak and publish on flathub…
My app is entirely build with CICD (in github actions).
I got the flatpak to build locally, but now i want to build it into a CICD workflow.

I got at the root of my repository a “flatpak” folder containing the buildscript (build-flatpak.sh, app yaml).
The thing im confused about is: How is this supposed to function? I know that i have to fork the flathub repo and then put my .yml file there followed by a pr. From my understanding this now means that the app is available on flathup, problem being: I cant just tell the manifest to download “github.com/.../releases/lateast/linux-portable.tar.gz” for the building process, because it requires a sha hash. Please help me, i have no clue how to do it… (wget, curl, etc, all fail when i try to download the file in the build-flatpak.sh)


# yaml-language-server: $schema=https://raw.githubusercontent.com/flatpak/flatpak-builder/main/data/flatpak-manifest.schema.json

---
app-id: com.myapp.example
runtime: org.freedesktop.Platform
runtime-version: "22.08"
sdk: org.freedesktop.Sdk
command: myapp
separate-locales: false
finish-args:
  - --share=ipc
  - --socket=fallback-x11
  - --socket=wayland
  - --device=dri
  - --socket=pulseaudio
  - --share=network
modules:
  - name: myapp
    buildsystem: simple
    only-arches:
      - x86_64
    build-commands:
      - "./build-flatpak.sh"
    sources:
      - type: file
        url: http://localhost:8080/linux-flatpak.tar.gz #https://github.com/.../releases/latest/linux-flatpak.tar.gz
        sha256: f9a02aad918f962584989344d82edcae89609f241651c3e2c9c5ecba8eee9628
      - type: dir
        path: ../myapp
      - type: file
        path: build-flatpak.sh

#!/bin/bash

set -e

set -x

# No spaces in project name.

projectName=myapp

projectId=com.myapp.example

executableName=myapp

# ------------------------------- Build Flatpak ----------------------------- #

# Extract portable Flutter build.

mkdir -p $projectName

tar -xf linux-flatpak.tar.gz -C $projectName

# Copy the portable app to the Flatpak-based location.

cp -r $projectName /app/

chmod +x /app/$projectName/$executableName

mkdir -p /app/bin

ln -s /app/$projectName/$executableName /app/bin/$executableName

# Install the icon. (Omit for now, we got no svg icon)

#iconDir=/app/share/icons/hicolor/scalable/apps

#mkdir -p $iconDir

#cp -r assets/icons/$projectId.svg $iconDir/

# Install the desktop file.

desktopFileDir=/app/share/applications

mkdir -p $desktopFileDir

cp -r packaging/flatpak/$projectId.desktop $desktopFileDir/

# Install the AppStream metadata file.

metadataDir=/app/share/metainfo

mkdir -p $metadataDir

cp -r packaging/flatpak/$projectId.metainfo.xml $metadataDir/

You can compute a sha on your PC, when you have downloaded the release and then run sha256sum <NameOfFile>. Then add that sha to your config.

the thing is that i dont want to manually make releases, comlute sha hashes and pr the changes into the flathub repo… the app is moving fast ish and having the Continious Deploymant part of CICD for flatpak would be nice… for android and ios, fastlane exist, heck, even the microsoft store has a way for continious deployment and i want to do something similar for flatpak or ill forget about it and itll get stuck on a old version, etc…
(If flathub had a api to upload precompiled .flazpak files, i could make that work, but having the manifest require a sha hash and it being in a seperate repository is just suboptimal in this case. -\[••]/-)

You can write a script, that hashes the build and commits that to git.

When external builds are allowed by flathub, you should also be able to use GitHub - flatpak/flatpak-github-actions: Build your Flatpak application using Github Actions to publish

thing is your build-flatpak.sh script do stuff that your build system should do and that is not specific to flatpak.

Also there is a flatpak github action available that simplify most of it.

You manifest doesn’t seem to build anything but rather just download binaries, which is really not the best way.

oh, thats what ive been searching for, thanks

good to know, i just followed a guide i found and tried to build from there…
i already got a action to build the binaries, so flatpak packaging should go into there?

Yes, ideally, you would be building from source directly into a flatpak

okay, thanks, ill try and figure it out…
Is there a “cheatsheet” for the flatpak manifest yml?

Not that I know of.

There is https://docs.flathub.org/ which you probably know.

But with most advanced stuff, I end up searching through Flathub · GitHub (code search) to see if somebody else solved it. (that might not help you with your pipeline itself)

1 Like