diff --git a/CHANGELOG.md b/CHANGELOG.md index 37229366..733727c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this ## Unreleased +* Add some metadata in the `metadata.txt` when packaging such as commit number, commit SHA1 and date if these keys are presents + ## 2.2.0 - 2022-03-17 -* allow to release a version (1.2.3) which is different from the release tag (v1.2.3) (#120) +* Allow to release a version (1.2.3) which is different from the release tag (v1.2.3) (#120) + +## 2.1.2 - 2022-02-15 + +* Raise an error if a built resource is present in source and the names conflicts by @3nids ## 2.1.1 - 2022-01-20 diff --git a/docs/usage/cli_package.md b/docs/usage/cli_package.md index 56fe106b..160025bb 100644 --- a/docs/usage/cli_package.md +++ b/docs/usage/cli_package.md @@ -28,3 +28,22 @@ optional arguments: If omitted, a git submodule is updated. If specified, git submodules will not be updated/initialized before packaging. ``` + +## Additional metadata + +When packaging the plugin, some extra metadata information can be added if these keys are present in the `metadata.txt`: + +* `commitNumber=` : the commit number in the branch +* `commitSha1=` : the commit ID +* `dateTime=` : the date time in UTC format when the packaging is done + +* :::{tip} +These extra parameters are specific to QGIS Plugin CI, so it's strongly recommended storing them below a dedicated section: + +```ini +[tool:qgis-plugin-ci] +commitNumber= +commitSha1= +dateTime= +``` +::: diff --git a/docs/usage/cli_release.md b/docs/usage/cli_release.md index edc5d5c7..9de9136d 100644 --- a/docs/usage/cli_release.md +++ b/docs/usage/cli_release.md @@ -39,3 +39,22 @@ optional arguments: --osgeo-password OSGEO_PASSWORD The Osgeo password to publish the plugin. ``` + +## Additional metadata + +When packaging the plugin, some extra metadata information can be added if these keys are present in the `metadata.txt`: + +* `commitNumber=` : the commit number in the branch +* `commitSha1=` : the commit ID +* `dateTime=` : the date time in UTC format when the packaging is done + +* :::{tip} +These extra parameters are specific to QGIS Plugin CI, so it's strongly recommended storing them below a dedicated section: + +```ini +[tool:qgis-plugin-ci] +commitNumber= +commitSha1= +dateTime= +``` +::: diff --git a/qgis_plugin_CI_testing/metadata.txt b/qgis_plugin_CI_testing/metadata.txt index d44e31cc..35dc5244 100755 --- a/qgis_plugin_CI_testing/metadata.txt +++ b/qgis_plugin_CI_testing/metadata.txt @@ -23,3 +23,6 @@ experimental=True # change icon... icon=icons/opengisch.png + +[tool:qgis-plugin-ci] +commitNumber= diff --git a/qgispluginci/release.py b/qgispluginci/release.py index 4ffd13e7..e64ca71e 100644 --- a/qgispluginci/release.py +++ b/qgispluginci/release.py @@ -106,6 +106,30 @@ def create_archive( "version={}".format(release_version), ) + # Commit number + replace_in_file( + f"{parameters.plugin_path}/metadata.txt", + r"^commitNumber=.*$", + f"commitNumber={len(list(repo.iter_commits()))}", + ) + + # Git SHA1 + replace_in_file( + f"{parameters.plugin_path}/metadata.txt", + r"^commitSha1=.*$", + f"commitSha1={repo.head.object.hexsha}", + ) + + # Date/time in UTC + date_time = datetime.datetime.now(datetime.timezone.utc).strftime( + "%Y-%m-%dT%H:%M:%SZ" + ) + replace_in_file( + f"{parameters.plugin_path}/metadata.txt", + r"^dateTime=.*$", + f"dateTime={date_time}", + ) + # set the plugin as experimental on a pre-release if is_prerelease: replace_in_file( diff --git a/test/test_release.py b/test/test_release.py index c553d9d3..75668980 100644 --- a/test/test_release.py +++ b/test/test_release.py @@ -3,6 +3,7 @@ # standard import filecmp import os +import re import unittest import urllib.request from pathlib import Path @@ -13,7 +14,6 @@ import yaml from github import Github, GithubException from pytransifex.exceptions import PyTransifexException -from utils import can_skip_test # Project from qgispluginci.changelog import ChangelogParser @@ -23,7 +23,10 @@ from qgispluginci.translation import Translation from qgispluginci.utils import replace_in_file -# if change, also update CHANGELOG.md +# Tests +from .utils import can_skip_test + +# If changed, also update CHANGELOG.md RELEASE_VERSION_TEST = "0.1.2" @@ -173,12 +176,20 @@ 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") + + # Changelog self.assertGreater( data.find(bytes(changelog_lastitems, "utf8")), 0, f"changelog detection failed in release: {data}", ) + # Commit number + self.assertEqual(1, len(re.findall(r"commitNumber=\d+", str(data)))) + + # Commit sha1 not in the metadata.txt + self.assertEqual(0, len(re.findall(r"commitSha1=\d+", str(data)))) + if __name__ == "__main__": unittest.main() diff --git a/test/test_translation.py b/test/test_translation.py index 68a04a8f..89028f61 100644 --- a/test/test_translation.py +++ b/test/test_translation.py @@ -7,12 +7,14 @@ # 3rd party import yaml from pytransifex.exceptions import PyTransifexException -from utils import can_skip_test # project from qgispluginci.parameters import Parameters from qgispluginci.translation import Translation +# Tests +from .utils import can_skip_test + class TestTranslation(unittest.TestCase): def setUp(self):