jenkins-bot has submitted this change and it was merged. Change subject: Function to set DOC_PATH prefix on publish jobs ......................................................................
Function to set DOC_PATH prefix on publish jobs A Zuul function to generate the sub path needed to publish documentation. Changes merged on a branch and published tags need to land at different places. Examples: refs/tags/1.24.0 -> /1.24.0/ REL1_24 -> /REL1_24/ master -> /master/ (eventually can be made /latest/) The documentation 'publish' jobs triggered on Gerrit change-merged events so we can report back on the Gerrit change that the job has completed. The branch is available in Zuul Change objects with the 'refspec' attribute. Later on, we will be able to publish documentation when a tag is proposed which is generate a ref-updated event caught by the 'publish' pipeline. It is only used to generate MediaWiki releases for now. For those events, the updated reference is the attribute 'ref' in Zuul Change objects. Zuul has the ability to tweak parameters sent to Gearman functions (and thus later on to Jenkins jobs), by registering a function in the layout.yaml file: http://ci.openstack.org/zuul/zuul.html#includes The set_doc_subpath in /zuul/doc_functions.py carry the logic that interprets the change-merged and ref-updated events to generate the proper sub path which is passed to the job as DOC_SUBPATH. Later on we will then be able to trigger the publish jobs via the publish pipeline and have documentation generated for each release \O/ Adjust tox.ini to pass positional arguments to nosetest which let one run a subset of tests: tox -epy27 -- tests/test_zuul_doc_functions.py --verbose Change-Id: I5fbb100294597cbdf029c285fe53b1285a9532c2 --- A tests/test_zuul_doc_functions.py M tox.ini A zuul/doc_functions.py M zuul/layout.yaml 4 files changed, 90 insertions(+), 1 deletion(-) Approvals: Hashar: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/test_zuul_doc_functions.py b/tests/test_zuul_doc_functions.py new file mode 100644 index 0000000..a15ed8f --- /dev/null +++ b/tests/test_zuul_doc_functions.py @@ -0,0 +1,60 @@ +import os +import unittest + +set_doc_subpath = None # defined for flake8 +# Import function +execfile(os.path.join( + os.path.dirname(os.path.abspath(__file__)), + '../zuul/doc_functions.py')) + + +class FakeChange(object): + + def __init__(self, branch, ref=None, refspec=None): + self.branch = branch + if ref: + self.ref = ref + if refspec: + self.refspec = refspec + + +class FakeItemChange(object): + + def __init__(self, *args, **kwargs): + self.change = FakeChange(*args, **kwargs) + + +class TestDocFunctions(unittest.TestCase): + + def assertDocSubpath(self, expected, item): + params = {} + set_doc_subpath(item, None, params) + self.assertIn( + 'DOC_SUBPATH', params, + "Missing parameter: 'DOC_SUBPATH': %s" % expected) + self.assertEqual(expected, params.get('DOC_SUBPATH')) + + def assertNoDocSubpath(self, item): + params = {} + set_doc_subpath(item, None, params) + self.assertNotIn('DOC_SUBPATH', params, + 'DOC_SUBPATH should not be set') + + def test_change_with_no_ref_nor_refspec(self): + self.assertNoDocSubpath(FakeItemChange('master')) + + def test_change_with_ref(self): + self.assertDocSubpath( + 'master', + FakeItemChange('master', refspec='refs/changes/34/1234/8')) + + def test_ref_updated_branch(self): + self.assertDocSubpath( + 'master', + # ref-updated events give the branch ref as a short version! + FakeItemChange('', ref='master')) + + def test_ref_updated_tag(self): + self.assertDocSubpath( + '42.0', + FakeItemChange('', ref='refs/tags/42.0')) diff --git a/tox.ini b/tox.ini index d9b3907..a665e14 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ envlist = py27 [testenv] -commands = nosetests +commands = nosetests {posargs} deps = nose PyYAML diff --git a/zuul/doc_functions.py b/zuul/doc_functions.py new file mode 100644 index 0000000..0022869 --- /dev/null +++ b/zuul/doc_functions.py @@ -0,0 +1,24 @@ +import re + +tag_re = r'^refs/tags/(.*)' + + +def set_doc_subpath(item, job, params): + change = item.change + doc_subpath = '' + + # ref-updated + # Tags: 'refs/tags/foo' + # Branch: 'master' + if hasattr(change, 'ref'): + tag = re.match(tag_re, change.ref) + if tag: + doc_subpath = tag.group(1) + else: + doc_subpath = change.ref + # Changes + elif hasattr(change, 'refspec'): + doc_subpath = change.branch + + if doc_subpath: + params['DOC_SUBPATH'] = doc_subpath diff --git a/zuul/layout.yaml b/zuul/layout.yaml index f304d22..615ab65 100644 --- a/zuul/layout.yaml +++ b/zuul/layout.yaml @@ -16,6 +16,8 @@ # - http://ci.openstack.org/zuul/zuul.html#layout-yaml # - http://ci.openstack.org/zuul/zuul.html#configuration +includes: + - python-file: 'doc_functions.py' pipelines: # Terminology: @@ -327,6 +329,9 @@ # # See: http://docs.python.org/2/library/re.html#search-vs-match + - name: ^.*-publish$ + parameter-function: set_doc_subpath + # Experiment for analytics/kraken repository - name: analytics-kraken voting: false -- To view, visit https://gerrit.wikimedia.org/r/173049 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5fbb100294597cbdf029c285fe53b1285a9532c2 Gerrit-PatchSet: 8 Gerrit-Project: integration/config Gerrit-Branch: master Gerrit-Owner: Hashar <[email protected]> Gerrit-Reviewer: Greg Grossmeier <[email protected]> Gerrit-Reviewer: Hashar <[email protected]> Gerrit-Reviewer: Krinkle <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
