-
Notifications
You must be signed in to change notification settings - Fork 7
/
upload-inspect-report
executable file
·164 lines (129 loc) · 5.66 KB
/
upload-inspect-report
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env php
<?php
require_once(__DIR__.'/vendor/autoload.php');
use BoostTasks\BinTrayCache;
use BoostTasks\TempDirectory;
use BoostTasks\Settings;
use BoostTasks\CommandLineOptions;
use BoostTasks\Log;
use BoostTasks\Process;
function main() {
$options = CommandLineOptions::process($_SERVER['argv'],
'Run inspect on the latest cached downloads from bintray.');
Settings::init($options);
// Setup directories.
$report_path = Settings::dataPath('inspect');
$upload_path = Settings::dataPath('inspect/upload');
$cache = new BinTrayCache;
// Get details of latest downloads and see if they need to be inspected.
$branches = array();
$to_inspect = array();
foreach(array('develop', 'master') as $branch) {
$details = $cache->latestDownload($branch);
if ($details) {
$details['sha1_path'] = "{$report_path}/{$branch}-sha1.txt";
$branches[$branch] = $details;
$last_sha1 = is_file($details['sha1_path']) ? trim(file_get_contents($details['sha1_path'])) : '';
if ($details['sha1'] != $last_sha1) { $to_inspect[] = $branch; }
}
}
if (!$to_inspect) {
Log::info("Inspect: nothing to do.");
return;
}
Log::info("Inspect: running for ". implode(", ", $to_inspect).".");
// Get hardlinks of latest downloads.
// Not downloading because the cache doesn't support multiple processes.
// There is a bit of race condition here, but minimised by making a hardlink
// fairly quickly.
// Might tweak the cache implementation so that it's less likely to
// delete a file here.
$temp_directory = new TempDirectory(Settings::dataPath('inspect'));
foreach($branches as $branch => $details) {
$archive_path = "{$temp_directory->path}/{$branch}/".basename($details['path']);
mkdir(dirname($archive_path));
link($details['path'], $archive_path);
$branches[$branch]['archive_path'] = $archive_path;
}
// Build inspect.
$build_branch = 'develop';
if (!array_key_exists($build_branch, $branches)) {
Log::error("Error getting {$build_branch} tarball for inspect.");
return;
}
$build_path = "{$temp_directory->path}/build-inspect";
mkdir($build_path);
$build_path = BinTrayCache::extractSingleRootArchive(
$branches[$build_branch]['archive_path'], $build_path);
Process::run("{$build_path}/tools/build/bootstrap.sh", "{$build_path}/tools/build", null, null, 60*5);
Process::run("{$build_path}/tools/build/b2 -q dist-bin", "{$build_path}/tools/inspect/build", null, null, 60*5);
$inspect_exec = "{$build_path}/dist/bin/inspect";
// Run inspect.
foreach ($to_inspect as $branch) {
$details = $branches[$branch];
$extract_path = "{$temp_directory->path}/boost-{$branch}";
mkdir($extract_path);
$extract_path = BinTrayCache::extractSingleRootArchive($details['archive_path'], $extract_path);
// Note: if you change the name, will also need to change upload_files.
$inspect_final_name = "docs-inspect-{$branch}.html";
$inspect_path = "{$temp_directory->path}/{$inspect_final_name}";
$version_string = "a snapshot of {$branch}";
$version_string .= ", commit ".substr($details['version'], 0, 10);
if ($created = strtotime($details['created'])) {
$version_string .= ", created on ".date(DATE_RFC850, $created);
}
// Status: 0 = no errors, 1 = inspect errors, 2 = error running inspect.
// TODO: Would be good to get stderr.
$status = Process::status(
"{$inspect_exec} '{$extract_path}' -version-string '{$version_string}' > '{$inspect_path}'",
$extract_path, null, null, 60*5);
if ($status != 0 && $status != 1) {
Log::error("Inspect: error running inspect for {$branch}");
continue;
}
// Keep a copy of the inspect file, and copy into upload directory.
copy($inspect_path, "{$upload_path}/{$inspect_final_name}");
copy($inspect_path, "{$report_path}/{$inspect_final_name}");
file_put_contents($details['sha1_path'], $details['sha1']);
}
upload_files($upload_path);
}
function upload_files($upload_path) {
$files_to_upload = glob("{$upload_path}/docs-inspect-*.html");
if (!$files_to_upload) { return true; }
// Get cowic login details for FTP.
$cowic_username = Settings::settings('cowic-username');
$cowic_password = Settings::settings('cowic-password');
if (is_null($cowic_username) || is_null($cowic_password)) {
Log::warning("Not uploading inspect reports as login details not set.");
return false;
}
$ftp_id = ftp_connect('boost.cowic.de');
if (!$ftp_id) {
Log::error("Unable to connect to boost.cowic.de to upload inspect report");
return false;
}
if (!ftp_login($ftp_id, $cowic_username, $cowic_password)) {
Log::error("Error logging in to boost.cowic.de to upload inspect report");
return false;
}
$return = true;
foreach ($files_to_upload as $inspect_path) {
$inspect_final_name = basename($inspect_path);
$inspect_tmp_name = "{$inspect_final_name}.upload";
$success =
ftp_pasv($ftp_id, true) &&
ftp_put($ftp_id, $inspect_tmp_name, $inspect_path, FTP_BINARY) &&
ftp_rename($ftp_id, $inspect_tmp_name, $inspect_final_name);
if (!$success) {
Log::error("Error uploading {$inspect_final_name} report to boost.cowic.de");
$return = false;
}
else {
unlink($inspect_path);
}
}
ftp_close($ftp_id);
return $return;
}
main();