Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 37bab7c

Browse files
committed
Update deploy.php to also deploy method documentation over SSH. Fixes issue 37
* Uses hg archive (instead of cat before) to create a temporary directory with the desired revision. * SSH configuration is stored in deploy_configuration.json
1 parent 9e56d9a commit 37bab7c

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

deploy.php

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
$options = getopt(REV_SHORT . ':', array(REV_LONG . ':'));
1212
$configuration = json_decode(file_get_contents('./deploy_configuration.json'));
13-
if(!(isset($configuration->username) && isset($configuration->password) && isset($configuration->page)))
13+
if(!(isset($configuration->username) && isset($configuration->password) && isset($configuration->page)
14+
&& isset($configuration->ssh->host) && isset($configuration->ssh->username) && isset($configuration->ssh->password) && isset($configuration->ssh->path)))
1415
{
15-
fwrite(STDERR, 'You must provide a JSON file, deploy_configuaration.json, in the repository root (but not committed) with username, password, and page fields set.');
16+
fwrite(STDERR, 'You must provide a JSON file, deploy_configuaration.json, in the repository root (but not committed) with username, password, page, and ssh configuration fields set.');
1617
exit(1);
1718
}
1819

@@ -44,7 +45,17 @@
4445
exit(5);
4546
}
4647

47-
$orig_code = shell_exec('hg cat -r ' . $revid . ' ' . PROVEIT_FILE);
48+
$temp_dir = tempnam("/tmp", "proveit_deploy_r{$revid}_");
49+
if(!$temp_dir)
50+
{
51+
fwrite(STDERR, "Failed to create temporary file.\n");
52+
exit(9);
53+
}
54+
unlink($temp_dir); // We need a directory, rather than file.
55+
shell_exec("hg archive -r $revid $temp_dir");
56+
chdir($temp_dir);
57+
58+
$orig_code = file_get_contents(PROVEIT_FILE);
4859
$closure_ch = curl_init('http://closure-compiler.appspot.com/compile');
4960
$params = http_build_query(array(
5061
'js_code' => $orig_code,
@@ -158,4 +169,51 @@
158169
fwrite(STDERR, $edit_resp_str);
159170
exit(3);
160171
}
161-
?>
172+
173+
system('./yuidoc.sh');
174+
echo "Connecting to {$configuration->ssh->host}\n";
175+
$con = ssh2_connect($configuration->ssh->host);
176+
177+
$auth_ret = ssh2_auth_password($con, $configuration->ssh->username, $configuration->ssh->password);
178+
if(!$auth_ret)
179+
{
180+
fwrite(STDERR, 'SSH password authentication failed.\n');
181+
exit(6);
182+
}
183+
184+
$sftp = ssh2_sftp($con);
185+
if(!$sftp)
186+
{
187+
fwrite(STDERR, "Failed to open SFTP subsystem.\n");
188+
exit(7);
189+
}
190+
191+
function sftp_walk($con, $sftp, $local_dir, $remote_dir)
192+
{
193+
$dir = opendir($local_dir);
194+
ssh2_sftp_mkdir($sftp, $remote_dir, 0755, true);
195+
while (($file = readdir($dir)) !== false)
196+
{
197+
$local_file = $local_dir . '/' . $file;
198+
$remote_file = $remote_dir . '/' . $file;
199+
if(!is_dir($local_file))
200+
{
201+
echo "Transferring $local_file to $remote_file\n";
202+
$scp_ret = ssh2_scp_send($con, $local_file, $remote_file, 0755);
203+
if(!$scp_ret)
204+
{
205+
fwrite(STDERR, "Failed to transfer file.\n");
206+
exit(8);
207+
}
208+
}
209+
else if($file != "." && $file != "..")
210+
{
211+
sftp_walk($con, $sftp, $local_file, $remote_file);
212+
}
213+
}
214+
}
215+
216+
sftp_walk($con, $sftp, 'yui_docs/html', $configuration->ssh->path);
217+
chdir(dirname(__FILE__));
218+
system("rm -r $temp_dir");
219+
echo "You have succesfully deployed the ProveIt API documentation.\n";

0 commit comments

Comments
 (0)