Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F149981
arc_update-diff_with_results_from_delayed_build
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
avivey
May 2 2014, 6:29 PM
2014-05-02 18:29:14 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
arc_update-diff_with_results_from_delayed_build
View Options
<?php
final
class
UpdateDiffWorkflow
extends
ArcanistBaseWorkflow
{
private
$console
;
private
static
$TEST_FIELDS
=
array
(
'name'
,
'link'
,
'result'
,
'message'
,
'coverage'
,
);
public
function
run
()
{
$this
->
console
=
PhutilConsole
::
getConsole
();
$root
=
$this
->
getWorkingCopy
()->
getProjectRoot
()
.
'/'
;
$diff_id
=
$this
->
getArgument
(
'diff'
);
if
(!
$diff_id
)
{
throw
new
ArcanistUsageException
(
"diff param required"
);
}
$this
->
console
->
writeOut
(
"Updating diff $diff_id/
\n
"
);
$lint_messages
=
$this
->
runLint
();
$test_results
=
$this
->
runUnit
();
try
{
$this
->
getConduit
()->
callMethodSynchronous
(
// todo async
'differential.finishpostponedlinters'
,
array
(
'diffID'
=>
$diff_id
,
'linters'
=>
array
(
'jenkins'
=>
$lint_messages
)));
}
catch
(
Exception
$ex
)
{
$this
->
console
->
writeOut
(
"Lint reporting failed: "
.
$ex
->
getMessage
()
.
"
\n
"
);
}
$coverage
=
magically_obtain_coverage_data
();
// TODO
$sampeler
=
new
TestResultsSampeler
();
// this object reduces the number of tests, which == number of api calls.
$sampeler
->
setExtraTestCoverage
(
$coverage
);
if
(
$this
->
isBuildFailed
())
{
$sampeler
->
setExtraTestStatus
(
ArcanistUnitTestResult
::
RESULT_BROKEN
);
$sampeler
->
setExtraTestText
(
"Build Failed! "
);
}
$build_uri
=
getenv
(
'BUILD_URL'
);
if
(
$build_uri
)
$sampeler
->
setExtraTestLink
(
$build_uri
);
$sampeler_results
=
$sampeler
->
sampelize
(
$test_results
);
$test_results
=
$sampeler_results
[
'sampled'
];
$extra_test
=
$sampeler_results
[
'extra test'
];
foreach
(
$test_results
as
$test
)
{
$data
=
$test
->
toDictionary
();
$data
=
array_select_keys
(
$data
,
self
::
$TEST_FIELDS
);
$data
[
'diff_id'
]
=
$diff_id
;
$this
->
getConduit
()->
callMethodSynchronous
(
// todo async
'differential.updateunitresults'
,
$data
);
}
$data
=
$extra_test
->
toDictionary
();
$data
=
array_select_keys
(
$data
,
self
::
$TEST_FIELDS
);
$data
[
'diff_id'
]
=
$diff_id
;
// This deletes the "postponed" value.
$data
[
'file'
]
=
'Jenkins postponed tests'
;
$data
[
'message'
]
=
$extra_test
->
getName
();
$data
[
'name'
]
=
'Jenkins Build'
;
$this
->
getConduit
()->
callMethodSynchronous
(
'differential.updateunitresults'
,
$data
);
}
private
function
isBuildFailed
()
{
$status
=
$this
->
getArgument
(
'build-status'
,
false
);
if
(
$status
===
false
)
// no data
return
false
;
if
(
$status
==
0
)
// build pass
return
false
;
return
true
;
}
public
function
getArguments
()
{
return
array
(
'diff'
=>
array
(
'param'
=>
'diff_id'
,
'help'
=>
'diff_id to update (not Differential Diff - small diff!)'
),
'build-status'
=>
array
(
'param'
=>
'build_status'
,
'help'
=>
'exit code from the build script (Unix style - 0 means "good")'
),
);
}
public
function
getCommandSynopses
()
{
return
phutil_console_format
(
<<<EOTEXT
**update-diff** [__options__]
EOTEXT
);
}
public
function
getCommandHelp
()
{
return
'Expected to be run by Jenkins, after "mvn test" was executed.'
;
}
public
function
requiresWorkingCopy
()
{
return
true
;
}
public
function
requiresConduit
()
{
return
true
;
}
public
function
requiresAuthentication
()
{
return
true
;
}
public
function
requiresRepositoryAPI
()
{
return
true
;
}
public
function
getWorkflowName
()
{
return
'update-diff'
;
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/tp/6h/umqiptpgqvkfnils
Default Alt Text
arc_update-diff_with_results_from_delayed_build (3 KB)
Attached To
Mode
P1132 arc update-diff with results from delayed build - rough draft
Attached
Detach File
Event Timeline
Log In to Comment