hackalive Posted October 27, 2013 Share Posted October 27, 2013 (edited) Hi guys, I am trying to add to my PHP cron script I have. I want the cron to check a private repo on github.com to see if it has been updated since last download and then to download the master.zip, and then extract it over the top of the old code. My first issue is how to get the PHP code to download the master.zip from a private repo. Obviously: file_put_contents("master.zip", file_get_contents("https://github.com/company/repo/archive/master.zip")); is not going to work, as it is a private repo. I did take a look at this https://github.com/markomarkovic/simple-php-git-deploy but was unable to get it to work as I have now idea how to create an SSH for a shared hosting account that PHP can use to contact GitHub. So if anyone can help me get markomarkovic's code to work or has any other code suggestions or ideas please let me know Cheers in advance! Edited October 27, 2013 by hackalive Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/ Share on other sites More sharing options...
ignace Posted October 27, 2013 Share Posted October 27, 2013 (edited) At work we use Beanstalk instead of Github. Beanstalk allows you to deploy over FTP when you push new changes to the master branch. You can't use the above library as it assumes you have control over the server, which you don't. So the only way you'll be able to auto-deploy is by writing it yourself and running it from your own computer. That could look something like this (untested): if (file_exists('.revision')) { $deployed_commit = file_get_contents('.revision'); exec('git diff --name-only ' . $deployed_commit . ' HEAD', $output); // $output contains all changed files since $deployed_commit } else { // from scratch, upload all files } exec('git rev-parse HEAD', $output); file_put_contents('.revision', $output[0]); Edited October 27, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455658 Share on other sites More sharing options...
hackalive Posted October 27, 2013 Author Share Posted October 27, 2013 (edited) @ignace, i cant run it from my own computer, I want to make it part of the cron. Surely there is some way to 'login' to github.com (API or some form) and then run the code to download the zip? Some way to manually SSH key? Also how can i convert: curl -L -F "login=$USER" -F "token=$TOKEN" https://github.com/$USER/$REPO/$PKGTYPE/$BRANCHorTAG to PHP? Edited October 27, 2013 by hackalive Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455671 Share on other sites More sharing options...
trq Posted October 27, 2013 Share Posted October 27, 2013 I wouldn't bother with cron. You can easily setup a github web hook to make a request to your server (via http) whenever a commit is made. When that request is received, you can then download the updated zip. See here. Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455681 Share on other sites More sharing options...
hackalive Posted October 27, 2013 Author Share Posted October 27, 2013 (edited) @trq: I can't see any where in that WebHook the ability to download the zip of the private repo - am I missing something? Edited October 27, 2013 by hackalive Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455685 Share on other sites More sharing options...
ignace Posted October 27, 2013 Share Posted October 27, 2013 You would need to write the script it calls as webhook to download the zip.. Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455723 Share on other sites More sharing options...
hackalive Posted October 27, 2013 Author Share Posted October 27, 2013 (edited) GitHub reply: The archive feature is covered in our API documentation here: http://developer.github.com/v3/repos/contents/#get-archive-linkSince it's a private repository you'll want to create an OAuth token to grant your script access to the repository:http://developer.github.com/v3/oauthI don't have much experience with PHP myself, but perhaps one of the PHP API wrappers has some example code you could look at:http://developer.github.com/v3/libraries Can anyone perhaps help me implement (code) it? Edited October 27, 2013 by hackalive Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455777 Share on other sites More sharing options...
hackalive Posted October 28, 2013 Author Share Posted October 28, 2013 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455951 Share on other sites More sharing options...
trq Posted October 29, 2013 Share Posted October 29, 2013 We're not here to write code for people. Where exactly are you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/283331-github-cron-download/#findComment-1455984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.