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

Improved versioning #738

Merged
merged 10 commits into from
Nov 19, 2023
21 changes: 0 additions & 21 deletions .bumpversion.cfg

This file was deleted.

14 changes: 11 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ jobs:
steps:
- name: Prepare repo
uses: actions/checkout@v2
# Fetch history, so we also fetch the previous tag for deriving
# the version number
with:
fetch-depth: 0
- name: Install system packages
# It would be good to cache the GNOME Sdk, as it
# is rather big to download each time.
Expand All @@ -105,10 +109,14 @@ jobs:
- name: Export bundle and try to install it
run: |
mkdir -p dist
flatpak build-bundle --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo build/flatpak/repo dist/Hamster.flatpak org.gnome.Hamster
flatpak --user -y install dist/Hamster.flatpak
# Note: For pull requests, this version includes the git hash
# of the autogenerated *merge* commit, not the original
# to-be-merged commit (because that's also what is tested).
VERSION=$(python src/hamster/version.py)
flatpak build-bundle --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo build/flatpak/repo "dist/Hamster-$VERSION.flatpak" org.gnome.Hamster
flatpak --user -y install "dist/Hamster-$VERSION.flatpak"
- name: Upload built artifact
uses: actions/upload-artifact@v2
with:
name: Flatpak application
path: dist/Hamster.flatpak
path: dist/*.flatpak
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>org.gnome.Hamster.GUI</id>
<id>org.gnome.Hamster</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0+ and CC-BY-SA-3.0</project_license>
<name>Hamster</name>
Expand Down Expand Up @@ -44,6 +44,10 @@
</screenshots>
​<translation type="gettext">hamster</translation>
<url type="homepage">https://github.com/projecthamster/hamster/wiki</url>
<releases>
<!-- Provide a (clearly) fake date, otherwise flatpak will ignore the entry -->
<release version="@VERSION@" date="1980-01-01" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date should be an easter egg: "2007-08-01" Toms first commit to the repo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that such a date might actually look like its meaningful, 1980-01-01 is even more clearly invalid/fake. I'm not entirely sure where this date will actually show up, though, but I'm inclined to leave it as is?

</releases>
<provides>
<binary>hamster</binary>
</provides>
Expand Down
8 changes: 7 additions & 1 deletion data/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ def build(ctx):
ctx(features='glib2',
settings_schema_files=['org.gnome.hamster.gschema.xml'])

ctx.install_files('${DATADIR}/metainfo', 'org.gnome.Hamster.GUI.metainfo.xml')
filename = "org.gnome.Hamster.metainfo.xml"
ctx(features = "subst",
source= "%s.in" % filename,
target= "%s" % filename,
dict = ctx.env,
install_path = "${DATADIR}/metainfo"
)

filename = "org.gnome.Hamster.GUI.desktop"
ctx(features = "subst",
Expand Down
18 changes: 0 additions & 18 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/hamster/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreleased
15 changes: 3 additions & 12 deletions src/hamster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@
from gi.repository import Gtk as gtk

from hamster.lib import default_logger
from hamster.version import get_version


logger = default_logger(__name__)

try:
# defs.py is created by waf from defs.py.in
from hamster import defs
__version__ = defs.VERSION
installed = True
except ImportError:
# if defs is not there, we are running from sources
from subprocess import getstatusoutput
rc, output = getstatusoutput("git describe --tags --always --dirty=+")
__version__ = "3.0.2" if rc else "{} (uninstalled)".format(output)
installed = False
del getstatusoutput, rc, output
(__version__, installed) = get_version()

# cleanup namespace
del get_version
del default_logger
del gtk # performance is retained
47 changes: 47 additions & 0 deletions src/hamster/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Should not normally be used directly, use hamster.__version__ and
# hamster.installed instead

def get_installed_version():
try:
# defs.py is created by waf from defs.py.in
from hamster import defs
return defs.VERSION
except ImportError:
# if defs is not there, we are running from sources
return None

def get_uninstalled_version():
# If available, prefer the git version, otherwise fall back to
# the VERSION file (which is meaningful only in released
# versions)
from subprocess import getstatusoutput
rc, output = getstatusoutput("git describe --tags --always --dirty=+")
if rc == 0:
import re
# Strip "v" prefix that is used in git tags
return re.sub(r'^v', '', output)
else:
from pathlib import Path
with open(Path(__file__).parent / 'VERSION', 'r') as f:
return f.read()

def get_version():
"""
Figure out the hamster version.

Returns a tuple with the version string and wether we are installed or not.
"""

version = get_installed_version()
if version is not None:
return (version, True)

version = get_uninstalled_version()
return ("{} (uninstalled)".format(version), False)


if __name__ == '__main__':
import sys
# Intended to be called by waf when installing, so only return
# uninstalled version
sys.stdout.write(get_uninstalled_version())
10 changes: 4 additions & 6 deletions wscript
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- python -*-


from subprocess import getstatusoutput
import subprocess

from waflib import Utils


# slight code duplication with hamster/__init__.py, but this is finally cleaner.
rc, output = getstatusoutput("git describe --tags --always --dirty=+")
VERSION = "3.0.2" if rc else output

# Reuse code from hamster to figure out the version number to use
process = subprocess.run(["python3", "src/hamster/version.py"], check=True, stdout=subprocess.PIPE, text=True)
DirkHoffmann marked this conversation as resolved.
Show resolved Hide resolved
VERSION = process.stdout
APPNAME = 'hamster'

top = '.'
Expand Down
Loading