diff --git a/qgispluginci/release.py b/qgispluginci/release.py index f916659f..492c6d0f 100644 --- a/qgispluginci/release.py +++ b/qgispluginci/release.py @@ -4,6 +4,7 @@ import logging import os import re +import shutil import sys import tarfile import xmlrpc.client @@ -193,6 +194,16 @@ def create_archive( continue tt.add(m.name) + # add LICENSE if not already in plugin path but available in its parent + parent_folder_license_copied = False + if not Path(f"{parameters.plugin_path}/LICENSE").is_file(): + parent_license = Path(f"{parameters.plugin_path}/../LICENSE") + if parent_license.is_file(): + shutil.copy(parent_license, f"{parameters.plugin_path}/LICENSE") + parent_folder_license_copied = True + with tarfile.open(top_tar_file, mode="a") as tt: + tt.add(f"{parameters.plugin_path}/LICENSE") + # add translation files if add_translations: with tarfile.open(top_tar_file, mode="a") as tt: @@ -265,6 +276,9 @@ def create_archive( info.compress_type = zf.compression zf.writestr(info, fl) + if parent_folder_license_copied: + Path(f"{parameters.plugin_path}/LICENSE").unlink() + logger.debug("-" * 40) logger.debug(f"Files in ZIP archive ({archive_name}):") with zipfile.ZipFile(file=archive_name, mode="r") as zf: diff --git a/test/test_release.py b/test/test_release.py index 3b14556e..98d099d8 100755 --- a/test/test_release.py +++ b/test/test_release.py @@ -16,6 +16,9 @@ import yaml from github import Github, GithubException +# Tests +from utils import can_skip_test_github + # Project from qgispluginci.changelog import ChangelogParser from qgispluginci.exceptions import GithubReleaseNotFound @@ -24,9 +27,6 @@ from qgispluginci.translation import Translation from qgispluginci.utils import replace_in_file -# Tests -from .utils import can_skip_test_github - # If changed, also update CHANGELOG.md RELEASE_VERSION_TEST = "0.1.2" @@ -196,6 +196,7 @@ def test_release_changelog(self): # open archive and compare with ZipFile(archive_name, "r") as zip_file: data = zip_file.read(f"{parameters.plugin_path}/metadata.txt") + license_data = zip_file.read(f"{parameters.plugin_path}/LICENSE") # Changelog self.assertGreater( @@ -204,6 +205,13 @@ def test_release_changelog(self): f"changelog detection failed in release: {data}", ) + # License + self.assertGreater( + license_data.find(bytes("GNU GENERAL PUBLIC LICENSE", "utf8")), + 0, + "license file content mismatch", + ) + # Commit number self.assertEqual(1, len(re.findall(r"commitNumber=\d+", str(data))))