aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2014-07-22 12:40:15 -0500
committerAndy Doan <andy.doan@linaro.org>2014-07-22 12:40:15 -0500
commitf723667b2e1340326d39620a319fc187aafe3169 (patch)
treed8c2e829bf20b0101b538ed2ac19bdb83e5a18be
parente4785c43a6f56d22e17080ddb9a477158c7a8b23 (diff)
Add revision information for deployment
Fixes: https://bugs.linaro.org/show_bug.cgi?id=226 by including either the last commit-id or the tag if available Change-Id: Iecd2a857036429bd37f9d3220853f3c1f575536a
-rw-r--r--templates/header.html2
-rw-r--r--templates_releases/header.html2
-rw-r--r--tests/test_version.py33
-rw-r--r--version.py20
4 files changed, 54 insertions, 3 deletions
diff --git a/templates/header.html b/templates/header.html
index 3a9e1cb..34c2eb3 100644
--- a/templates/header.html
+++ b/templates/header.html
@@ -34,7 +34,7 @@
{% block content %}{% endblock %}
</div>
<div id="footer">
- Running <a href="https://git.linaro.org/infrastructure/linaro-license-protection.git">linaro-license-protection</a> {{ revno }}.
+ Running <a href="https://git.linaro.org/infrastructure/linaro-license-protection.git">linaro-license-protection</a> <a href="https://git.linaro.org/infrastructure/linaro-license-protection.git/commit/{{ revno }}">{{ revno }}</a>.
</div>
</body>
</html>
diff --git a/templates_releases/header.html b/templates_releases/header.html
index 7fd0bb7..133bb1b 100644
--- a/templates_releases/header.html
+++ b/templates_releases/header.html
@@ -34,7 +34,7 @@
{% block content %}{% endblock %}
</div>
<div id="footer">
- Running <a href="https://git.linaro.org/infrastructure/linaro-license-protection.git">linaro-license-protection</a> {{ revno }}.
+ Running <a href="https://git.linaro.org/infrastructure/linaro-license-protection.git">linaro-license-protection</a> <a href="https://git.linaro.org/infrastructure/linaro-license-protection.git/commit/{{ revno }}">{{ revno }}</a>.
</div>
</body>
</html>
diff --git a/tests/test_version.py b/tests/test_version.py
new file mode 100644
index 0000000..af0ef1e
--- /dev/null
+++ b/tests/test_version.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+import unittest
+
+import version
+
+import mock
+
+
+class TestVersion(unittest.TestCase):
+ '''ensure the version module behaves well.'''
+
+ def setUp(self):
+ super(TestVersion, self).setUp()
+ m = mock.patch('subprocess.check_output')
+ self.addCleanup(m.stop)
+ self.subprocess = m.start()
+
+ def test_no_tags(self):
+ self.subprocess.return_value = 'fakehash ('
+ self.assertEquals('fakehash', version._get_version())
+
+ def test_short_tag(self):
+ self.subprocess.return_value = 'fakehash (HEAD, tag: 2014.07, refs'
+ self.assertEquals('2014.07', version._get_version())
+
+ def test_longer_tag(self):
+ self.subprocess.return_value = 'fakehash (HEAD, tag: 2014.07.02, refs'
+ self.assertEquals('2014.07.02', version._get_version())
+
+ def test_invalid_tag(self):
+ self.subprocess.return_value = 'fakehash (HEAD, tag: aaaa.bb, refs'
+ self.assertEquals('fakehash', version._get_version())
diff --git a/version.py b/version.py
index 64d15ad..e8aca2b 100644
--- a/version.py
+++ b/version.py
@@ -1 +1,19 @@
-VERSION = '2014.05'
+import re
+import subprocess
+
+VERSION = None
+
+
+def _get_version():
+ '''return either the tag on HEAD or the shortened commit id if not found'''
+ out = subprocess.check_output(['git', 'log', '--format=%h %d', '-1'])
+ version, ref_names = out.split('(')
+ m = re.match(r'.*tag: (\d{4}\.\d{2}.*?),', ref_names)
+ if m:
+ version = m.group(1)
+ return version.strip()
+
+try:
+ VERSION = _get_version()
+except:
+ VERSION = '???'