1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/flatpak/update_flathub_descriptor_dependencies.py

132 lines
5.0 KiB
Python
Raw Normal View History

chore(CI): Use docker for CI scripts Motiviation: * Reproducing issues in CI is currently difficult * Predicting issues in CI is currently difficult if you are not on ubuntu 18.04 * Reproducing issues submitted from other distros is currently done by creating a VM of that distro and building qtox for it locally * Documentation for how to build on different distros is out of date * Issues on non-ubuntu distributions are not caught by CI * Cross compiling for windows locally is not trivial * Iterating when working with custom build scripts is slow, scripts don't necessarily support re-running without re-starting the docker container and re-building qtox again * Updating dependencies is a pain Changes: * docker-compose file has been added to the root of our repo. After `docker compose run --rm ubuntu` (or other supported distros), you are ready to compile and run qtox * Dependencies are owned by dependency install scripts in buildscripts/. This allows us to use the same exact dependencies in our OSX/windows/linux scripts * New docker images have been added for a variety of distributions. These are now run in CI in a variety of configurations * Docker images are cached in CI so rebuild time for the majority of jobs is quite quick * Build scripts have been trimmed to leverage state of docker containers. * Windows build script no longer installs anything, dependencies are now managed by the windows_builder docker images * Build scripts should now be easily re-runnable. Usage is now `docker compose run --rm <image>` and then run the scripts * All artifacts are now uploaded to github after build, this means we can take an appimage/flatpak/exe/dmg for any given PR and try it out without having to build it ourselves Notes: * Docker image size is quite important. We have a maximum of 5GB cache space on github actions. The majority of the linux distro docker images cache at ~300-400MB, which gives us room to test ~6 distros after accounting for the sizes of flatpak/windows docker images * Docker layer ordering is relatively intentional. Approximate order should be that large dependencies that change infrequently should be farther up. This lowers the amount of rebuilding we have to do when dependencies are updated * download_xxx.sh scripts are the cleanest way I could find to implement a shared dependency map between osx scripts and docker containers. Although it would be nice to have a single dependency mapping file, splitting it into individual scripts allows us to only rebuild some docker layers when dependencies are updated. * Github actions are split between docker image building and docker image use. This allows us to re-use the same docker images for multiple jobs, but only build it once * Unfortunately I could not find a way to de-duplicate the stitching between jobs, so we have a lot of copy pasta in that area
2021-11-08 13:27:45 +08:00
#!/usr/bin/env python3
# Copyright © 2021 by The qTox Project Contributors
#
# This program is libre software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from argparse import ArgumentParser
from pathlib import Path
import re
import tempfile
import json
import unittest
import subprocess
QTOX_ROOT = Path(__file__).parent.parent
DOWNLOAD_FILE_PATHS = QTOX_ROOT / 'buildscripts' / 'download'
def parse_args():
parser = ArgumentParser(description="""
Update dependencies of a flathub manifest to match the versions used by
qtox. This script will iterate over all known dependencies in the manifest
and replace their tags with the ones specified by our download_xxx.sh
scripts. The commit hash for the tag will be replaced with whatever is
currently in the git remote
""")
parser.add_argument(
"--flathub-manifest",
help="Path to flathub manifest",
required=True,
dest="flathub_manifest_path")
parser.add_argument(
"--output",
help="Output manifest path",
required=True,
dest="output_manifest_path")
return parser.parse_args()
VERSION_EXTRACT_REGEX=re.compile(".*_VERSION=(.*)")
def find_version(download_script_path):
"""
Find the version specified for a given dependency by parsing its download script
"""
# Unintelligent regex parsing, but it will have to do.
# Hope there is no shell expansion in our version info, otherwise we'll have
# to do something a little more intelligent
with open(download_script_path) as f:
script_content = f.read()
matches = VERSION_EXTRACT_REGEX.search(script_content, re.MULTILINE)
return matches.group(1)
class FindVersionTest(unittest.TestCase):
def test_version_parsing(self):
# Create a dummy download script and check that we can extract the version from it
with tempfile.TemporaryDirectory() as d:
sample_download_script = """
#!/bin/bash
source "$(dirname "$0")"/common.sh
TEST_VERSION=1.2.3
TEST_HASH=:)
download_verify_extrat_tarball \
https://test_site.com/${TEST_VERSION} \
${TEST_HASH}
"""
sample_download_script_path = d + '/test_script.sh'
with open(sample_download_script_path, 'w') as f:
f.write(sample_download_script)
self.assertEqual(find_version(sample_download_script_path), "1.2.3")
def load_flathub_manifest(flathub_manifest_path):
with open(flathub_manifest_path) as f:
return json.load(f)
def commit_from_tag(url, tag):
git_output = subprocess.run(
['git', 'ls-remote', url, f"{tag}^{{}}"], check=True, stdout=subprocess.PIPE)
commit = git_output.stdout.split(b'\t')[0]
return commit.decode()
class CommitFromTagTest(unittest.TestCase):
def test_commit_from_tag(self):
self.assertEqual(commit_from_tag(str(QTOX_ROOT), "v1.17.3"), "c0e9a3b79609681e5b9f6bbf8f9a36cb1993dc5f")
def update_source(module, tag):
module_source = module["sources"][0]
module_source["tag"]= tag
module_source["commit"] = commit_from_tag(module_source["url"], module_source["tag"])
def main(flathub_manifest_path, output_manifest_path):
flathub_manifest = load_flathub_manifest(flathub_manifest_path)
sqlcipher_version = find_version(DOWNLOAD_FILE_PATHS / 'download_sqlcipher.sh')
sodium_version = find_version(DOWNLOAD_FILE_PATHS / 'download_sodium.sh')
toxcore_version = find_version(DOWNLOAD_FILE_PATHS / 'download_toxcore.sh')
toxext_version = find_version(DOWNLOAD_FILE_PATHS / 'download_toxext.sh')
toxext_messages_version = find_version(DOWNLOAD_FILE_PATHS / 'download_toxext_messages.sh')
for module in flathub_manifest["modules"]:
if module["name"] == "sqlcipher":
update_source(module, f"v{sqlcipher_version}")
elif module["name"] == "libsodium":
update_source(module, sodium_version)
elif module["name"] == "c-toxcore":
update_source(module, f"v{toxcore_version}")
elif module["name"] == "toxext":
update_source(module, f"v{toxext_version}")
elif module["name"] == "tox_extension_messages":
update_source(module, f"v{toxext_messages_version}")
with open(output_manifest_path, 'w') as f:
json.dump(flathub_manifest, f, indent=4)
if __name__ == '__main__':
main(**vars(parse_args()))