From 18bdfef857829fefbe2e35449edb2d64dfe5ff80 Mon Sep 17 00:00:00 2001 From: Mike Shal Date: Fri, 9 Oct 2015 09:26:34 -0400 Subject: [PATCH] Bug 1212942 - Add pushdate routes; r=garndt,jlund --- .../mozharness/mozilla/building/buildbase.py | 5 ++ testing/mozharness/scripts/desktop_l10n.py | 6 +++ testing/mozharness/scripts/mobile_l10n.py | 6 +++ testing/taskcluster/mach_commands.py | 50 +++++++++++++++++++ testing/taskcluster/routes.json | 2 + 5 files changed, 69 insertions(+) diff --git a/testing/mozharness/mozharness/mozilla/building/buildbase.py b/testing/mozharness/mozharness/mozilla/building/buildbase.py index 817bb80600a4..b81e0bd3329b 100755 --- a/testing/mozharness/mozharness/mozilla/building/buildbase.py +++ b/testing/mozharness/mozharness/mozilla/building/buildbase.py @@ -1396,12 +1396,17 @@ or run without that action (ie: --no-{action})" repo = self._query_repo() revision = self.query_revision() pushinfo = self.vcs_query_pushinfo(repo, revision) + pushdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(pushinfo.pushdate)) index = self.config.get('taskcluster_index', 'index.garbage.staging') fmt = { 'index': index, 'project': self.buildbot_config['properties']['branch'], 'head_rev': revision, + 'pushdate': pushdate, + 'year': pushdate[0:4], + 'month': pushdate[4:6], + 'day': pushdate[6:8], 'build_product': self.config['stage_product'], 'build_name': self.query_build_name(), 'build_type': self.query_build_type(), diff --git a/testing/mozharness/scripts/desktop_l10n.py b/testing/mozharness/scripts/desktop_l10n.py index f5fb74335559..47673dde38ab 100755 --- a/testing/mozharness/scripts/desktop_l10n.py +++ b/testing/mozharness/scripts/desktop_l10n.py @@ -11,6 +11,7 @@ This script manages Desktop repacks for nightly builds. import os import re import sys +import time import shlex import logging @@ -965,6 +966,7 @@ class DesktopSingleLocale(LocalesMixin, ReleaseMixin, MockMixin, BuildbotMixin, if not repo: self.fatal("Unable to determine repository for querying the push info.") pushinfo = self.vcs_query_pushinfo(repo, revision, vcs='hgtool') + pushdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(pushinfo.pushdate)) routes_json = os.path.join(self.query_abs_dirs()['abs_mozilla_dir'], 'testing/taskcluster/routes.json') @@ -980,6 +982,10 @@ class DesktopSingleLocale(LocalesMixin, ReleaseMixin, MockMixin, BuildbotMixin, 'index': self.config.get('taskcluster_index', 'index.garbage.staging'), 'project': branch, 'head_rev': revision, + 'pushdate': pushdate, + 'year': pushdate[0:4], + 'month': pushdate[4:6], + 'day': pushdate[6:8], 'build_product': self.config['stage_product'], 'build_name': self.query_build_name(), 'build_type': self.query_build_type(), diff --git a/testing/mozharness/scripts/mobile_l10n.py b/testing/mozharness/scripts/mobile_l10n.py index e55c8ec4751e..b0b8381ac49e 100755 --- a/testing/mozharness/scripts/mobile_l10n.py +++ b/testing/mozharness/scripts/mobile_l10n.py @@ -15,6 +15,7 @@ import os import re import subprocess import sys +import time import shlex try: @@ -486,6 +487,7 @@ class MobileSingleLocale(MockMixin, LocalesMixin, ReleaseMixin, revision = self.query_revision() repo = self.query_l10n_repo() pushinfo = self.vcs_query_pushinfo(repo, revision, vcs='hgtool') + pushdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(pushinfo.pushdate)) routes_json = os.path.join(self.query_abs_dirs()['abs_mozilla_dir'], 'testing/taskcluster/routes.json') with open(routes_json) as f: @@ -506,6 +508,10 @@ class MobileSingleLocale(MockMixin, LocalesMixin, ReleaseMixin, 'index': self.config.get('taskcluster_index', 'index.garbage.staging'), 'project': branch, 'head_rev': revision, + 'pushdate': pushdate, + 'year': pushdate[0:4], + 'month': pushdate[4:6], + 'day': pushdate[6:8], 'build_product': self.config['stage_product'], 'build_name': self.query_build_name(), 'build_type': self.query_build_type(), diff --git a/testing/taskcluster/mach_commands.py b/testing/taskcluster/mach_commands.py index db1ed5d79896..f9c9f2375a64 100644 --- a/testing/taskcluster/mach_commands.py +++ b/testing/taskcluster/mach_commands.py @@ -11,6 +11,8 @@ import os import json import copy import sys +import time +from collections import namedtuple from mach.decorators import ( CommandArgument, @@ -203,6 +205,44 @@ def remove_caches_from_task(task): except KeyError: pass +def query_pushinfo(repository, revision): + """Query the pushdate and pushid of a repository/revision. + This is intended to be used on hg.mozilla.org/mozilla-central and + similar. It may or may not work for other hg repositories. + """ + PushInfo = namedtuple('PushInfo', ['pushid', 'pushdate']) + + try: + import urllib2 + url = '%s/json-pushes?changeset=%s' % (repository, revision) + sys.stderr.write("Querying URL for pushdate: %s\n" % url) + contents = json.load(urllib2.urlopen(url)) + + # The contents should be something like: + # { + # "28537": { + # "changesets": [ + # "1d0a914ae676cc5ed203cdc05c16d8e0c22af7e5", + # ], + # "date": 1428072488, + # "user": "user@mozilla.com" + # } + # } + # + # So we grab the first element ("28537" in this case) and then pull + # out the 'date' field. + pushid = contents.iterkeys().next() + pushdate = contents[pushid]['date'] + return PushInfo(pushid, pushdate) + + except Exception: + sys.stderr.write( + "Error querying pushinfo for repository '%s' revision '%s'\n" % ( + repository, revision, + ) + ) + return None + @CommandProvider class DecisionTask(object): @Command('taskcluster-decision', category="ci", @@ -333,6 +373,12 @@ class Graph(object): cmdline_interactive = params.get('interactive', False) + # Default to current time if querying the head rev fails + pushdate = time.strftime('%Y%m%d%H%M%S', time.gmtime()) + pushinfo = query_pushinfo(params['head_repository'], params['head_rev']) + if pushinfo: + pushdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(pushinfo.pushdate)) + # Template parameters used when expanding the graph parameters = dict(gaia_info().items() + { 'index': 'index', @@ -344,6 +390,10 @@ class Graph(object): 'head_repository': params['head_repository'], 'head_ref': params['head_ref'] or params['head_rev'], 'head_rev': params['head_rev'], + 'pushdate': pushdate, + 'year': pushdate[0:4], + 'month': pushdate[4:6], + 'day': pushdate[6:8], 'owner': params['owner'], 'from_now': json_time_from_now, 'now': current_json_time(), diff --git a/testing/taskcluster/routes.json b/testing/taskcluster/routes.json index 135c2d81a9f6..9596f4c97418 100644 --- a/testing/taskcluster/routes.json +++ b/testing/taskcluster/routes.json @@ -1,6 +1,7 @@ { "routes": [ "{index}.gecko.v2.{project}.revision.{head_rev}.{build_product}.{build_name}-{build_type}", + "{index}.gecko.v2.{project}.pushdate.{year}.{month}.{day}.{pushdate}.{build_product}.{build_name}-{build_type}", "{index}.gecko.v2.{project}.latest.{build_product}.{build_name}-{build_type}" ], "nightly": [ @@ -11,6 +12,7 @@ ], "l10n": [ "{index}.gecko.v2.{project}.revision.{head_rev}.{build_product}-l10n.{build_name}-{build_type}.{locale}", + "{index}.gecko.v2.{project}.pushdate.{year}.{month}.{day}.{pushdate}.{build_product}-l10n.{build_name}-{build_type}.{locale}", "{index}.gecko.v2.{project}.latest.{build_product}-l10n.{build_name}-{build_type}.{locale}" ] }