Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some metadata when packaging in the metadata.txt #119

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions docs/usage/cli_package.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=
```
:::
19 changes: 19 additions & 0 deletions docs/usage/cli_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=
```
:::
3 changes: 3 additions & 0 deletions qgis_plugin_CI_testing/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ experimental=True

# change icon...
icon=icons/opengisch.png

[tool:qgis-plugin-ci]
commitNumber=
24 changes: 24 additions & 0 deletions qgispluginci/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 13 additions & 2 deletions test/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# standard
import filecmp
import os
import re
import unittest
import urllib.request
from pathlib import Path
Expand All @@ -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
Expand All @@ -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"


Expand Down Expand Up @@ -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()
4 changes: 3 additions & 1 deletion test/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down