Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2022-03-25 01:31:29 +0300
committerlovetox <philipp@hoerist.com>2022-03-26 21:33:58 +0300
commite09c2c82366a286942b2b023d7edcc04a4a9dce8 (patch)
tree6beb8ff10071b012757c3735d6743db65f5e1e48 /scripts
parenta27493cb546c8a1d78f4e00d6332adfed660f1dc (diff)
Refactor CI Pipelines
- Move tasks to python scripts - Rework appveyor build - Add deploy jobs
Diffstat (limited to 'scripts')
-rw-r--r--scripts/ci/deploy.py97
-rwxr-xr-xscripts/ci/sdist.py50
2 files changed, 147 insertions, 0 deletions
diff --git a/scripts/ci/deploy.py b/scripts/ci/deploy.py
new file mode 100644
index 000000000..8e77c6644
--- /dev/null
+++ b/scripts/ci/deploy.py
@@ -0,0 +1,97 @@
+import os
+import sys
+from ftplib import FTP_TLS, ftpcp
+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'
+
+console = Console()
+
+
+def ftp_connection(func: Any) -> Any:
+ @functools.wraps(func)
+ def func_wrapper(filedir: Path) -> None:
+ ftp = FTP_TLS(FTP_URL, FTP_USER, FTP_PASS)
+ console.print('Successfully connected to', FTP_URL)
+ func(ftp, filedir)
+ ftp.quit()
+ console.print('Quit')
+ return
+ return func_wrapper
+
+
+def get_release_folder_from_tag(tag: str) -> str:
+ numbers = tag.split('.')
+ return '.'.join(numbers[:2])
+
+
+def get_gajim_tag() -> str:
+ tag = os.environ.get('CI_COMMIT_TAG')
+ if tag is None:
+ exit('No tag found')
+ return tag.removesuffix('gajim-')
+
+
+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:
+ dir_list = get_dir_list(ftp)
+ if dirname not in dir_list:
+ ftp.mkd(dirname)
+
+
+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)
+
+
+def get_deploy_method() -> str:
+ deploy_type = os.environ['DEPLOY_TYPE']
+ is_nightly = bool(os.environ.get('GAJIM_NIGHTLY_BUILD'))
+ if is_nightly:
+ return f'deploy_{deploy_type}_nightly'
+ return f'deploy_{deploy_type}_release'
+
+
+@ftp_connection
+def deploy_windows_nightly(ftp: FTP_TLS, filedir: Path) -> None:
+ ftp.cwd(WINDOWS_NIGHTLY_FOLDER)
+ upload_all_from_dir(ftp, filedir)
+
+
+@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)
+ upload_all_from_dir(ftp, filedir)
+
+
+@ftp_connection
+def deploy_linux_nightly():
+ raise NotImplementedError
+
+
+@ftp_connection
+def deploy_linux_release():
+ raise NotImplementedError
+
+
+if __name__ == '__main__':
+ filedir = Path(sys.argv[1])
+ current_module = sys.modules[__name__]
+ method = getattr(current_module, get_deploy_method())
+ method(filedir)
diff --git a/scripts/ci/sdist.py b/scripts/ci/sdist.py
new file mode 100755
index 000000000..8aeda48b8
--- /dev/null
+++ b/scripts/ci/sdist.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+import io
+import zipfile
+import subprocess
+import shutil
+from pathlib import Path
+import requests
+
+PLUGINS = [
+ 'plugin_installer',
+]
+
+PLUGINS_BASE_URL = 'https://ftp.gajim.org'
+PLUGINS_FOLDER = Path('./gajim/data/plugins')
+
+
+def get_plugins_url(plugin):
+ return f'{PLUGINS_BASE_URL}/plugins_master_zip/{plugin}.zip'
+
+
+def extraxt_zip(zip_bytes, path):
+ print('Extract to', path)
+ with zipfile.ZipFile(io.BytesIO(zip_bytes)) as zip_file:
+ zip_file.extractall(path)
+
+
+def download_plugins():
+ PLUGINS_FOLDER.mkdir(parents=True)
+ for plugin in PLUGINS:
+ url = get_plugins_url(plugin)
+ print('Download', url)
+ req = requests.get(url)
+ req.raise_for_status()
+ extraxt_zip(req.content, PLUGINS_FOLDER)
+
+
+def setup():
+ print('Setup')
+ subprocess.call(['python3', 'setup.py', 'sdist'])
+
+
+def cleanup():
+ print('Cleanup')
+ shutil.rmtree(PLUGINS_FOLDER)
+
+
+download_plugins()
+setup()
+cleanup()