Skip to content

Commit

Permalink
If LICENSE is missing from the plugin path but available in the paren…
Browse files Browse the repository at this point in the history
…t path when packaging, include that (#307)

@m-kuhn , @suricactus , as discussed to fix qfieldsync releases.
  • Loading branch information
Guts authored Aug 2, 2024
2 parents b8c8bbd + 8e5ddf1 commit 90f3a7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 14 additions & 0 deletions qgispluginci/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import re
import shutil
import sys
import tarfile
import xmlrpc.client
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 11 additions & 3 deletions test/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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(
Expand All @@ -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))))

Expand Down

0 comments on commit 90f3a7d

Please sign in to comment.