|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | + |
| 6 | +import structlog |
| 7 | + |
| 8 | +from code_coverage_bot import config |
| 9 | +from code_coverage_bot import trigger_missing |
| 10 | +from code_coverage_bot import uploader |
| 11 | +from code_coverage_bot.cli import setup_cli |
| 12 | +from code_coverage_bot.hooks.base import Hook |
| 13 | +from code_coverage_bot.secrets import secrets |
| 14 | + |
| 15 | +logger = structlog.get_logger(__name__) |
| 16 | + |
| 17 | + |
| 18 | +class CronTriggerHook(Hook): |
| 19 | + """ |
| 20 | + This function is executed when the bot is triggered via cron. |
| 21 | + """ |
| 22 | + |
| 23 | + def __init__(self, *args, **kwargs): |
| 24 | + # Retrieve latest ingested revision |
| 25 | + try: |
| 26 | + revision = uploader.gcp_latest("mozilla-central")[0]["revision"] |
| 27 | + except Exception as e: |
| 28 | + logger.warn("Failed to retrieve the latest reports ingested: {}".format(e)) |
| 29 | + raise |
| 30 | + |
| 31 | + super().__init__(config.MOZILLA_CENTRAL_REPOSITORY, revision, *args, **kwargs) |
| 32 | + |
| 33 | + def run(self) -> None: |
| 34 | + trigger_missing.trigger_missing(config.MOZILLA_CENTRAL_REPOSITORY) |
| 35 | + |
| 36 | + # Index the task in the TaskCluster index at the given revision and as "latest". |
| 37 | + # Given that all tasks have the same rank, the latest task that finishes will |
| 38 | + # overwrite the "latest" entry. |
| 39 | + self.index_task( |
| 40 | + [ |
| 41 | + "project.relman.code-coverage.{}.crontrigger.{}".format( |
| 42 | + secrets[secrets.APP_CHANNEL], self.revision |
| 43 | + ), |
| 44 | + "project.relman.code-coverage.{}.crontrigger.latest".format( |
| 45 | + secrets[secrets.APP_CHANNEL] |
| 46 | + ), |
| 47 | + ] |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +def main() -> None: |
| 52 | + logger.info("Starting code coverage bot for crontrigger") |
| 53 | + args = setup_cli(ask_revision=False, ask_repository=False) |
| 54 | + hook = CronTriggerHook(args.task_name_filter, args.cache_root, args.working_dir) |
| 55 | + hook.run() |
0 commit comments