Skip to content

Commit

Permalink
Upload the artifact required by Searchfox and index code coverage tas…
Browse files Browse the repository at this point in the history
…k as soon as possible

Fixes #719
  • Loading branch information
marco-c committed Jan 21, 2021
1 parent b6d9560 commit 26cae81
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions bot/code_coverage_bot/hooks/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import zipfile
from datetime import timedelta

import structlog

Expand All @@ -18,6 +19,7 @@
from code_coverage_bot.phabricator import PhabricatorUploader
from code_coverage_bot.phabricator import parse_revision_id
from code_coverage_bot.secrets import secrets
from code_coverage_bot.taskcluster import taskcluster_config
from code_coverage_tools import gcp

logger = structlog.get_logger(__name__)
Expand Down Expand Up @@ -108,18 +110,38 @@ def run(self):
logger.warn("Full covdir report already on GCP")
return

# Generate and upload the full report as soon as possible, so it is available
# for consumers (e.g. Searchfox) right away.
self.retrieve_source_and_artifacts()

self.check_javascript_files()

reports = self.build_reports()
logger.info("Built all covdir reports", nb=len(reports))
reports = self.build_reports(only=[("all", "all")])

# Retrieve the full report
full_path = reports.get(("all", "all"))
assert full_path is not None, "Missing full report (all:all)"
with open(full_path, "r") as f:
report = json.load(f)
report_text = f.read()

# Upload report as an artifact.
taskcluster_config.upload_artifact(
"public/code-coverage-report.json",
report_text,
"application/json",
timedelta(days=30),
)

# Index on Taskcluster
self.index_task(
[
"project.relman.code-coverage.{}.repo.mozilla-central.{}".format(
secrets[secrets.APP_CHANNEL], self.revision
),
"project.relman.code-coverage.{}.repo.mozilla-central.latest".format(
secrets[secrets.APP_CHANNEL]
),
]
)

report = json.loads(report_text)

# Check extensions
paths = uploader.covdir_paths(report)
Expand All @@ -128,10 +150,6 @@ def run(self):
path.endswith(extension) for path in paths
), "No {} file in the generated report".format(extension)

# Upload reports on GCP
self.upload_reports(reports)
logger.info("Uploaded all covdir reports", nb=len(reports))

# Upload coverage on phabricator
changesets = self.get_hgmo_changesets()
coverage = self.upload_phabricator(report, changesets)
Expand All @@ -140,17 +158,17 @@ def run(self):
notify_email(self.revision, changesets, coverage)
logger.info("Sent low coverage email notification")

# Index on Taskcluster
self.index_task(
[
"project.relman.code-coverage.{}.repo.mozilla-central.{}".format(
secrets[secrets.APP_CHANNEL], self.revision
),
"project.relman.code-coverage.{}.repo.mozilla-central.latest".format(
secrets[secrets.APP_CHANNEL]
),
]
)
self.check_javascript_files()

# Generate all reports except the full one which we generated earlier.
all_report_combinations = self.artifactsHandler.get_combinations()
del all_report_combinations[("all", "all")]
reports.update(self.build_reports())
logger.info("Built all covdir reports", nb=len(reports))

# Upload reports on GCP
self.upload_reports(reports)
logger.info("Uploaded all covdir reports", nb=len(reports))


class TryHook(RepositoryHook):
Expand Down

0 comments on commit 26cae81

Please sign in to comment.