1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

flatpak: add tests in CI, add no_dependencies parameter (#2751)

* Similar version restrictions than flatpak_remote tests.

* ...

* Try to work around missing dependencies.

* Revert "Try to work around missing dependencies."

This reverts commit 66a4e38566.

* Add changelog.

* App8 -> App2; make sure that there are two apps App1 and App2.

* Fix forgotten variabe.

* Remove test notices.

* Seems like flatpak no longer supports file:// URLs.

The tests would need to be rewritten to offer the URL via http:// instead.

* Try local HTTP server for URL tests.

* ...

* Lint, add status check.

* Add boilerplate.

* Add 'ps aux'.

* Surrender to -f.

* Work around apparent flatpak bug.

* Fix YAML.

* Improve condition.

* Make sure test reruns behave better.
This commit is contained in:
Felix Fontein 2021-06-08 08:46:20 +02:00 committed by GitHub
parent 94a53adff1
commit bb37b67166
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 255 additions and 140 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "flatpak - add ``no_dependencies`` parameter (https://github.com/ansible/ansible/pull/55452, https://github.com/ansible-collections/community.general/pull/2751)."

View file

@ -6,27 +6,6 @@
# Copyright: (c) 2017 Ansible Project # Copyright: (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# ATTENTION CONTRIBUTORS!
#
# TL;DR: Run this module's integration tests manually before opening a pull request
#
# Long explanation:
# The integration tests for this module are currently NOT run on the Ansible project's continuous
# delivery pipeline. So please: When you make changes to this module, make sure that you run the
# included integration tests manually for both Python 2 and Python 3:
#
# Python 2:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 2.7 flatpak
# Python 3:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 3.6 flatpak
#
# Because of external dependencies, the current integration tests are somewhat too slow and brittle
# to be included right now. I have plans to rewrite the integration tests based on a local flatpak
# repository so that they can be included into the normal CI pipeline.
# //oolongbrothers
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
@ -60,18 +39,28 @@ options:
name: name:
description: description:
- The name of the flatpak to manage. - The name of the flatpak to manage.
- When used with I(state=present), I(name) can be specified as an C(http(s)) URL to a - When used with I(state=present), I(name) can be specified as a URL to a
C(flatpakref) file or the unique reverse DNS name that identifies a flatpak. C(flatpakref) file or the unique reverse DNS name that identifies a flatpak.
- Both C(https://) and C(http://) URLs are supported.
- When supplying a reverse DNS name, you can use the I(remote) option to specify on what remote - When supplying a reverse DNS name, you can use the I(remote) option to specify on what remote
to look for the flatpak. An example for a reverse DNS name is C(org.gnome.gedit). to look for the flatpak. An example for a reverse DNS name is C(org.gnome.gedit).
- When used with I(state=absent), it is recommended to specify the name in the reverse DNS - When used with I(state=absent), it is recommended to specify the name in the reverse DNS
format. format.
- When supplying an C(http(s)) URL with I(state=absent), the module will try to match the - When supplying a URL with I(state=absent), the module will try to match the
installed flatpak based on the name of the flatpakref to remove it. However, there is no installed flatpak based on the name of the flatpakref to remove it. However, there is no
guarantee that the names of the flatpakref file and the reverse DNS name of the installed guarantee that the names of the flatpakref file and the reverse DNS name of the installed
flatpak do match. flatpak do match.
type: str type: str
required: true required: true
no_dependencies:
description:
- If installing runtime dependencies should be omitted or not
- This parameter is primarily implemented for integration testing this module.
There might however be some use cases where you would want to have this, like when you are
packaging your own flatpaks.
type: bool
default: false
version_added: 3.2.0
remote: remote:
description: description:
- The flatpak remote (repository) to install the flatpak from. - The flatpak remote (repository) to install the flatpak from.
@ -94,10 +83,11 @@ EXAMPLES = r'''
name: https://s3.amazonaws.com/alexlarsson/spotify-repo/spotify.flatpakref name: https://s3.amazonaws.com/alexlarsson/spotify-repo/spotify.flatpakref
state: present state: present
- name: Install the gedit flatpak package - name: Install the gedit flatpak package without dependencies (not recommended)
community.general.flatpak: community.general.flatpak:
name: https://git.gnome.org/browse/gnome-apps-nightly/plain/gedit.flatpakref name: https://git.gnome.org/browse/gnome-apps-nightly/plain/gedit.flatpakref
state: present state: present
no_dependencies: true
- name: Install the gedit package from flathub for current user - name: Install the gedit package from flathub for current user
community.general.flatpak: community.general.flatpak:
@ -153,18 +143,21 @@ from ansible.module_utils.basic import AnsibleModule
OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application" OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application"
def install_flat(module, binary, remote, name, method): def install_flat(module, binary, remote, name, method, no_dependencies):
"""Add a new flatpak.""" """Add a new flatpak."""
global result global result
flatpak_version = _flatpak_version(module, binary) flatpak_version = _flatpak_version(module, binary)
command = [binary, "install", "--{0}".format(method)]
if StrictVersion(flatpak_version) < StrictVersion('1.1.3'): if StrictVersion(flatpak_version) < StrictVersion('1.1.3'):
noninteractive_arg = "-y" command += ["-y"]
else: else:
noninteractive_arg = "--noninteractive" command += ["--noninteractive"]
if no_dependencies:
command += ["--no-deps"]
if name.startswith('http://') or name.startswith('https://'): if name.startswith('http://') or name.startswith('https://'):
command = [binary, "install", "--{0}".format(method), noninteractive_arg, name] command += [name]
else: else:
command = [binary, "install", "--{0}".format(method), noninteractive_arg, remote, name] command += [remote, name]
_flatpak_command(module, module.check_mode, command) _flatpak_command(module, module.check_mode, command)
result['changed'] = True result['changed'] = True
@ -279,6 +272,7 @@ def main():
choices=['user', 'system']), choices=['user', 'system']),
state=dict(type='str', default='present', state=dict(type='str', default='present',
choices=['absent', 'present']), choices=['absent', 'present']),
no_dependencies=dict(type='bool', default=False),
executable=dict(type='path', default='flatpak') executable=dict(type='path', default='flatpak')
), ),
supports_check_mode=True, supports_check_mode=True,
@ -287,6 +281,7 @@ def main():
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
remote = module.params['remote'] remote = module.params['remote']
no_dependencies = module.params['no_dependencies']
method = module.params['method'] method = module.params['method']
executable = module.params['executable'] executable = module.params['executable']
binary = module.get_bin_path(executable, None) binary = module.get_bin_path(executable, None)
@ -301,7 +296,7 @@ def main():
module.fail_json(msg="Executable '%s' was not found on the system." % executable, **result) module.fail_json(msg="Executable '%s' was not found on the system." % executable, **result)
if state == 'present' and not flatpak_exists(module, binary, name, method): if state == 'present' and not flatpak_exists(module, binary, name, method):
install_flat(module, binary, remote, name, method) install_flat(module, binary, remote, name, method, no_dependencies)
elif state == 'absent' and flatpak_exists(module, binary, name, method): elif state == 'absent' and flatpak_exists(module, binary, name, method):
uninstall_flat(module, binary, name, method) uninstall_flat(module, binary, name, method)

View file

@ -6,27 +6,6 @@
# Copyright: (c) 2017 Ansible Project # Copyright: (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# ATTENTION CONTRIBUTORS!
#
# TL;DR: Run this module's integration tests manually before opening a pull request
#
# Long explanation:
# The integration tests for this module are currently NOT run on the Ansible project's continuous
# delivery pipeline. So please: When you make changes to this module, make sure that you run the
# included integration tests manually for both Python 2 and Python 3:
#
# Python 2:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 2.7 flatpak_remote
# Python 3:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 3.6 flatpak_remote
#
# Because of external dependencies, the current integration tests are somewhat too slow and brittle
# to be included right now. I have plans to rewrite the integration tests based on a local flatpak
# repository so that they can be included into the normal CI pipeline.
# //oolongbrothers
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type

View file

@ -1,4 +1,4 @@
unsupported shippable/posix/group3
destructive destructive
skip/aix skip/aix
skip/freebsd skip/freebsd
@ -6,4 +6,3 @@ skip/osx
skip/macos skip/macos
skip/rhel skip/rhel
needs/root needs/root
needs/privileged

View file

@ -0,0 +1,65 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import posixpath
import sys
try:
from http.server import SimpleHTTPRequestHandler, HTTPServer
from urllib.parse import unquote
except ImportError:
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
from urllib import unquote
# Argument parsing
if len(sys.argv) != 4:
print('Syntax: {0} <bind> <port> <path>'.format(sys.argv[0]))
sys.exit(-1)
HOST, PORT, PATH = sys.argv[1:4]
PORT = int(PORT)
# The HTTP request handler
class Handler(SimpleHTTPRequestHandler):
def translate_path(self, path):
# Modified from Python 3.6's version of SimpleHTTPRequestHandler
# to support using another base directory than CWD.
# abandon query parameters
path = path.split('?', 1)[0]
path = path.split('#', 1)[0]
# Don't forget explicit trailing slash when normalizing. Issue17324
trailing_slash = path.rstrip().endswith('/')
try:
path = unquote(path, errors='surrogatepass')
except (UnicodeDecodeError, TypeError) as exc:
path = unquote(path)
path = posixpath.normpath(path)
words = path.split('/')
words = filter(None, words)
path = PATH
for word in words:
if os.path.dirname(word) or word in (os.curdir, os.pardir):
# Ignore components that are not a simple file/directory name
continue
path = os.path.join(path, word)
if trailing_slash:
path += '/'
return path
# Run simple HTTP server
httpd = HTTPServer((HOST, PORT), Handler)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()

View file

@ -1,2 +1,3 @@
dependencies: dependencies:
- prepare_tests - prepare_tests
- setup_flatpak_remote

View file

@ -4,8 +4,8 @@
- name: Test addition of absent flatpak (check mode) - name: Test addition of absent flatpak (check mode)
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
remote: flathub remote: dummy-remote
state: present state: present
register: addition_result register: addition_result
check_mode: true check_mode: true
@ -18,8 +18,8 @@
- name: Test non-existent idempotency of addition of absent flatpak (check mode) - name: Test non-existent idempotency of addition of absent flatpak (check mode)
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
remote: flathub remote: dummy-remote
state: present state: present
register: double_addition_result register: double_addition_result
check_mode: true check_mode: true
@ -36,7 +36,7 @@
- name: Test removal of absent flatpak check mode - name: Test removal of absent flatpak check mode
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
state: absent state: absent
register: removal_result register: removal_result
check_mode: true check_mode: true
@ -51,8 +51,8 @@
- name: Test addition of absent flatpak with url (check mode) - name: Test addition of absent flatpak with url (check mode)
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: flathub remote: dummy-remote
state: present state: present
register: url_addition_result register: url_addition_result
check_mode: true check_mode: true
@ -65,8 +65,8 @@
- name: Test non-existent idempotency of addition of absent flatpak with url (check mode) - name: Test non-existent idempotency of addition of absent flatpak with url (check mode)
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: flathub remote: dummy-remote
state: present state: present
register: double_url_addition_result register: double_url_addition_result
check_mode: true check_mode: true
@ -85,7 +85,7 @@
- name: Test removal of absent flatpak with url not doing anything (check mode) - name: Test removal of absent flatpak with url not doing anything (check mode)
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
state: absent state: absent
register: url_removal_result register: url_removal_result
check_mode: true check_mode: true
@ -96,15 +96,14 @@
- url_removal_result is not changed - url_removal_result is not changed
msg: "Removing an absent flatpak shall mark module execution as not changed" msg: "Removing an absent flatpak shall mark module execution as not changed"
# - Tests with present flatpak ------------------------------------------------- # - Tests with present flatpak -------------------------------------------------
# state=present on present flatpak # state=present on present flatpak
- name: Test addition of present flatpak (check mode) - name: Test addition of present flatpak (check mode)
flatpak: flatpak:
name: org.gnome.Calculator name: com.dummy.App2
remote: flathub remote: dummy-remote
state: present state: present
register: addition_present_result register: addition_present_result
check_mode: true check_mode: true
@ -119,7 +118,7 @@
- name: Test removal of present flatpak (check mode) - name: Test removal of present flatpak (check mode)
flatpak: flatpak:
name: org.gnome.Calculator name: com.dummy.App2
state: absent state: absent
register: removal_present_result register: removal_present_result
check_mode: true check_mode: true
@ -132,7 +131,7 @@
- name: Test non-existent idempotency of removal (check mode) - name: Test non-existent idempotency of removal (check mode)
flatpak: flatpak:
name: org.gnome.Calculator name: com.dummy.App2
state: absent state: absent
register: double_removal_present_result register: double_removal_present_result
check_mode: true check_mode: true
@ -149,8 +148,8 @@
- name: Test addition with url of present flatpak (check mode) - name: Test addition with url of present flatpak (check mode)
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Calculator.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
remote: flathub remote: dummy-remote
state: present state: present
register: url_addition_present_result register: url_addition_present_result
check_mode: true check_mode: true
@ -165,7 +164,7 @@
- name: Test removal with url of present flatpak (check mode) - name: Test removal with url of present flatpak (check mode)
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Calculator.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
state: absent state: absent
register: url_removal_present_result register: url_removal_present_result
check_mode: true check_mode: true
@ -178,8 +177,8 @@
- name: Test non-existent idempotency of removal with url of present flatpak (check mode) - name: Test non-existent idempotency of removal with url of present flatpak (check mode)
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Calculator.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App2.flatpakref
remote: flathub remote: dummy-remote
state: absent state: absent
register: double_url_removal_present_result register: double_url_removal_present_result
check_mode: true check_mode: true

View file

@ -30,8 +30,8 @@
- name: Test executable override - name: Test executable override
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
remote: flathub remote: dummy-remote
state: present state: present
executable: nothing-that-exists executable: nothing-that-exists
ignore_errors: true ignore_errors: true
@ -57,5 +57,20 @@
vars: vars:
method: system method: system
always:
- name: Check HTTP server status
async_status:
jid: "{{ webserver_status.ansible_job_id }}"
ignore_errors: true
- name: List processes
command: ps aux
- name: Stop HTTP server
command: >-
pkill -f -- '{{ remote_tmp_dir }}/serve.py'
when: | when: |
ansible_distribution in ('Fedora', 'Ubuntu') ansible_distribution == 'Fedora' or
ansible_distribution == 'Ubuntu' and not ansible_distribution_major_version | int < 16

View file

@ -4,32 +4,58 @@
state: present state: present
become: true become: true
when: ansible_distribution == 'Fedora' when: ansible_distribution == 'Fedora'
- block: - block:
- name: Activate flatpak ppa on Ubuntu - name: Activate flatpak ppa on Ubuntu
apt_repository: apt_repository:
repo: ppa:alexlarsson/flatpak repo: ppa:alexlarsson/flatpak
state: present state: present
mode: '0644' mode: '0644'
when: ansible_lsb.major_release | int < 18
- name: Install flatpak package on Ubuntu - name: Install flatpak package on Ubuntu
apt: apt:
name: flatpak name: flatpak
state: present state: present
become: true
when: ansible_distribution == 'Ubuntu' when: ansible_distribution == 'Ubuntu'
- name: Enable flathub for user
- name: Install dummy remote for user
flatpak_remote: flatpak_remote:
name: flathub name: dummy-remote
state: present state: present
flatpakrepo_url: https://dl.flathub.org/repo/flathub.flatpakrepo flatpakrepo_url: /tmp/flatpak/repo/dummy-repo.flatpakrepo
method: user method: user
- name: Enable flathub for system
- name: Install dummy remote for system
flatpak_remote: flatpak_remote:
name: flathub name: dummy-remote
state: present state: present
flatpakrepo_url: https://dl.flathub.org/repo/flathub.flatpakrepo flatpakrepo_url: /tmp/flatpak/repo/dummy-repo.flatpakrepo
method: system method: system
- name: Remove (if necessary) flatpak for testing check mode on absent flatpak
flatpak:
name: com.dummy.App1
remote: dummy-remote
state: absent
no_dependencies: true
- name: Add flatpak for testing check mode on present flatpak - name: Add flatpak for testing check mode on present flatpak
flatpak: flatpak:
name: org.gnome.Calculator name: com.dummy.App2
remote: flathub remote: dummy-remote
state: present state: present
no_dependencies: true
- name: Copy HTTP server
copy:
src: serve.py
dest: '{{ remote_tmp_dir }}/serve.py'
mode: '0755'
- name: Start HTTP server
command: '{{ remote_tmp_dir }}/serve.py 127.0.0.1 8000 /tmp/flatpak/'
async: 120
poll: 0
register: webserver_status

View file

@ -2,10 +2,11 @@
- name: Test addition - {{ method }} - name: Test addition - {{ method }}
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
remote: flathub remote: dummy-remote
state: present state: present
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: addition_result register: addition_result
- name: Verify addition test result - {{ method }} - name: Verify addition test result - {{ method }}
@ -16,10 +17,11 @@
- name: Test idempotency of addition - {{ method }} - name: Test idempotency of addition - {{ method }}
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
remote: flathub remote: dummy-remote
state: present state: present
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: double_addition_result register: double_addition_result
- name: Verify idempotency of addition test result - {{ method }} - name: Verify idempotency of addition test result - {{ method }}
@ -32,9 +34,10 @@
- name: Test removal - {{ method }} - name: Test removal - {{ method }}
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
state: absent state: absent
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: removal_result register: removal_result
- name: Verify removal test result - {{ method }} - name: Verify removal test result - {{ method }}
@ -45,9 +48,10 @@
- name: Test idempotency of removal - {{ method }} - name: Test idempotency of removal - {{ method }}
flatpak: flatpak:
name: org.gnome.Characters name: com.dummy.App1
state: absent state: absent
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: double_removal_result register: double_removal_result
- name: Verify idempotency of removal test result - {{ method }} - name: Verify idempotency of removal test result - {{ method }}
@ -60,10 +64,11 @@
- name: Test addition with url - {{ method }} - name: Test addition with url - {{ method }}
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: flathub remote: dummy-remote
state: present state: present
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: url_addition_result register: url_addition_result
- name: Verify addition test result - {{ method }} - name: Verify addition test result - {{ method }}
@ -74,10 +79,11 @@
- name: Test idempotency of addition with url - {{ method }} - name: Test idempotency of addition with url - {{ method }}
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
remote: flathub remote: dummy-remote
state: present state: present
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: double_url_addition_result register: double_url_addition_result
- name: Verify idempotency of addition with url test result - {{ method }} - name: Verify idempotency of addition with url test result - {{ method }}
@ -90,25 +96,45 @@
- name: Test removal with url - {{ method }} - name: Test removal with url - {{ method }}
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
state: absent state: absent
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: url_removal_result register: url_removal_result
ignore_errors: true
- name: Verify removal test result - {{ method }} - name: Verify removal test result failed - {{ method }}
# It looks like flatpak has a bug when the hostname contains a port. If this is the case, it emits
# the following message, which we check for. If another error happens, we fail.
# Upstream issue: https://github.com/flatpak/flatpak/issues/4307
# (The second message happens with Ubuntu 18.04.)
assert:
that:
- >-
url_removal_result.msg in [
"error: Invalid branch 127.0.0.1:8000: Branch can't contain :",
"error: Invalid id http:: Name can't contain :",
]
when: url_removal_result is failed
- when: url_removal_result is not failed
block:
- name: Verify removal test result - {{ method }}
assert: assert:
that: that:
- url_removal_result is changed - url_removal_result is changed
msg: "state=absent with url as name shall remove flatpak when present" msg: "state=absent with url as name shall remove flatpak when present"
- name: Test idempotency of removal with url - {{ method }} - name: Test idempotency of removal with url - {{ method }}
flatpak: flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref name: http://127.0.0.1:8000/repo/com.dummy.App1.flatpakref
state: absent state: absent
method: "{{ method }}" method: "{{ method }}"
no_dependencies: true
register: double_url_removal_result register: double_url_removal_result
- name: Verify idempotency of removal with url test result - {{ method }} - name: Verify idempotency of removal with url test result - {{ method }}
assert: assert:
that: that:
- double_url_removal_result is not changed - double_url_removal_result is not changed

View file

@ -1,51 +1,59 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eux set -eux
flatpak install -y --system flathub org.freedesktop.Platform//1.6 org.freedesktop.Sdk//1.6 # Delete traces from last run
rm -rf appdir* dummy-repo.gpg gpg hello.sh repo
echo $'#!/bin/sh\necho hello world' > hello.sh
export NUM=1
flatpak build-init appdir$NUM com.dummy.App$NUM org.freedesktop.Sdk org.freedesktop.Platform 1.6;
flatpak build appdir$NUM mkdir /app/bin;
flatpak build appdir$NUM install --mode=750 hello.sh /app/bin;
flatpak build-finish --command=hello.sh appdir$NUM
flatpak build-export repo appdir$NUM stable
# Create GPG key
mkdir -p gpg mkdir -p gpg
chmod 0700 gpg chmod 0700 gpg
gpg --homedir gpg --batch --passphrase '' --quick-gen-key test@dummy.com future-default default 10y gpg --homedir gpg --batch --passphrase '' --quick-gen-key test@dummy.com future-default default 10y
KEY_ID=$(gpg --homedir=gpg --list-keys --with-colons test@dummy.com | grep fpr: | head -1 | cut -d ':' -f 10) KEY_ID=$(gpg --homedir=gpg --list-keys --with-colons test@dummy.com | grep fpr: | head -1 | cut -d ':' -f 10)
gpg --homedir=gpg --export "${KEY_ID}" > dummy-repo.gpg gpg --homedir=gpg --export "${KEY_ID}" > dummy-repo.gpg
BASE64_PUBLIC_KEY=$(base64 dummy-repo.gpg | tr -d '\n') BASE64_PUBLIC_KEY=$(base64 dummy-repo.gpg | tr -d '\n')
cat > repo/com.dummy.App1.flatpakref <<EOF # Install dependencies
[Flatpak Ref] flatpak install -y --system flathub org.freedesktop.Platform//1.6 org.freedesktop.Sdk//1.6
Title=Dummy App$NUM
Name=com.dummy.App$NUM
Branch=stable
Url=file:///tmp/flatpak/repo
GPGKey=${BASE64_PUBLIC_KEY}
IsRuntime=false
RuntimeRepo=https://flathub.org/repo/flathub.flatpakrepo
EOF
# Add individual flatpaks
echo $'#!/bin/sh\necho hello world' > hello.sh
for NUM in 1 2; do
flatpak build-init appdir${NUM} com.dummy.App${NUM} org.freedesktop.Sdk org.freedesktop.Platform 1.6;
flatpak build appdir${NUM} mkdir /app/bin;
flatpak build appdir${NUM} install --mode=750 hello.sh /app/bin;
flatpak build-finish --command=hello.sh appdir${NUM}
flatpak build-export repo appdir${NUM} stable
cat > repo/com.dummy.App${NUM}.flatpakref <<EOF
[Flatpak Ref]
Title=Dummy App${NUM}
Name=com.dummy.App${NUM}
Branch=stable
Url=file:///tmp/flatpak/repo
GPGKey=${BASE64_PUBLIC_KEY}
IsRuntime=false
RuntimeRepo=https://flathub.org/repo/flathub.flatpakrepo
EOF
done
# Build repository
cat > repo/dummy-repo.flatpakrepo <<EOF cat > repo/dummy-repo.flatpakrepo <<EOF
[Flatpak Repo] [Flatpak Repo]
Title=Dummy Repo Title=Dummy Repo
Url=file:///tmp/flatpak/repo Url=file:///tmp/flatpak/repo
Comment=Dummy repo for ansible module integration testing Comment=Dummy repo for ansible module integration testing
Description=Dummy repo for ansible module integration testing Description=Dummy repo for ansible module integration testing
GPGKey=${BASE64_PUBLIC_KEY} GPGKey=${BASE64_PUBLIC_KEY}
EOF EOF
flatpak build-sign repo --gpg-sign="${KEY_ID}" --gpg-homedir=gpg flatpak build-sign repo --gpg-sign="${KEY_ID}" --gpg-homedir=gpg
flatpak build-update-repo repo --gpg-sign="${KEY_ID}" --gpg-homedir=gpg flatpak build-update-repo repo --gpg-sign="${KEY_ID}" --gpg-homedir=gpg
# Compress repository
tar cvfJ repo.tar.xz repo/ tar cvfJ repo.tar.xz repo/
mv repo.tar.xz files/ mv repo.tar.xz files/
# Cleanup
rm -rf appdir* dummy-repo.gpg gpg hello.sh repo rm -rf appdir* dummy-repo.gpg gpg hello.sh repo