diff options
author | lovetox <philipp@hoerist.com> | 2022-03-27 15:56:05 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2022-03-27 15:56:05 +0300 |
commit | 1fda4597a0f9695cd27ef605e4a3f600f9a22636 (patch) | |
tree | e8668d1dc87304b1c4d93a63b2b0a17b951b50c2 /.ci | |
parent | 2bb4f344163c98f5bc2383c89812e11ab7f19f63 (diff) |
chore: CI: Add linux deploy jobs
Diffstat (limited to '.ci')
-rw-r--r-- | .ci/deploy.py | 70 | ||||
-rwxr-xr-x | .ci/sdist.py | 36 |
2 files changed, 72 insertions, 34 deletions
diff --git a/.ci/deploy.py b/.ci/deploy.py index e8099d22d..b2603943e 100644 --- a/.ci/deploy.py +++ b/.ci/deploy.py @@ -1,17 +1,24 @@ +from typing import Any +from typing import Optional + +import functools import os import sys +from datetime import date from ftplib import FTP_TLS from pathlib import Path -import functools -from typing import Any from rich.console import Console + FTP_URL = 'panoramix.gajim.org' FTP_USER = os.environ['FTP_USER'] FTP_PASS = os.environ['FTP_PASS'] -WINDOWS_NIGHTLY_FOLDER = 'win_snap' +WINDOWS_NIGHTLY_FOLDER = 'downloads/snap/win' +LINUX_NIGHTLY_FOLDER = 'downloads/snap' + +RELEASE_FOLDER_BASE = 'downloads' console = Console() @@ -37,24 +44,44 @@ def get_gajim_tag() -> str: tag = os.environ.get('CI_COMMIT_TAG') if tag is None: exit('No tag found') - return tag.removesuffix('gajim-') + return tag.removeprefix('gajim-') + + +def find_linux_tarball(filedir: Path) -> Path: + files = list(filedir.glob('gajim-*.tar.gz')) + if len(files) != 1: + exit('Unknown files found') + return files[0] def get_dir_list(ftp: FTP_TLS) -> list[str]: return [x[0] for x in ftp.mlsd()] -def ensure_folder_exists(ftp: FTP_TLS, dirname: str) -> None: +def create_release_folder(ftp: FTP_TLS, tag: str) -> None: + ftp.cwd(RELEASE_FOLDER_BASE) + folder = get_release_folder_from_tag(tag) dir_list = get_dir_list(ftp) - if dirname not in dir_list: - ftp.mkd(dirname) + if folder not in dir_list: + ftp.mkd(folder) + ftp.cwd(folder) + + +def upload_all_from_dir(ftp: FTP_TLS, filedir: Path) -> None: + for filepath in filedir.iterdir(): + upload_file(ftp, filepath) + +def upload_file(ftp: FTP_TLS, + filepath: Path, + name: Optional[str] = None) -> None: -def upload_all_from_dir(ftp: FTP_TLS, dir: Path) -> None: - for file_path in dir.iterdir(): - console.print('Upload file', file_path.name) - with open(file_path, 'rb') as f: - ftp.storbinary('STOR ' + file_path.name, f) + if name is None: + name = filepath.name + + console.print('Upload file', filepath.name, 'as', name) + with open(filepath, 'rb') as f: + ftp.storbinary('STOR ' + name, f) def get_deploy_method() -> str: @@ -74,20 +101,25 @@ def deploy_windows_nightly(ftp: FTP_TLS, filedir: Path) -> None: @ftp_connection def deploy_windows_release(ftp: FTP_TLS, filedir: Path) -> None: tag = get_gajim_tag() - folder = get_release_folder_from_tag(tag) - ensure_folder_exists(ftp, folder) - ftp.cwd(folder) + create_release_folder(ftp, tag) upload_all_from_dir(ftp, filedir) @ftp_connection -def deploy_linux_nightly(): - raise NotImplementedError +def deploy_linux_nightly(ftp: FTP_TLS, filedir: Path) -> None: + ftp.cwd(LINUX_NIGHTLY_FOLDER) + filepath = find_linux_tarball(filedir) + filename = f'gajim-{date.today().isoformat()}.tar.gz' + upload_file(ftp, filepath, name=filename) @ftp_connection -def deploy_linux_release(): - raise NotImplementedError +def deploy_linux_release(ftp: FTP_TLS, file: Path) -> None: + tag = get_gajim_tag() + create_release_folder(ftp, tag) + filepath = find_linux_tarball(filedir) + filename = f'gajim-{tag}.tar.gz' + upload_file(ftp, filepath, name=filename) if __name__ == '__main__': diff --git a/.ci/sdist.py b/.ci/sdist.py index 8aeda48b8..513338c91 100755 --- a/.ci/sdist.py +++ b/.ci/sdist.py @@ -1,11 +1,16 @@ #!/usr/bin/env python3 import io -import zipfile -import subprocess +import requests import shutil +import subprocess +import zipfile from pathlib import Path -import requests + +from rich.console import Console + +console = Console() + PLUGINS = [ 'plugin_installer', @@ -15,36 +20,37 @@ PLUGINS_BASE_URL = 'https://ftp.gajim.org' PLUGINS_FOLDER = Path('./gajim/data/plugins') -def get_plugins_url(plugin): +def get_plugins_url(plugin: str) -> str: return f'{PLUGINS_BASE_URL}/plugins_master_zip/{plugin}.zip' -def extraxt_zip(zip_bytes, path): - print('Extract to', path) +def extraxt_zip(zip_bytes: bytes, path: Path) -> None: + console.print('Extract to', path) with zipfile.ZipFile(io.BytesIO(zip_bytes)) as zip_file: zip_file.extractall(path) -def download_plugins(): +def download_plugins() -> None: PLUGINS_FOLDER.mkdir(parents=True) for plugin in PLUGINS: url = get_plugins_url(plugin) - print('Download', url) + console.print('Download', url) req = requests.get(url) req.raise_for_status() extraxt_zip(req.content, PLUGINS_FOLDER) -def setup(): - print('Setup') +def setup() -> None: + console.print('Setup') subprocess.call(['python3', 'setup.py', 'sdist']) -def cleanup(): - print('Cleanup') +def cleanup() -> None: + console.print('Cleanup') shutil.rmtree(PLUGINS_FOLDER) -download_plugins() -setup() -cleanup() +if __name__ == '__main__': + download_plugins() + setup() + cleanup() |