Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F72154256
D302.1776859481.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D302.1776859481.diff
View Options
diff --git a/lilybuild/lilybuild/config.py b/lilybuild/lilybuild/config.py
--- a/lilybuild/lilybuild/config.py
+++ b/lilybuild/lilybuild/config.py
@@ -7,7 +7,7 @@
from twisted.internet import defer
from .ci_steps import RunCIJobStep, AnalyzeCIFileCommand, on_success
-from .phorge import CheckoutSourceFromPhorge, SendArtifactLinkToPhorge, SendBuildStatusToPhorge, MaybeRequireApprovalForPhorge
+from .phorge import CheckoutSourceFromPhorge, MaybeRequireApprovalForPhorge
from .helpers import normalize_base_url, phorge_token_to_arcrc
import yaml
@@ -82,12 +82,15 @@
def get_phorge_base_url_for_repo(self, repo_id):
return self.repos[repo_id]['phorge_base_url']
+ def get_phorge_token_for_repo(self, repo_id):
+ return self.repos[repo_id]['phorge_token']
+
def add_lilybuild_builder(self):
factory = util.BuildFactory()
factory.addStep(self.create_source_step())
if report_phorge in self.reports:
factory.addStep(MaybeRequireApprovalForPhorge(lbc=self, workdir=src_dir))
- factory.addStep(SendArtifactLinkToPhorge(lbc=self, workdir=src_dir))
+
factory.addStep(AnalyzeCIFileCommand(
lbc=self,
workdir=work_root,
@@ -100,8 +103,6 @@
result_dir=result_dir,
doStepIf=on_success,
))
- if report_phorge in self.reports:
- factory.addStep(SendBuildStatusToPhorge(lbc=self, workdir=src_dir))
builder = util.BuilderConfig(
name=self.builder_name,
diff --git a/lilybuild/lilybuild/phorge.py b/lilybuild/lilybuild/phorge.py
--- a/lilybuild/lilybuild/phorge.py
+++ b/lilybuild/lilybuild/phorge.py
@@ -7,16 +7,27 @@
import json
from buildbot.plugins import *
from buildbot.process import buildstep, logobserver
+from buildbot.process.properties import Properties
from buildbot.interfaces import IRenderable
from buildbot.steps.download_secret_to_worker import DownloadSecretsToWorker, RemoveWorkerFileSecret
from buildbot.steps.worker import CompositeStepMixin
-from buildbot.util import bytes2unicode
+from buildbot.util import bytes2unicode, httpclientservice
+from buildbot.reporters.base import ReporterBase
+from buildbot.reporters.generators.build import BuildStatusGenerator
+from buildbot.reporters.generators.buildrequest import BuildRequestGenerator
+
from twisted.internet import defer
from twisted.python import log
SEND_COVERAGE_EXEC = '/lilybuild/lilybuild/send_coverage.py'
-class PhorgeMixin(CompositeStepMixin, buildstep.ShellMixin):
+class PhorgeCommonMixin:
+ staging_uri_prop_name = 'harbormaster_variable_repository.staging.uri'
+ staging_ref_prop_name = 'harbormaster_variable_repository.staging.ref'
+ diff_id_prop_name = 'harbormaster_variable_buildable.diff'
+ build_target_prop_name = 'harbormaster_build_target_phid'
+
+class PhorgeMixin(PhorgeCommonMixin, CompositeStepMixin, buildstep.ShellMixin):
'''
Should be inherited by a BuildStep.
@@ -24,10 +35,6 @@
self.lbc: LilyBuildConfig
self.secret_dir: str
'''
- staging_uri_prop_name = 'harbormaster_variable_repository.staging.uri'
- staging_ref_prop_name = 'harbormaster_variable_repository.staging.ref'
- diff_id_prop_name = 'harbormaster_variable_buildable.diff'
- build_target_prop_name = 'harbormaster_build_target_phid'
arc_command = '/tools/arcanist/bin/arc'
def setup_phorge_mixin(self, kwargs):
@@ -189,42 +196,118 @@
set_prop('lilybuild_source', 'arc-patch')
return res
-class SendArtifactLinkToPhorge(PhorgeMixin, steps.BuildStep):
- def __init__(self, lbc, **kwargs):
+class HarbormasterStatusPush(PhorgeCommonMixin, ReporterBase):
+ def checkConfig(self, lbc, generators=None, **kwargs):
+ if generators is None:
+ generators = self.create_default_generators()
+
+ super().checkConfig(generators=generators, **kwargs)
+
+ def create_default_generators(self):
+ end_formatter = MessageFormatterRenderable('Build done.')
+ pending_formatter = MessageFormatterRenderable('Build pending.')
+
+ return [
+ BuildRequestGenerator(formatter=pending_formatter),
+ BuildStatusGenerator(
+ message_formatter=end_formatter
+ ),
+ ]
+
+ @defer.inlineCallbacks
+ def reconfigService(self, lbc, generators=None, **kwargs):
+ if generators is None:
+ generators = self.create_default_generators()
+
+ yield super().reconfigService(generators=generators, **kwargs)
+
self.lbc = lbc
- self.setup_phorge_mixin(kwargs)
- super().__init__(
- name='Send artifact link to Phorge',
- doStepIf=lambda step: step.get_is_phorge(),
- alwaysRun=True,
- **kwargs
+ self.http_session = yield httpclientservice.HTTPSession(
+ self.master.httpservice,
+ '',
+ headers={'User-Agent': 'Buildbot'},
)
@defer.inlineCallbacks
- def run(self):
- if self.getProperty('lilybuild_require_approval'):
- # Do not send another artifact if this requires approval
- return util.SKIPPED
+ def sendToPhorge(self, repo_id, method, data):
+ base_url = self.lbc.get_phorge_base_url_for_repo(repo_id)
+ props = Properties.fromDict({})
+ props.master = self.master
+ token = yield props.render(self.lbc.get_phorge_token_for_repo(repo_id))
+ to_send = {}
+ to_send.update(data)
+ log.msg(f'Sending data to phorge (repo id: {repo_id}): {to_send}')
+ to_send['api.token'] = token
+ res = yield self.http_session.post(
+ base_url + '/api/' + method,
+ data=to_send
+ )
+ if not res:
+ return
+ if res.code < 300:
+ content = yield res.content()
+ log.err(f'Failed to send data to phorge (repo id: {repo_id}): {content}')
+ else:
+ log.msg(f'Sending data to phorge successful (repo id: {repo_id})')
- build_url = yield self.build.getUrl()
+ def sendBuildStatus(self, repo_id, data):
+ return self.sendToPhorge(repo_id, 'harbormaster.sendmessage', data)
- data = {
- 'buildTargetPHID': self.getProperty(self.build_target_prop_name),
- 'artifactKey': f'lilybuild-{self.build.buildid}',
- 'artifactType': 'uri',
- 'artifactData': {
- 'uri': build_url,
- 'name': f'Buildbot build #{self.build.buildid}',
- 'ui.external': True,
- },
- }
- encoded_data = json.dumps(data)
- res = yield self.run_arc_with_secret([
- 'call-conduit',
- '--',
- 'harbormaster.createartifact',
- ], initialStdin=encoded_data)
- return res
+ def sendArtifact(self, repo_id, data):
+ return self.sendToPhorge(repo_id, 'harbormaster.createartifact', data)
+
+ @defer.inlineCallbacks
+ def sendMessage(self, reports):
+ report = reports[0]
+ build = reports[0]['builds'][0]
+
+ props = Properties.fromDict(build['properties'])
+ props.master = self.master
+
+ buildid = build.get('buildid')
+ if not buildid:
+ br = build.get('buildrequest')
+ if br:
+ buildid = br.get('buildrequestid')
+
+ build_url = build['url']
+
+ repo_id = props.getProperty('lilybuild_repo_id')
+ build_target = props.getProperty(self.build_target_prop_name)
+ if not build_target:
+ log.msg('Skipping phorge status push because there is no build target')
+ return
+
+ if props.getProperty('lilybuild_require_approval'):
+ # Do not send final build result if this is skipped, because
+ # otherwise we cannot update it later.
+ log.msg('Skipping phorge status push because this requires approval')
+ return
+
+ if build['complete']:
+ if build['results'] in [util.SUCCESS, util.WARNINGS, util.SKIPPED]:
+ state = 'pass'
+ elif build['results'] == util.RETRY:
+ state = 'work'
+ else:
+ state = 'fail'
+ data = {
+ 'receiver': build_target,
+ 'type': state
+ }
+ res = yield self.sendBuildStatus(repo_id, data)
+ return res
+ else:
+ data = {
+ 'buildTargetPHID': build_target,
+ 'artifactKey': f'lilybuild-{buildid}',
+ 'artifactType': 'uri',
+ 'artifactData[uri]': build_url,
+ 'artifactData[name]': f'Buildbot build #{buildid}',
+ 'artifactData[ui.external]': 'true',
+ }
+ res = yield self.sendArtifact(repo_id, data)
+ return res
class MaybeRequireApprovalForPhorge(PhorgeMixin, steps.BuildStep):
def __init__(self, lbc, sources_need_approval=None, **kwargs):
@@ -280,39 +363,6 @@
set_prop('lilybuild_require_approval', True)
return util.FAILURE
-
-class SendBuildStatusToPhorge(PhorgeMixin, steps.BuildStep):
- def __init__(self, lbc, **kwargs):
- self.lbc = lbc
- self.setup_phorge_mixin(kwargs)
- super().__init__(
- name='Send build status to Phorge',
- doStepIf=lambda step: step.get_is_phorge(),
- alwaysRun=True,
- **kwargs
- )
-
- @defer.inlineCallbacks
- def run(self):
- if self.getProperty('lilybuild_require_approval'):
- # Do not send final build result if this is skipped, because
- # otherwise we cannot update it later.
- return util.SKIPPED
-
- build_url = yield self.build.getUrl()
-
- data = {
- 'receiver': self.getProperty(self.build_target_prop_name),
- 'type': 'pass' if self.build.results == util.SUCCESS else 'fail',
- }
- encoded_data = json.dumps(data)
- res = yield self.run_arc_with_secret([
- 'call-conduit',
- '--',
- 'harbormaster.sendmessage',
- ], initialStdin=encoded_data)
- return res
-
class SendCoverageToPhorge(PhorgeMixin, steps.BuildStep):
def __init__(self, lbc, coverage_file, **kwargs):
self.lbc = lbc
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 22, 5:04 AM (4 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1359859
Default Alt Text
D302.1776859481.diff (10 KB)
Attached To
Mode
D302: Use reporter for build start/end notify
Attached
Detach File
Event Timeline
Log In to Comment