forked from WordPress/phpunit-test-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
60 lines (46 loc) · 2.09 KB
/
report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Reports the test run results to WordPress.org
*/
require __DIR__ . '/functions.php';
// Check required environment variables.
check_required_env( false );
$WPT_SSH_CONNECT = getenv( 'WPT_SSH_CONNECT' );
$WPT_TEST_DIR = getenv( 'WPT_TEST_DIR' );
$WPT_PREPARE_DIR = getenv( 'WPT_PREPARE_DIR' );
$WPT_SSH_OPTIONS = getenv( 'WPT_SSH_OPTIONS' );
$WPT_REPORT_API_KEY = getenv( 'WPT_REPORT_API_KEY' );
log_message('Getting SVN Revision');
$rev = exec('git --git-dir=' . escapeshellarg( $WPT_PREPARE_DIR ) . '/.git log -1 --pretty=%B | grep "git-svn-id:" | cut -d " " -f 2 | cut -d "@" -f 2');
log_message('Getting SVN message');
$message = trim( exec('git --git-dir=' . escapeshellarg( $WPT_PREPARE_DIR ) . '/.git log -1 --pretty=%B | head -1') );
log_message('Copying junit.xml results');
$junit_location = escapeshellarg( $WPT_TEST_DIR ) . '/tests/phpunit/build/logs/*';
if ( ! empty( $WPT_SSH_CONNECT ) ) {
$junit_location = '-e "ssh ' . $WPT_SSH_OPTIONS . '" ' . escapeshellarg( $WPT_SSH_CONNECT . ':' . $junit_location );
}
$junit_exec = 'rsync -rv ' . $junit_location . ' ' . escapeshellarg( $WPT_PREPARE_DIR );
perform_operations( array(
$junit_exec,
) );
log_message( 'Processing and uploading junit.xml' );
$xml = file_get_contents( $WPT_PREPARE_DIR . '/junit.xml' );
$results = process_junit_xml( $xml );
$env = '';
if ( file_exists( $WPT_PREPARE_DIR . '/env.json' ) ) {
$env = file_get_contents( $WPT_PREPARE_DIR . '/env.json' );
} elseif ( $WPT_PREPARE_DIR === $WPT_TEST_DIR ) {
$env = json_encode( get_env_details(), JSON_PRETTY_PRINT );
}
list( $http_status, $response_body ) = upload_results( $results, $rev, $message, $env, $WPT_REPORT_API_KEY );
$response = json_decode( $response_body, true );
if ( 20 == substr( $http_status, 0, 2 ) ) {
$message = 'Results successfully uploaded';
$message .= isset( $response['link'] ) ? ': ' . $response['link'] : '';
log_message( $message );
} else {
$message = 'Error uploading results';
$message .= isset( $response['message'] ) ? ': ' . $response['message'] : '';
$message .= ' (HTTP status ' . (int) $http_status . ')';
error_message( $message );
}