From 5a783df096dacf84bc78a00e416f0c195cfa3c46 Mon Sep 17 00:00:00 2001
From: Jan Mach <jan.mach@cesnet.cz>
Date: Tue, 30 May 2017 10:21:15 +0200
Subject: [PATCH] Propagating build number to Grunt and documentation.

Build number from Buildbot system now gets propagated to Grunt and autogenerated documentation. This feature is intended to be used for development (unstable) builds to somehow autoincrement the package version number. For production distributions this will be skipped and developer still has to set the desired version number manually. (Redmine issues: #3361 and #3387)
---
 Gruntfile.js             | 17 ++++++++++++++++-
 doc/sphinx/conf.py       |  4 ++++
 doc/sphinx/index.rst     |  6 +++++-
 doc/sphinx/metadata.json |  2 +-
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 8a71da71..1e9eda56 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,12 +1,22 @@
 module.exports = function(grunt) {
 
+    // ---------------------------------------------------------------------
+    // Command line options.
+    var distribution = grunt.option('distribution') || 'development';
+    var buildnumber  = grunt.option('buildnumber') || '';
+
     function cbk_dir_size(err, stdout, stderr, cb) {
         grunt.config.set('template.deb-control.options.data.package_size', stdout.trim());
         cb();
     }
 
     function version() {
-        return '<%= meta.version %>';
+        if (distribution == 'development') {
+            return '<%= meta.version %>.' + buildnumber;
+        }
+        else {
+            return '<%= meta.version %>'
+        }
     }
 
     function deb_package_filename() {
@@ -246,6 +256,11 @@ module.exports = function(grunt) {
         grunt.config.set('template.deb-control.options.data.package_version', grunt.template.process(version()));
     });
 
+    // Subtask for displaying current version number.
+    grunt.registerTask('check-version', function() {
+        console.log("Current package version: " + grunt.template.process(version()));
+    });
+
     // Save current state of metadata.
     grunt.registerTask('save-meta', function() {
         try {
diff --git a/doc/sphinx/conf.py b/doc/sphinx/conf.py
index ba0c5ecc..7545d55e 100644
--- a/doc/sphinx/conf.py
+++ b/doc/sphinx/conf.py
@@ -27,6 +27,9 @@ sys.path.insert(0, os.path.abspath('../../lib'))
 with open('metadata.json') as json_metadata_file:
     custom_metadata = json.load(json_metadata_file)
 
+def setup(app):
+    app.add_config_value('build_suite', custom_metadata['suite'], 'env')
+
 # -- General configuration -----------------------------------------------------
 
 # If your documentation needs a minimal Sphinx version, state it here.
@@ -121,6 +124,7 @@ rst_epilog = """
 .. |suite| replace:: *{suite}*
 .. |bversion| replace:: *{bversion}*
 .. |revision| replace:: ``{revision}``
+.. |bnumber| replace:: *- {bnumber}*
 """.format(**custom_metadata)
 
 # -- Options for HTML output ----------------------------------------------
diff --git a/doc/sphinx/index.rst b/doc/sphinx/index.rst
index 9bc1e3ab..df78524a 100644
--- a/doc/sphinx/index.rst
+++ b/doc/sphinx/index.rst
@@ -14,6 +14,11 @@ Welcome to Mentat's documentation!
     * distribution: |codename| (|suite|)
     * Git revision: |revision|
 
+.. ifconfig:: build_suite in ('unstable')
+
+    .. warning::
+
+        This documentation was generated from unstable codebase: |bversion| |bnumber|
 
 Contents:
 --------------------------------------------------------------------------------
@@ -30,4 +35,3 @@ Indices and tables
 * :ref:`genindex`
 * :ref:`modindex`
 * :ref:`search`
-
diff --git a/doc/sphinx/metadata.json b/doc/sphinx/metadata.json
index cee11fca..7a267d0d 100644
--- a/doc/sphinx/metadata.json
+++ b/doc/sphinx/metadata.json
@@ -1 +1 @@
-{"codename":"local","suite": "unstable","bversion":"unknown","revision":"latest"}
+{"codename":"local","suite": "unstable","bversion":"unknown","revision":"latest","bnumber":"unknown"}
-- 
GitLab