Hatt icon indicating copy to clipboard operation
Hatt copied to clipboard

Build & Publish on Flatpak

Open alexandre-eliot opened this issue 1 year ago • 0 comments

Issue

As a user I would like to be able to download Hatt using the package manager : Flatpak

Briefly discussed in issue 11, I did a bit of research and took some notes that I am publishing here in the hopes that it would be integrated.

Submission

  1. fork the Flathub repository on GitHub with "Copy the master branch only" unchecked.

  2. Clone it locally

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

# Switch into the cloned repository
cd flathub

# Create a new branch with your app’s name
git checkout -b frenchgithubuser-hatt

The name of the branch has no incidence on the submission and at no point in the submission will you need to change it. Doing so will make github close the Pull Request.

  1. Create the app manifest and push it to frenchgithubuser-hatt

See manifest example

Something like this:

# file: org.frenchgithubuser.Hatt.yml
id: io.github.FrenchGithubUser.Hatt
# The runtime is the environment that the application will run in, so you can use dependencies it provides
runtime: org.frenchgithubuser.Platform
runtime-version: "0.3.4"
sdk: org.frenchgithubuser.Sdk
# This is the command that will be run when the application is launched
command: hatt
# These are the permissions that the application needs
# Read more about finishing here: https://docs.flatpak.org/en/latest/manifests.html#finishing
finish-args:
  - --socket=fallback-x11
  - --socket=wayland
  - --socket=pulseaudio
  - --share=network
  - --share=ipc
modules:
  - name: mycoolapp
    # There are other types of buildsystems, like autotools, cmake, cmake-ninja, simple, qmake
    buildsystem: meson
    sources:
      - type: archive
        url: https://github.com/FrenchGithubUser/Hatt/archive/refs/tags/0.3.4.tar.gz
        dest: Hatt
        sha256: e198214acdbb57363561dee2d73f27199999af26c283723067525bd854703e12
        # ^--- We should generate another one
        # Automatically check for updates and create merge requests
        x-checker-data:
          # There are different types of checkers, see the documentation for more information
          type: anitya
          # This is the ID of the project on anitya
          project-id: 1
          url-template: https://github.com/FrenchGithubUser/Hatt/releases/download/v$version/hatt-source-$version.tar.xz

Note : This file can also be formated in json.

  1. Open a pull request against the new-pr branch on GitHub

Please make sure to title the Pull Request with the name of the application. Example "Add org.example.MyAwesomeApp".

Maintenance

In the Flathub repository that has been created after the merge request was treated

You can create a file called flathub.json to control various parameters of the build infrastructure such as :

  • build architecture limitation
  • end of life
  • disable external data checker
  • automatic PR merge
  • import update flag

GitHub Actions

Here is a GitHub action I put together using the documentation and inspired by obs-studio's flatpak github action :

Note that it yet to be tested and thus, might need a bit of tweaking to do to make it work.

name: Flatpak

on:
  release:
    types: [published]
    branches: [main]

jobs:
  publish:
    name: Publish to Flathub
    runs-on: [ubuntu-latest]
    container:
      image: bilelmoussaoui/flatpak-github-actions:gnome-44
      options: --privileged
    strategy:
      matrix:
        arch: [x86_64, aarch64]
      # Don't fail the whole workflow if one architecture fails
      fail-fast: false
    steps:
    - uses: actions/checkout@v4
    # Docker is required by the docker/setup-qemu-action which enables emulation
    - name: Install deps
      if: ${{ matrix.arch != 'x86_64' }}
      run: |
        dnf -y install docker
    - name: Set up QEMU
      if: ${{ matrix.arch != 'x86_64' }}
      id: qemu
      uses: docker/setup-qemu-action@v2
      with:
        platforms: arm64
        submodules: 'recursive'

    - name: Setup build environment
      id: setup
      run: |
        git config --global --add safe.directory $GITHUB_WORKSPACE
        echo "commitHash=$(git rev-parse --short=9 HEAD)" >> $GITHUB_OUTPUT

    - name: Build Flatpak Manifest
      uses: flatpak/flatpak-github-actions/flatpak-builder@v6
      with:
        bundle: french-github-user-${{ steps.setup.outputs.commitHash }}.flatpak
        manifest-path: CI/flatpak/org.frenchgithubuser.Hatt.yml
        cache-key: flatpak-builder-${{ hashFiles('CI/flatpak/org.frenchgithubuser.Hatt.yml') }}
        branch: ${{ matrix.branch }}
        arch: ${{ matrix.arch }}

    - name: Publish
      uses: flatpak/flatpak-github-actions/flat-manager@v4
      with:
        flat-manager-url: https://hub.flathub.org/
        repository: stable
        token: ${{ secrets.FLATHUB_TOKEN }}

alexandre-eliot avatar Nov 24 '23 12:11 alexandre-eliot