Jump to content

Recommended Posts

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 by hackalive
Link to comment
https://forums.phpfreaks.com/topic/283331-github-cron-download/
Share on other sites

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 by ignace

@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 by hackalive

GitHub reply:

 

The archive feature is covered in our API documentation here:


http://developer.github.com/v3/repos/contents/#get-archive-link

Since 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/oauth

I 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 by hackalive
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.