Skip to content

Commit

Permalink
Add Makefile target for automatic version bump
Browse files Browse the repository at this point in the history
All the Makefiles for the different NIPAP components now have a new
target called 'bumpversion'. It will bump up the version based on the
content of the NEWS file in the project root. sed and the new
news2dch.py script is used to update individual files containing version
information and the debian/changelog respectively.

Fixes #435. This actually accomplishes more than we originally set out
to do with #435 but I guess that is ok ;)
  • Loading branch information
plajjan committed Jan 8, 2014
1 parent b8c7516 commit 3c9291f
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -14,6 +14,7 @@ all:
@echo "make builddeb - Generate a deb package"
@echo "make clean - Get rid of scratch and byte files"
@echo "make debrepo - Create Packages.gz file suitable for github apt repo"
@echo "make bumpversion - Bump version to latest in NEWS file"

source:
for PROJ in $(SUBPROJ); do \
Expand Down Expand Up @@ -61,3 +62,8 @@ clean:
for PROJ in $(SUBPROJ); do \
cd $$PROJ; make clean; cd ..; \
done

bumpversion:
for PROJ in $(SUBPROJ); do \
cd $$PROJ; make bumpversion; cd ..; \
done
8 changes: 8 additions & 0 deletions nipap-cli/Makefile
Expand Up @@ -12,6 +12,7 @@ all:
@echo "make install - Install on local system"
@echo "make buildrpm - Generate a rpm package"
@echo "make builddeb - Generate a deb package"
@echo "make bumpversion - Bump version to latest in ../NEWS file"
@echo "make clean - Get rid of scratch and byte files"

source:
Expand Down Expand Up @@ -45,3 +46,10 @@ clean:
.pc/ debian/$(PROJECT).debhelper.log debian/$(PROJECT).postinst.debhelper \
debian/$(PROJECT).prerm.debhelper debian/$(PROJECT).substvars nipap.1
find . -name '*.pyc' -delete

VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
bumpversion:
# replace version number in nipap_cli/__init__.py
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' nipap_cli/__init__.py
# update debian/changelog
../utilities/news2dch.py ../NEWS debian/changelog
10 changes: 10 additions & 0 deletions nipap-www/Makefile
Expand Up @@ -12,6 +12,7 @@ all:
@echo "make install - Install on local system"
@echo "make buildrpm - Generate a rpm package"
@echo "make builddeb - Generate a deb package"
@echo "make bumpversion - Bump version to latest in ../NEWS file"
@echo "make clean - Get rid of scratch and byte files"

source:
Expand Down Expand Up @@ -45,3 +46,12 @@ clean:
find . -name '*.pyc' -delete
rm -rf data/sessions/container_file/*
rm -rf data/sessions/container_file_lock/*

VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
bumpversion:
# replace version number in nipapwww/__init__.py
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' nipapwww/__init__.py
# replace version number in nipap_www.egg-info/PKG-INFO
sed -i 's/^Version:.*/Version: $(VER)/' nipap_www.egg-info/PKG-INFO
# update debian/changelog
../utilities/news2dch.py ../NEWS debian/changelog
8 changes: 8 additions & 0 deletions nipap/Makefile
Expand Up @@ -12,6 +12,7 @@ all:
@echo "make install - Install on local system"
@echo "make buildrpm - Generate a rpm package"
@echo "make builddeb - Generate a deb package"
@echo "make bumpversion - Bump version to latest in ../NEWS file"
@echo "make clean - Get rid of scratch and byte files"

source:
Expand Down Expand Up @@ -50,3 +51,10 @@ clean:
debian/nipap-common.postinst.debhelper \
debian/nipap-common.prerm.debhelper debian/nipap-common.substvars
find . -name '*.pyc' -delete

VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
bumpversion:
# replace version number in nipap/__init__.py
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' nipap/__init__.py
# update debian/changelog
../utilities/news2dch.py ../NEWS debian/changelog
8 changes: 8 additions & 0 deletions pynipap/Makefile
Expand Up @@ -11,6 +11,7 @@ all:
@echo "make install - Install on local system"
@echo "make buildrpm - Generate a rpm package"
@echo "make builddeb - Generate a deb package"
@echo "make bumpversion - Bump version to latest in ../NEWS file"
@echo "make clean - Get rid of scratch and byte files"

source:
Expand Down Expand Up @@ -42,3 +43,10 @@ clean:
$(PYTHON) setup.py clean
rm -rf build/ MANIFEST dist/ debian/python-pynipap* debian/files
find . -name '*.pyc' -delete

VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
bumpversion:
# replace version number in pynipap.py
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' pynipap.py
# # update debian/changelog
../utilities/news2dch.py ../NEWS debian/changelog
107 changes: 107 additions & 0 deletions utilities/news2dch.py
@@ -0,0 +1,107 @@
#!/usr/bin/python
"""
Copy content of NEWS file into dch file.
This is a bit of a hack but it works :)
"""

import re
import sys
from distutils.version import StrictVersion


class NewsFile:
def __init__(self, filename):
self.latest_version = None
self.raw_content = []
# list of versions
self.versions = []
# entries indexed by version
self.entries = {}

self._readfile(filename)
self._parse()


def _readfile(self, filename):
""" Read content of specified NEWS file
"""
f = open(filename)
self.content = f.readlines()
f.close()


def _parse(self):
""" Parse content of NEWS file
"""
cur_ver = None
cur_line = None
for line in self.content:
m = re.match('Version ([0-9]+\.[0-9]+\.[0-9]+)', line)
if m:
cur_ver = m.group(1)
self.versions.append(cur_ver)
self.entries[cur_ver] = []
cur_entry = self.entries[cur_ver]
if self.latest_version is None or StrictVersion(m.group(1)) > StrictVersion(self.latest_version):
self.latest_version = m.group(1)
elif cur_ver:
m = re.match(' \* (.*)', line)
if m:
cur_entry.append(m.group(1).strip())
elif not re.match('-------', line) and re.match(' *[^$]+', line):
cur_entry[-1] += " " + line.strip()


import subprocess
class DchFile(NewsFile):
def _parse(self):
""" Parse content of DCH file
"""
cur_ver = None
cur_line = None
for line in self.content:
m = re.match('[^ ]+ \(([0-9]+\.[0-9]+\.[0-9]+)-[0-9]+\) [^ ]+; urgency=[^ ]+', line)
if m:
cur_ver = m.group(1)
self.versions.append(cur_ver)
self.entries[cur_ver] = []
cur_entry = self.entries[cur_ver]
if self.latest_version is None or StrictVersion(cur_ver) > StrictVersion(self.latest_version):
self.latest_version = m.group(1)
elif cur_ver:
m = re.match(' \* (.*)', line)
if m:
cur_entry.append(m.group(1).strip())
elif not re.match('$', line) and re.match(' *[^$]+', line):
cur_entry[-1] += " " + line.strip()


def remove_last_entry(self):
# hehehe, calling sed from python <3
subprocess.call(['sed', '-i', 'debian/changelog', '-e', '1,/--/d', '-e', '1,1d'])


def add_entry(self, version, entry):
"""
"""
if version in self.entries:
subprocess.call(['dch', '-D', 'stable', '--force-distribution', '--append', entry])
self.entries[version].append(entry)
else:
subprocess.call(['dch', '-D', 'stable', '--force-distribution', '-v', version, entry])
self.entries[version] = []
self.entries[version].append(entry)


if __name__ == '__main__':
df = DchFile(sys.argv[2])
nf = NewsFile(sys.argv[1])
# if latest version in DCH is same as in NEWS, remove whole block from DCH
# so we can readd entries
if nf.latest_version == df.versions[0]:
df.remove_last_entry()

# add entries to DCH from latest version in NEWS file
for entry in nf.entries[nf.latest_version]:
df.add_entry(nf.latest_version + "-1", entry)

0 comments on commit 3c9291f

Please sign in to comment.