From 13c6247d3409d4d77658860f8dd9c8d33e55fa51 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Wed, 31 Jul 2024 20:04:51 +0700 Subject: [PATCH 1/2] If LICENSE is missing from the plugin path but available in the parent path when packaging, include that --- qgispluginci/release.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qgispluginci/release.py b/qgispluginci/release.py index f916659f..f845938f 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(str(parent_license.resolve()), 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: + os.remove(f"{parameters.plugin_path}/LICENSE") + logger.debug("-" * 40) logger.debug(f"Files in ZIP archive ({archive_name}):") with zipfile.ZipFile(file=archive_name, mode="r") as zf: From 8e5ddf150ac362b12e0cf1a1b47d600cfef271f6 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 1 Aug 2024 16:55:33 +0700 Subject: [PATCH 2/2] Address review --- qgispluginci/release.py | 6 +++--- test/test_release.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/qgispluginci/release.py b/qgispluginci/release.py index f845938f..492c6d0f 100644 --- a/qgispluginci/release.py +++ b/qgispluginci/release.py @@ -199,7 +199,7 @@ def create_archive( 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(str(parent_license.resolve()), f"{parameters.plugin_path}/LICENSE") + 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") @@ -277,8 +277,8 @@ def create_archive( zf.writestr(info, fl) if parent_folder_license_copied: - os.remove(f"{parameters.plugin_path}/LICENSE") - + 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))))