Skip to content

Instantly share code, notes, and snippets.

@josefadamcik
Created August 30, 2011 09:17
Show Gist options
  • Select an option

  • Save josefadamcik/1180517 to your computer and use it in GitHub Desktop.

Select an option

Save josefadamcik/1180517 to your computer and use it in GitHub Desktop.

Revisions

  1. josefadamcik renamed this gist Aug 30, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. josefadamcik renamed this gist Aug 30, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. josefadamcik created this gist Aug 30, 2011.
    59 changes: 59 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    <?php
    //ftp deploy helper (git only)

    $targetDir = "../webdeploy";
    //$lastDeploy = "bd777c31090f9e22aef12e61f7ba64c39f09f5d0";
    if (isset($argv[1])) {
    $lastDeploy = $argv[1];
    }

    $cfgWarning = array();

    prepareDeployDir($targetDir);
    $files = getFileDiff($lastDeploy);

    printn("[deploy] copyingfiles: ");
    //print_r($files);
    foreach($files as $file) {
    $dir = dirname($file);
    $target =$targetDir . "/" . $file;
    $basename = basename($file);
    printn("\t[cp]\t" . basename($file). "\tin " . dirname($file) );
    if (!file_exists($targetDir . "/" . $dir)) {
    mkdir ($targetDir . "/" . $dir, 0777, true);
    }
    exec("cp $file $target");
    //check if we have to upload changed config files
    if (strpos($dir, 'config') !== false) {
    $cfgWarning[] = $file;
    }
    }

    //config deploy warning
    if (count($cfgWarning) > 0) {
    printn("[WARN] config files exported, check changes!!");
    foreach ($cfgWarning as $wrnFile) {
    printn("\t" . $wrnFile);
    }
    }

    //FIXME: handle symlinks


    function getFileDiff($lastDeploy) {
    $diffOutput = array();
    exec("git diff --name-only $lastDeploy HEAD", $diffOutput);
    return $diffOutput;
    }

    function prepareDeployDir($dir) {
    if (file_exists($dir)) {
    printn("[deploy] removing old target dir $dir");
    exec("rm -rf $dir");
    }
    mkdir($dir, 0777, true);
    }

    function printn($str = "") {
    print $str."\n";
    }